Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 41 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
| 44 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 77 | /* file attributes which can be mapped to nfs attributes */ |
| 78 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 79 | | ATTR_UID \ |
| 80 | | ATTR_GID \ |
| 81 | | ATTR_SIZE \ |
| 82 | | ATTR_ATIME \ |
| 83 | | ATTR_MTIME \ |
| 84 | | ATTR_CTIME \ |
| 85 | | ATTR_ATIME_SET \ |
| 86 | | ATTR_MTIME_SET) |
| 87 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 88 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 89 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 90 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 92 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 93 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 94 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 95 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 100 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 101 | struct rpc_cred *); |
| 102 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 103 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 104 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 107 | static inline struct nfs4_label * |
| 108 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 109 | struct iattr *sattr, struct nfs4_label *label) |
| 110 | { |
| 111 | int err; |
| 112 | |
| 113 | if (label == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 117 | return NULL; |
| 118 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 120 | &dentry->d_name, (void **)&label->label, &label->len); |
| 121 | if (err == 0) |
| 122 | return label; |
| 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | static inline void |
| 127 | nfs4_label_release_security(struct nfs4_label *label) |
| 128 | { |
| 129 | if (label) |
| 130 | security_release_secctx(label->label, label->len); |
| 131 | } |
| 132 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | return server->attr_bitmask; |
| 136 | |
| 137 | return server->attr_bitmask_nl; |
| 138 | } |
| 139 | #else |
| 140 | static inline struct nfs4_label * |
| 141 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 142 | struct iattr *sattr, struct nfs4_label *l) |
| 143 | { return NULL; } |
| 144 | static inline void |
| 145 | nfs4_label_release_security(struct nfs4_label *label) |
| 146 | { return; } |
| 147 | static inline u32 * |
| 148 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 149 | { return server->attr_bitmask; } |
| 150 | #endif |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 153 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 155 | if (err >= -1000) |
| 156 | return err; |
| 157 | switch (err) { |
| 158 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 160 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 161 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 162 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 163 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 164 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 165 | case -NFS4ERR_BADOWNER: |
| 166 | case -NFS4ERR_BADNAME: |
| 167 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 168 | case -NFS4ERR_SHARE_DENIED: |
| 169 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 170 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 171 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 172 | case -NFS4ERR_FILE_OPEN: |
| 173 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 174 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 176 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is our standard bitmap for GETATTR requests. |
| 184 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 185 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 202 | FATTR4_WORD2_SECURITY_LABEL |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 206 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 207 | FATTR4_WORD0_TYPE |
| 208 | | FATTR4_WORD0_CHANGE |
| 209 | | FATTR4_WORD0_SIZE |
| 210 | | FATTR4_WORD0_FSID |
| 211 | | FATTR4_WORD0_FILEID, |
| 212 | FATTR4_WORD1_MODE |
| 213 | | FATTR4_WORD1_NUMLINKS |
| 214 | | FATTR4_WORD1_OWNER |
| 215 | | FATTR4_WORD1_OWNER_GROUP |
| 216 | | FATTR4_WORD1_RAWDEV |
| 217 | | FATTR4_WORD1_SPACE_USED |
| 218 | | FATTR4_WORD1_TIME_ACCESS |
| 219 | | FATTR4_WORD1_TIME_METADATA |
| 220 | | FATTR4_WORD1_TIME_MODIFY, |
| 221 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 223 | | FATTR4_WORD2_SECURITY_LABEL |
| 224 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 227 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 228 | FATTR4_WORD0_TYPE |
| 229 | | FATTR4_WORD0_CHANGE |
| 230 | | FATTR4_WORD0_FILEID, |
| 231 | }; |
| 232 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 233 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | FATTR4_WORD0_FILES_AVAIL |
| 235 | | FATTR4_WORD0_FILES_FREE |
| 236 | | FATTR4_WORD0_FILES_TOTAL, |
| 237 | FATTR4_WORD1_SPACE_AVAIL |
| 238 | | FATTR4_WORD1_SPACE_FREE |
| 239 | | FATTR4_WORD1_SPACE_TOTAL |
| 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | FATTR4_WORD0_MAXLINK |
| 244 | | FATTR4_WORD0_MAXNAME, |
| 245 | 0 |
| 246 | }; |
| 247 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 248 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | | FATTR4_WORD0_MAXREAD |
| 250 | | FATTR4_WORD0_MAXWRITE |
| 251 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 252 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 253 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 254 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 255 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | FATTR4_WORD0_TYPE |
| 260 | | FATTR4_WORD0_CHANGE |
| 261 | | FATTR4_WORD0_SIZE |
| 262 | | FATTR4_WORD0_FSID |
| 263 | | FATTR4_WORD0_FILEID |
| 264 | | FATTR4_WORD0_FS_LOCATIONS, |
| 265 | FATTR4_WORD1_MODE |
| 266 | | FATTR4_WORD1_NUMLINKS |
| 267 | | FATTR4_WORD1_OWNER |
| 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 277 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct nfs4_readdir_arg *readdir) |
| 279 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 280 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 283 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | readdir->cookie = 0; |
| 289 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 290 | if (cookie == 2) |
| 291 | return; |
| 292 | |
| 293 | /* |
| 294 | * NFSv4 servers do not return entries for '.' and '..' |
| 295 | * Therefore, we fake these entries here. We let '.' |
| 296 | * have cookie 0 and '..' have cookie 1. Note that |
| 297 | * when talking to the server, we always send cookie 0 |
| 298 | * instead of 1 or 2. |
| 299 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 300 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (cookie == 0) { |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_one; /* cookie, second word */ |
| 306 | *p++ = xdr_one; /* entry len */ |
| 307 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
| 322 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 323 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 324 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | readdir->pgbase = (char *)p - (char *)start; |
| 327 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 331 | static long nfs4_update_delay(long *timeout) |
| 332 | { |
| 333 | long ret; |
| 334 | if (!timeout) |
| 335 | return NFS4_POLL_RETRY_MAX; |
| 336 | if (*timeout <= 0) |
| 337 | *timeout = NFS4_POLL_RETRY_MIN; |
| 338 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 339 | *timeout = NFS4_POLL_RETRY_MAX; |
| 340 | ret = *timeout; |
| 341 | *timeout <<= 1; |
| 342 | return ret; |
| 343 | } |
| 344 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 346 | { |
| 347 | int res = 0; |
| 348 | |
| 349 | might_sleep(); |
| 350 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 351 | freezable_schedule_timeout_killable_unsafe( |
| 352 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 353 | if (fatal_signal_pending(current)) |
| 354 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | return res; |
| 356 | } |
| 357 | |
| 358 | /* This is the error handling routine for processes that are allowed |
| 359 | * to sleep. |
| 360 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 361 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 362 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 363 | { |
| 364 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 365 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 366 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 367 | int ret = errorcode; |
| 368 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 369 | exception->delay = 0; |
| 370 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 371 | exception->retry = 0; |
| 372 | switch(errorcode) { |
| 373 | case 0: |
| 374 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 375 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 376 | case -NFS4ERR_DELEG_REVOKED: |
| 377 | case -NFS4ERR_ADMIN_REVOKED: |
| 378 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 4816fda | 2015-09-20 14:58:42 -0400 | [diff] [blame] | 379 | if (inode && nfs_async_inode_return_delegation(inode, |
| 380 | NULL) == 0) |
| 381 | goto wait_on_recovery; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 382 | if (state == NULL) |
| 383 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 384 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 385 | if (ret < 0) |
| 386 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 387 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 388 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 389 | if (state != NULL) { |
| 390 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 391 | if (ret < 0) |
| 392 | break; |
| 393 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 394 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 395 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 396 | nfs4_schedule_lease_recovery(clp); |
| 397 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 398 | case -NFS4ERR_MOVED: |
| 399 | ret = nfs4_schedule_migration_recovery(server); |
| 400 | if (ret < 0) |
| 401 | break; |
| 402 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 403 | case -NFS4ERR_LEASE_MOVED: |
| 404 | nfs4_schedule_lease_moved_recovery(clp); |
| 405 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 406 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 407 | case -NFS4ERR_BADSESSION: |
| 408 | case -NFS4ERR_BADSLOT: |
| 409 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 410 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 411 | case -NFS4ERR_DEADSESSION: |
| 412 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 413 | case -NFS4ERR_SEQ_MISORDERED: |
| 414 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 415 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 416 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 417 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 418 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 419 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 420 | if (exception->timeout > HZ) { |
| 421 | /* We have retried a decent amount, time to |
| 422 | * fail |
| 423 | */ |
| 424 | ret = -EBUSY; |
| 425 | break; |
| 426 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 427 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 428 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 429 | case -NFS4ERR_GRACE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 430 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 431 | exception->delay = 1; |
| 432 | return 0; |
| 433 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 434 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 435 | case -NFS4ERR_OLD_STATEID: |
| 436 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 437 | break; |
| 438 | case -NFS4ERR_BADOWNER: |
| 439 | /* The following works around a Linux server bug! */ |
| 440 | case -NFS4ERR_BADNAME: |
| 441 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 442 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 443 | exception->retry = 1; |
| 444 | printk(KERN_WARNING "NFS: v4 server %s " |
| 445 | "does not accept raw " |
| 446 | "uid/gids. " |
| 447 | "Reenabling the idmapper.\n", |
| 448 | server->nfs_client->cl_hostname); |
| 449 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 450 | } |
| 451 | /* We failed to handle the error */ |
| 452 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 453 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 454 | exception->recovering = 1; |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | /* This is the error handling routine for processes that are allowed |
| 459 | * to sleep. |
| 460 | */ |
| 461 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 462 | { |
| 463 | struct nfs_client *clp = server->nfs_client; |
| 464 | int ret; |
| 465 | |
| 466 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 467 | if (exception->delay) { |
| 468 | ret = nfs4_delay(server->client, &exception->timeout); |
| 469 | goto out_retry; |
| 470 | } |
| 471 | if (exception->recovering) { |
| 472 | ret = nfs4_wait_clnt_recover(clp); |
| 473 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 474 | return -EIO; |
| 475 | goto out_retry; |
| 476 | } |
| 477 | return ret; |
| 478 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 479 | if (ret == 0) |
| 480 | exception->retry = 1; |
| 481 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 482 | } |
| 483 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 484 | static int |
| 485 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 486 | int errorcode, struct nfs4_exception *exception) |
| 487 | { |
| 488 | struct nfs_client *clp = server->nfs_client; |
| 489 | int ret; |
| 490 | |
| 491 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 492 | if (exception->delay) { |
| 493 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 494 | goto out_retry; |
| 495 | } |
| 496 | if (exception->recovering) { |
| 497 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 498 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 499 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 500 | goto out_retry; |
| 501 | } |
| 502 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 503 | ret = -EIO; |
| 504 | return ret; |
| 505 | out_retry: |
| 506 | if (ret == 0) |
| 507 | exception->retry = 1; |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | static int |
| 512 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 513 | struct nfs4_state *state, long *timeout) |
| 514 | { |
| 515 | struct nfs4_exception exception = { |
| 516 | .state = state, |
| 517 | }; |
| 518 | |
| 519 | if (task->tk_status >= 0) |
| 520 | return 0; |
| 521 | if (timeout) |
| 522 | exception.timeout = *timeout; |
| 523 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 524 | task->tk_status, |
| 525 | &exception); |
| 526 | if (exception.delay && timeout) |
| 527 | *timeout = exception.timeout; |
| 528 | if (exception.retry) |
| 529 | return -EAGAIN; |
| 530 | return 0; |
| 531 | } |
| 532 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 533 | /* |
| 534 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 535 | * or 'false' otherwise. |
| 536 | */ |
| 537 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 538 | { |
| 539 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 540 | |
| 541 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 542 | flavor == RPC_AUTH_GSS_KRB5P) |
| 543 | return true; |
| 544 | |
| 545 | return false; |
| 546 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 547 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 548 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | spin_lock(&clp->cl_lock); |
| 551 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 552 | clp->cl_last_renewal = timestamp; |
| 553 | spin_unlock(&clp->cl_lock); |
| 554 | } |
| 555 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 556 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 557 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 558 | struct nfs_client *clp = server->nfs_client; |
| 559 | |
| 560 | if (!nfs4_has_session(clp)) |
| 561 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 564 | struct nfs4_call_sync_data { |
| 565 | const struct nfs_server *seq_server; |
| 566 | struct nfs4_sequence_args *seq_args; |
| 567 | struct nfs4_sequence_res *seq_res; |
| 568 | }; |
| 569 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 570 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 571 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 572 | { |
| 573 | args->sa_slot = NULL; |
| 574 | args->sa_cache_this = cache_reply; |
| 575 | args->sa_privileged = 0; |
| 576 | |
| 577 | res->sr_slot = NULL; |
| 578 | } |
| 579 | |
| 580 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 581 | { |
| 582 | args->sa_privileged = 1; |
| 583 | } |
| 584 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 585 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 586 | struct nfs4_sequence_args *args, |
| 587 | struct nfs4_sequence_res *res, |
| 588 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 589 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 590 | struct nfs4_slot *slot; |
| 591 | |
| 592 | /* slot already allocated? */ |
| 593 | if (res->sr_slot != NULL) |
| 594 | goto out_start; |
| 595 | |
| 596 | spin_lock(&tbl->slot_tbl_lock); |
| 597 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 598 | goto out_sleep; |
| 599 | |
| 600 | slot = nfs4_alloc_slot(tbl); |
| 601 | if (IS_ERR(slot)) { |
| 602 | if (slot == ERR_PTR(-ENOMEM)) |
| 603 | task->tk_timeout = HZ >> 2; |
| 604 | goto out_sleep; |
| 605 | } |
| 606 | spin_unlock(&tbl->slot_tbl_lock); |
| 607 | |
| 608 | args->sa_slot = slot; |
| 609 | res->sr_slot = slot; |
| 610 | |
| 611 | out_start: |
| 612 | rpc_call_start(task); |
| 613 | return 0; |
| 614 | |
| 615 | out_sleep: |
| 616 | if (args->sa_privileged) |
| 617 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 618 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 619 | else |
| 620 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 621 | spin_unlock(&tbl->slot_tbl_lock); |
| 622 | return -EAGAIN; |
| 623 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 624 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 625 | |
| 626 | static int nfs40_sequence_done(struct rpc_task *task, |
| 627 | struct nfs4_sequence_res *res) |
| 628 | { |
| 629 | struct nfs4_slot *slot = res->sr_slot; |
| 630 | struct nfs4_slot_table *tbl; |
| 631 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 632 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 633 | goto out; |
| 634 | |
| 635 | tbl = slot->table; |
| 636 | spin_lock(&tbl->slot_tbl_lock); |
| 637 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 638 | nfs4_free_slot(tbl, slot); |
| 639 | spin_unlock(&tbl->slot_tbl_lock); |
| 640 | |
| 641 | res->sr_slot = NULL; |
| 642 | out: |
| 643 | return 1; |
| 644 | } |
| 645 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 646 | #if defined(CONFIG_NFS_V4_1) |
| 647 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 648 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 649 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 650 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 651 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 652 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 653 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 654 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 655 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 656 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 657 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 658 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 659 | /* Be nice to the server: try to ensure that the last transmitted |
| 660 | * value for highest_user_slotid <= target_highest_slotid |
| 661 | */ |
| 662 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 663 | send_new_highest_used_slotid = true; |
| 664 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 665 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 666 | send_new_highest_used_slotid = false; |
| 667 | goto out_unlock; |
| 668 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 669 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 670 | |
| 671 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 672 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 673 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 674 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 675 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 676 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 677 | nfs41_notify_server(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 680 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 681 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 682 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 683 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 684 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 685 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 686 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 687 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 688 | if (slot == NULL) |
| 689 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 690 | /* don't increment the sequence number if the task wasn't sent */ |
| 691 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 692 | goto out; |
| 693 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 694 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 695 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 696 | if (slot->interrupted) { |
| 697 | slot->interrupted = 0; |
| 698 | interrupted = true; |
| 699 | } |
| 700 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 701 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 702 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 703 | switch (res->sr_status) { |
| 704 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 705 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 706 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 707 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 708 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 709 | /* Check sequence flags */ |
Trond Myklebust | b15c7cd | 2015-07-05 15:01:36 -0400 | [diff] [blame] | 710 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 711 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 712 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 713 | case 1: |
| 714 | /* |
| 715 | * sr_status remains 1 if an RPC level error occurred. |
| 716 | * The server may or may not have processed the sequence |
| 717 | * operation.. |
| 718 | * Mark the slot as having hosted an interrupted RPC call. |
| 719 | */ |
| 720 | slot->interrupted = 1; |
| 721 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 722 | case -NFS4ERR_DELAY: |
| 723 | /* The server detected a resend of the RPC call and |
| 724 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 725 | * of RFC5661. |
| 726 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 727 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 728 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 729 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 730 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 731 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 732 | case -NFS4ERR_BADSLOT: |
| 733 | /* |
| 734 | * The slot id we used was probably retired. Try again |
| 735 | * using a different slot id. |
| 736 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 737 | goto retry_nowait; |
| 738 | case -NFS4ERR_SEQ_MISORDERED: |
| 739 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 740 | * Was the last operation on this sequence interrupted? |
| 741 | * If so, retry after bumping the sequence number. |
| 742 | */ |
| 743 | if (interrupted) { |
| 744 | ++slot->seq_nr; |
| 745 | goto retry_nowait; |
| 746 | } |
| 747 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 748 | * Could this slot have been previously retired? |
| 749 | * If so, then the server may be expecting seq_nr = 1! |
| 750 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 751 | if (slot->seq_nr != 1) { |
| 752 | slot->seq_nr = 1; |
| 753 | goto retry_nowait; |
| 754 | } |
| 755 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 756 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 757 | ++slot->seq_nr; |
| 758 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 759 | default: |
| 760 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 761 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 762 | } |
| 763 | out: |
| 764 | /* The session may be reset by one of the error handlers. */ |
| 765 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 766 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 767 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 768 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 769 | retry_nowait: |
| 770 | if (rpc_restart_call_prepare(task)) { |
| 771 | task->tk_status = 0; |
| 772 | ret = 0; |
| 773 | } |
| 774 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 775 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 776 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | goto out; |
| 778 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 779 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 780 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 781 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 782 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 783 | 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] | 784 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 785 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 786 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 787 | if (!res->sr_slot->table->session) |
| 788 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 789 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 790 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 791 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 792 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 793 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 794 | struct nfs4_sequence_args *args, |
| 795 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 796 | struct rpc_task *task) |
| 797 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 798 | struct nfs4_slot *slot; |
| 799 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 800 | |
| 801 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 802 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 803 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 804 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 805 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 806 | tbl = &session->fc_slot_table; |
| 807 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 808 | task->tk_timeout = 0; |
| 809 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 810 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 811 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 812 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 813 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 814 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 815 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 816 | } |
| 817 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 818 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 819 | if (IS_ERR(slot)) { |
| 820 | /* If out of memory, try again in 1/4 second */ |
| 821 | if (slot == ERR_PTR(-ENOMEM)) |
| 822 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 823 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 824 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 825 | } |
| 826 | spin_unlock(&tbl->slot_tbl_lock); |
| 827 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 828 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 829 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 830 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 831 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 832 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 833 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 834 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 835 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 836 | /* |
| 837 | * sr_status is only set in decode_sequence, and so will remain |
| 838 | * set to 1 if an rpc level failure occurs. |
| 839 | */ |
| 840 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 841 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 842 | out_success: |
| 843 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 844 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 845 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 846 | /* Privileged tasks are queued with top priority */ |
| 847 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 848 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 849 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 850 | else |
| 851 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 852 | spin_unlock(&tbl->slot_tbl_lock); |
| 853 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 854 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 855 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 856 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 857 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 858 | struct nfs4_sequence_args *args, |
| 859 | struct nfs4_sequence_res *res, |
| 860 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 861 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 862 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 863 | int ret = 0; |
| 864 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 865 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 866 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 867 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 868 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 869 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 870 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 871 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 872 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 873 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 874 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 875 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 876 | return ret; |
| 877 | } |
| 878 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 879 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 880 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 881 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 882 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 883 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 884 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 885 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 886 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 887 | } |
| 888 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 889 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 890 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 891 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 892 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 893 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 894 | } |
| 895 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 896 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 898 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 899 | }; |
| 900 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 901 | #else /* !CONFIG_NFS_V4_1 */ |
| 902 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 903 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 904 | struct nfs4_sequence_args *args, |
| 905 | struct nfs4_sequence_res *res, |
| 906 | struct rpc_task *task) |
| 907 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 908 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 909 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 910 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 911 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 912 | int nfs4_sequence_done(struct rpc_task *task, |
| 913 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 914 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 915 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 916 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 917 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 918 | |
| 919 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 920 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 921 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 922 | { |
| 923 | struct nfs4_call_sync_data *data = calldata; |
| 924 | nfs4_setup_sequence(data->seq_server, |
| 925 | data->seq_args, data->seq_res, task); |
| 926 | } |
| 927 | |
| 928 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 929 | { |
| 930 | struct nfs4_call_sync_data *data = calldata; |
| 931 | nfs4_sequence_done(task, data->seq_res); |
| 932 | } |
| 933 | |
| 934 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 935 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 936 | .rpc_call_done = nfs40_call_sync_done, |
| 937 | }; |
| 938 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 939 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 940 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 941 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 942 | struct nfs4_sequence_args *args, |
| 943 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 944 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 945 | int ret; |
| 946 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 947 | struct nfs_client *clp = server->nfs_client; |
| 948 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 949 | .seq_server = server, |
| 950 | .seq_args = args, |
| 951 | .seq_res = res, |
| 952 | }; |
| 953 | struct rpc_task_setup task_setup = { |
| 954 | .rpc_client = clnt, |
| 955 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 956 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 957 | .callback_data = &data |
| 958 | }; |
| 959 | |
| 960 | task = rpc_run_task(&task_setup); |
| 961 | if (IS_ERR(task)) |
| 962 | ret = PTR_ERR(task); |
| 963 | else { |
| 964 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 965 | rpc_put_task(task); |
| 966 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 967 | return ret; |
| 968 | } |
| 969 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 970 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 971 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 972 | struct rpc_message *msg, |
| 973 | struct nfs4_sequence_args *args, |
| 974 | struct nfs4_sequence_res *res, |
| 975 | int cache_reply) |
| 976 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 977 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 978 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 979 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 982 | { |
| 983 | struct nfs_inode *nfsi = NFS_I(dir); |
| 984 | |
| 985 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 986 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 987 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 989 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 990 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 991 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | spin_unlock(&dir->i_lock); |
| 993 | } |
| 994 | |
| 995 | struct nfs4_opendata { |
| 996 | struct kref kref; |
| 997 | struct nfs_openargs o_arg; |
| 998 | struct nfs_openres o_res; |
| 999 | struct nfs_open_confirmargs c_arg; |
| 1000 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1001 | struct nfs4_string owner_name; |
| 1002 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1003 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1005 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1007 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | struct nfs4_state_owner *owner; |
| 1009 | struct nfs4_state *state; |
| 1010 | struct iattr attrs; |
| 1011 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1012 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1013 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1014 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1015 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | int cancelled; |
| 1017 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1018 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1019 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1020 | int err, struct nfs4_exception *exception) |
| 1021 | { |
| 1022 | if (err != -EINVAL) |
| 1023 | return false; |
| 1024 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1025 | return false; |
| 1026 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1027 | exception->retry = 1; |
| 1028 | return true; |
| 1029 | } |
| 1030 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1031 | static u32 |
| 1032 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1033 | fmode_t fmode, int openflags) |
| 1034 | { |
| 1035 | u32 res = 0; |
| 1036 | |
| 1037 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1038 | case FMODE_READ: |
| 1039 | res = NFS4_SHARE_ACCESS_READ; |
| 1040 | break; |
| 1041 | case FMODE_WRITE: |
| 1042 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1043 | break; |
| 1044 | case FMODE_READ|FMODE_WRITE: |
| 1045 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1046 | } |
| 1047 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1048 | goto out; |
| 1049 | /* Want no delegation if we're using O_DIRECT */ |
| 1050 | if (openflags & O_DIRECT) |
| 1051 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1052 | out: |
| 1053 | return res; |
| 1054 | } |
| 1055 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1056 | static enum open_claim_type4 |
| 1057 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1058 | enum open_claim_type4 claim) |
| 1059 | { |
| 1060 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1061 | return claim; |
| 1062 | switch (claim) { |
| 1063 | default: |
| 1064 | return claim; |
| 1065 | case NFS4_OPEN_CLAIM_FH: |
| 1066 | return NFS4_OPEN_CLAIM_NULL; |
| 1067 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1068 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1069 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1070 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1071 | } |
| 1072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
| 1074 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1075 | { |
| 1076 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1077 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1078 | p->o_res.seqid = p->o_arg.seqid; |
| 1079 | p->c_res.seqid = p->c_arg.seqid; |
| 1080 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1081 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1082 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1083 | 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] | 1084 | } |
| 1085 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1086 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1087 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1088 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1089 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1090 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1091 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1092 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1093 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1094 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1095 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1096 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1097 | struct nfs4_opendata *p; |
| 1098 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1099 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1100 | if (p == NULL) |
| 1101 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1102 | |
| 1103 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1104 | if (IS_ERR(p->f_label)) |
| 1105 | goto err_free_p; |
| 1106 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1107 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1108 | if (IS_ERR(p->a_label)) |
| 1109 | goto err_free_f; |
| 1110 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1111 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1112 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1113 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1114 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1115 | nfs_sb_active(dentry->d_sb); |
| 1116 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1117 | p->dir = parent; |
| 1118 | p->owner = sp; |
| 1119 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1120 | p->o_arg.open_flags = flags; |
| 1121 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1122 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1123 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1124 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1125 | * will return permission denied for all bits until close */ |
| 1126 | if (!(flags & O_EXCL)) { |
| 1127 | /* ask server to check for all possible rights as results |
| 1128 | * are cached */ |
| 1129 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1130 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1131 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1132 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1133 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1134 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1135 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1136 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1137 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1138 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1139 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1140 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1141 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1142 | case NFS4_OPEN_CLAIM_NULL: |
| 1143 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1144 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1145 | p->o_arg.fh = NFS_FH(dir); |
| 1146 | break; |
| 1147 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1148 | case NFS4_OPEN_CLAIM_FH: |
| 1149 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1150 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1151 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1152 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1153 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1154 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1155 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1156 | p->o_arg.u.attrs = &p->attrs; |
| 1157 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1158 | |
| 1159 | verf[0] = jiffies; |
| 1160 | verf[1] = current->pid; |
| 1161 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1162 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1163 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1164 | p->c_arg.fh = &p->o_res.fh; |
| 1165 | p->c_arg.stateid = &p->o_res.stateid; |
| 1166 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1167 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1168 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1169 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1170 | |
| 1171 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1172 | nfs4_label_free(p->a_label); |
| 1173 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1174 | nfs4_label_free(p->f_label); |
| 1175 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1176 | kfree(p); |
| 1177 | err: |
| 1178 | dput(parent); |
| 1179 | return NULL; |
| 1180 | } |
| 1181 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1182 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1184 | struct nfs4_opendata *p = container_of(kref, |
| 1185 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1186 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1187 | |
| 1188 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1189 | if (p->state != NULL) |
| 1190 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1191 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1192 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1193 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1194 | nfs4_label_free(p->f_label); |
| 1195 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1196 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1197 | dput(p->dentry); |
| 1198 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1199 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1200 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1201 | kfree(p); |
| 1202 | } |
| 1203 | |
| 1204 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1205 | { |
| 1206 | if (p != NULL) |
| 1207 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1210 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1211 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1212 | int ret; |
| 1213 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1214 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1215 | return ret; |
| 1216 | } |
| 1217 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1218 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1219 | fmode_t fmode) |
| 1220 | { |
| 1221 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1222 | case FMODE_READ|FMODE_WRITE: |
| 1223 | return state->n_rdwr != 0; |
| 1224 | case FMODE_WRITE: |
| 1225 | return state->n_wronly != 0; |
| 1226 | case FMODE_READ: |
| 1227 | return state->n_rdonly != 0; |
| 1228 | } |
| 1229 | WARN_ON_ONCE(1); |
| 1230 | return false; |
| 1231 | } |
| 1232 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1233 | 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] | 1234 | { |
| 1235 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1236 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1237 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1238 | goto out; |
| 1239 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1240 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1241 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1242 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1243 | break; |
| 1244 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1245 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1246 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1247 | break; |
| 1248 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1249 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1250 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1251 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1252 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1253 | return ret; |
| 1254 | } |
| 1255 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1256 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1257 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1258 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1259 | if (delegation == NULL) |
| 1260 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1261 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1262 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1263 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1264 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1265 | switch (claim) { |
| 1266 | case NFS4_OPEN_CLAIM_NULL: |
| 1267 | case NFS4_OPEN_CLAIM_FH: |
| 1268 | break; |
| 1269 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1270 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1271 | break; |
| 1272 | default: |
| 1273 | return 0; |
| 1274 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1275 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1276 | return 1; |
| 1277 | } |
| 1278 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1279 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1280 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1281 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1282 | case FMODE_WRITE: |
| 1283 | state->n_wronly++; |
| 1284 | break; |
| 1285 | case FMODE_READ: |
| 1286 | state->n_rdonly++; |
| 1287 | break; |
| 1288 | case FMODE_READ|FMODE_WRITE: |
| 1289 | state->n_rdwr++; |
| 1290 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1291 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1292 | } |
| 1293 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1294 | 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] | 1295 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1296 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1297 | bool need_recover = false; |
| 1298 | |
| 1299 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1300 | need_recover = true; |
| 1301 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1302 | need_recover = true; |
| 1303 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1304 | need_recover = true; |
| 1305 | if (need_recover) |
| 1306 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1307 | } |
| 1308 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1309 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1310 | nfs4_stateid *stateid) |
| 1311 | { |
| 1312 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1313 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1314 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1315 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1316 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1317 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1318 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1319 | return true; |
| 1320 | return false; |
| 1321 | } |
| 1322 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1323 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1324 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1325 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1326 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1327 | if (state->n_wronly) |
| 1328 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1329 | if (state->n_rdonly) |
| 1330 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1331 | if (state->n_rdwr) |
| 1332 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1333 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1334 | } |
| 1335 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1336 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1337 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1338 | nfs4_stateid *stateid, fmode_t fmode) |
| 1339 | { |
| 1340 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1341 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1342 | case FMODE_WRITE: |
| 1343 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1344 | break; |
| 1345 | case FMODE_READ: |
| 1346 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1347 | break; |
| 1348 | case 0: |
| 1349 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1350 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1351 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1352 | } |
| 1353 | if (stateid == NULL) |
| 1354 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1355 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1356 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1357 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1358 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1359 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1360 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1361 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1362 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1363 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1364 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1365 | } |
| 1366 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1367 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1368 | nfs4_stateid *arg_stateid, |
| 1369 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1370 | { |
| 1371 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1372 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1373 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1374 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1375 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1376 | } |
| 1377 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1378 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1379 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1380 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1381 | case FMODE_READ: |
| 1382 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1383 | break; |
| 1384 | case FMODE_WRITE: |
| 1385 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1386 | break; |
| 1387 | case FMODE_READ|FMODE_WRITE: |
| 1388 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1389 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1390 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1391 | return; |
| 1392 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1393 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1394 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1395 | } |
| 1396 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1397 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1399 | /* |
| 1400 | * Protect the call to nfs4_state_set_mode_locked and |
| 1401 | * serialise the stateid update |
| 1402 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1403 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1404 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1405 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1406 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1407 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1408 | } |
| 1409 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1410 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1411 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1412 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1413 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1416 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1417 | { |
| 1418 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1419 | struct nfs_delegation *deleg_cur; |
| 1420 | int ret = 0; |
| 1421 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1422 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1423 | |
| 1424 | rcu_read_lock(); |
| 1425 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1426 | if (deleg_cur == NULL) |
| 1427 | goto no_delegation; |
| 1428 | |
| 1429 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1430 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1431 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1432 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1433 | goto no_delegation_unlock; |
| 1434 | |
| 1435 | if (delegation == NULL) |
| 1436 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1437 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1438 | goto no_delegation_unlock; |
| 1439 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1440 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1441 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1442 | ret = 1; |
| 1443 | no_delegation_unlock: |
| 1444 | spin_unlock(&deleg_cur->lock); |
| 1445 | no_delegation: |
| 1446 | rcu_read_unlock(); |
| 1447 | |
| 1448 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1449 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1450 | ret = 1; |
| 1451 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1452 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1453 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1454 | |
| 1455 | return ret; |
| 1456 | } |
| 1457 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1458 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1459 | const nfs4_stateid *stateid) |
| 1460 | { |
| 1461 | struct nfs4_state *state = lsp->ls_state; |
| 1462 | bool ret = false; |
| 1463 | |
| 1464 | spin_lock(&state->state_lock); |
| 1465 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1466 | goto out_noupdate; |
| 1467 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1468 | goto out_noupdate; |
| 1469 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1470 | ret = true; |
| 1471 | out_noupdate: |
| 1472 | spin_unlock(&state->state_lock); |
| 1473 | return ret; |
| 1474 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1475 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1476 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1477 | { |
| 1478 | struct nfs_delegation *delegation; |
| 1479 | |
| 1480 | rcu_read_lock(); |
| 1481 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1482 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1483 | rcu_read_unlock(); |
| 1484 | return; |
| 1485 | } |
| 1486 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1487 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1488 | } |
| 1489 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1490 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1491 | { |
| 1492 | struct nfs4_state *state = opendata->state; |
| 1493 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1494 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1495 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1496 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1497 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1498 | nfs4_stateid stateid; |
| 1499 | int ret = -EAGAIN; |
| 1500 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1501 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1502 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1503 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1504 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1505 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1506 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1507 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1508 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1509 | rcu_read_lock(); |
| 1510 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1511 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1512 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1513 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1514 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1515 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1516 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1517 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1518 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1519 | if (!opendata->is_recover) { |
| 1520 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1521 | if (ret != 0) |
| 1522 | goto out; |
| 1523 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1524 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1525 | |
| 1526 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1527 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1528 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1529 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1530 | out: |
| 1531 | return ERR_PTR(ret); |
| 1532 | out_return_state: |
| 1533 | atomic_inc(&state->count); |
| 1534 | return state; |
| 1535 | } |
| 1536 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1537 | static void |
| 1538 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1539 | { |
| 1540 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1541 | struct nfs_delegation *delegation; |
| 1542 | int delegation_flags = 0; |
| 1543 | |
| 1544 | rcu_read_lock(); |
| 1545 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1546 | if (delegation) |
| 1547 | delegation_flags = delegation->flags; |
| 1548 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1549 | switch (data->o_arg.claim) { |
| 1550 | default: |
| 1551 | break; |
| 1552 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1553 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1554 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1555 | "returning a delegation for " |
| 1556 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1557 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1558 | return; |
| 1559 | } |
| 1560 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1561 | nfs_inode_set_delegation(state->inode, |
| 1562 | data->owner->so_cred, |
| 1563 | &data->o_res); |
| 1564 | else |
| 1565 | nfs_inode_reclaim_delegation(state->inode, |
| 1566 | data->owner->so_cred, |
| 1567 | &data->o_res); |
| 1568 | } |
| 1569 | |
| 1570 | /* |
| 1571 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1572 | * and update the nfs4_state. |
| 1573 | */ |
| 1574 | static struct nfs4_state * |
| 1575 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1576 | { |
| 1577 | struct inode *inode = data->state->inode; |
| 1578 | struct nfs4_state *state = data->state; |
| 1579 | int ret; |
| 1580 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1581 | if (!data->rpc_done) { |
| 1582 | if (data->rpc_status) { |
| 1583 | ret = data->rpc_status; |
| 1584 | goto err; |
| 1585 | } |
| 1586 | /* cached opens have already been processed */ |
| 1587 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1590 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1591 | if (ret) |
| 1592 | goto err; |
| 1593 | |
| 1594 | if (data->o_res.delegation_type != 0) |
| 1595 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1596 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1597 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1598 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1599 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1600 | |
| 1601 | return state; |
| 1602 | err: |
| 1603 | return ERR_PTR(ret); |
| 1604 | |
| 1605 | } |
| 1606 | |
| 1607 | static struct nfs4_state * |
| 1608 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1609 | { |
| 1610 | struct inode *inode; |
| 1611 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1612 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1613 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1614 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1615 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1616 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1617 | goto out; |
| 1618 | } |
| 1619 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1620 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1621 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1622 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1623 | 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] | 1624 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1625 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1626 | goto err; |
| 1627 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1628 | state = nfs4_get_open_state(inode, data->owner); |
| 1629 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1630 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1631 | if (data->o_res.delegation_type != 0) |
| 1632 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1633 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1634 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1635 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1636 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1637 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1638 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1639 | err_put_inode: |
| 1640 | iput(inode); |
| 1641 | err: |
| 1642 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1643 | } |
| 1644 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1645 | static struct nfs4_state * |
| 1646 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1647 | { |
| 1648 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1649 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1650 | return _nfs4_opendata_to_nfs4_state(data); |
| 1651 | } |
| 1652 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1653 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1654 | { |
| 1655 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1656 | struct nfs_open_context *ctx; |
| 1657 | |
| 1658 | spin_lock(&state->inode->i_lock); |
| 1659 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1660 | if (ctx->state != state) |
| 1661 | continue; |
| 1662 | get_nfs_open_context(ctx); |
| 1663 | spin_unlock(&state->inode->i_lock); |
| 1664 | return ctx; |
| 1665 | } |
| 1666 | spin_unlock(&state->inode->i_lock); |
| 1667 | return ERR_PTR(-ENOENT); |
| 1668 | } |
| 1669 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1670 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1671 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1672 | { |
| 1673 | struct nfs4_opendata *opendata; |
| 1674 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1675 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1676 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1677 | if (opendata == NULL) |
| 1678 | return ERR_PTR(-ENOMEM); |
| 1679 | opendata->state = state; |
| 1680 | atomic_inc(&state->count); |
| 1681 | return opendata; |
| 1682 | } |
| 1683 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1684 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1685 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1686 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1687 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1688 | int ret; |
| 1689 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1690 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1691 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1692 | opendata->o_arg.open_flags = 0; |
| 1693 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1694 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1695 | NFS_SB(opendata->dentry->d_sb), |
| 1696 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1697 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1698 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1699 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1700 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1701 | if (ret != 0) |
| 1702 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1703 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1704 | if (IS_ERR(newstate)) |
| 1705 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1706 | if (newstate != opendata->state) |
| 1707 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1708 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1709 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1713 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1714 | int ret; |
| 1715 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1716 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1717 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1718 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1719 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1720 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1721 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1722 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1724 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1725 | if (ret != 0) |
| 1726 | return ret; |
| 1727 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1728 | if (ret != 0) |
| 1729 | return ret; |
| 1730 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1731 | if (ret != 0) |
| 1732 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1733 | /* |
| 1734 | * We may have performed cached opens for all three recoveries. |
| 1735 | * Check if we need to update the current stateid. |
| 1736 | */ |
| 1737 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1738 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1739 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1740 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1741 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1742 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1743 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1744 | return 0; |
| 1745 | } |
| 1746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | /* |
| 1748 | * OPEN_RECLAIM: |
| 1749 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1751 | 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] | 1752 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1753 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1754 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1755 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | int status; |
| 1757 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1758 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1759 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1760 | if (IS_ERR(opendata)) |
| 1761 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1762 | rcu_read_lock(); |
| 1763 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1764 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1765 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1766 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1767 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1768 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1769 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return status; |
| 1771 | } |
| 1772 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1773 | 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] | 1774 | { |
| 1775 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1776 | struct nfs4_exception exception = { }; |
| 1777 | int err; |
| 1778 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1779 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1780 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1781 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1782 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1783 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1784 | break; |
| 1785 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | } while (exception.retry); |
| 1787 | return err; |
| 1788 | } |
| 1789 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1790 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1791 | { |
| 1792 | struct nfs_open_context *ctx; |
| 1793 | int ret; |
| 1794 | |
| 1795 | ctx = nfs4_state_find_open_context(state); |
| 1796 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1797 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1798 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1799 | put_nfs_open_context(ctx); |
| 1800 | return ret; |
| 1801 | } |
| 1802 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1803 | 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] | 1804 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1805 | switch (err) { |
| 1806 | default: |
| 1807 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1808 | "%d.\n", __func__, err); |
| 1809 | case 0: |
| 1810 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1811 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1812 | case -ESTALE: |
| 1813 | break; |
| 1814 | case -NFS4ERR_BADSESSION: |
| 1815 | case -NFS4ERR_BADSLOT: |
| 1816 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1817 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1818 | case -NFS4ERR_DEADSESSION: |
| 1819 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1820 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1821 | return -EAGAIN; |
| 1822 | case -NFS4ERR_STALE_CLIENTID: |
| 1823 | case -NFS4ERR_STALE_STATEID: |
| 1824 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1825 | case -NFS4ERR_EXPIRED: |
| 1826 | /* Don't recall a delegation if it was lost */ |
| 1827 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1828 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1829 | case -NFS4ERR_MOVED: |
| 1830 | nfs4_schedule_migration_recovery(server); |
| 1831 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1832 | case -NFS4ERR_LEASE_MOVED: |
| 1833 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1834 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1835 | case -NFS4ERR_DELEG_REVOKED: |
| 1836 | case -NFS4ERR_ADMIN_REVOKED: |
| 1837 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1838 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1839 | nfs_inode_find_state_and_recover(state->inode, |
| 1840 | stateid); |
| 1841 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1842 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1843 | case -NFS4ERR_DELAY: |
| 1844 | case -NFS4ERR_GRACE: |
| 1845 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1846 | ssleep(1); |
| 1847 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1848 | case -ENOMEM: |
| 1849 | case -NFS4ERR_DENIED: |
| 1850 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1851 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | return err; |
| 1854 | } |
| 1855 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1856 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1857 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1858 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1859 | { |
| 1860 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1861 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1862 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1863 | |
| 1864 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1865 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1866 | if (IS_ERR(opendata)) |
| 1867 | return PTR_ERR(opendata); |
| 1868 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1869 | write_seqlock(&state->seqlock); |
| 1870 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1871 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1872 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1873 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1874 | case FMODE_READ|FMODE_WRITE: |
| 1875 | case FMODE_WRITE: |
| 1876 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1877 | if (err) |
| 1878 | break; |
| 1879 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1880 | if (err) |
| 1881 | break; |
| 1882 | case FMODE_READ: |
| 1883 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1884 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1885 | nfs4_opendata_put(opendata); |
| 1886 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1887 | } |
| 1888 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1889 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1890 | { |
| 1891 | struct nfs4_opendata *data = calldata; |
| 1892 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1893 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1894 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1897 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1898 | { |
| 1899 | struct nfs4_opendata *data = calldata; |
| 1900 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1901 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1902 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1903 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1904 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1905 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1906 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1907 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1908 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1909 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | static void nfs4_open_confirm_release(void *calldata) |
| 1913 | { |
| 1914 | struct nfs4_opendata *data = calldata; |
| 1915 | struct nfs4_state *state = NULL; |
| 1916 | |
| 1917 | /* If this request hasn't been cancelled, do nothing */ |
| 1918 | if (data->cancelled == 0) |
| 1919 | goto out_free; |
| 1920 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1921 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1922 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1923 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1924 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1925 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1926 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1927 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1931 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1932 | .rpc_call_done = nfs4_open_confirm_done, |
| 1933 | .rpc_release = nfs4_open_confirm_release, |
| 1934 | }; |
| 1935 | |
| 1936 | /* |
| 1937 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1938 | */ |
| 1939 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1940 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1941 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1942 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1943 | struct rpc_message msg = { |
| 1944 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1945 | .rpc_argp = &data->c_arg, |
| 1946 | .rpc_resp = &data->c_res, |
| 1947 | .rpc_cred = data->owner->so_cred, |
| 1948 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1949 | struct rpc_task_setup task_setup_data = { |
| 1950 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1951 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1952 | .callback_ops = &nfs4_open_confirm_ops, |
| 1953 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1954 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1955 | .flags = RPC_TASK_ASYNC, |
| 1956 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | int status; |
| 1958 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1959 | 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] | 1960 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1961 | data->rpc_done = 0; |
| 1962 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1963 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 1964 | if (data->is_recover) |
| 1965 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1966 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1967 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1968 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1969 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1970 | if (status != 0) { |
| 1971 | data->cancelled = 1; |
| 1972 | smp_wmb(); |
| 1973 | } else |
| 1974 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1975 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | return status; |
| 1977 | } |
| 1978 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1979 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1981 | struct nfs4_opendata *data = calldata; |
| 1982 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1983 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1984 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1985 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1986 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1987 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1988 | /* |
| 1989 | * Check if we still need to send an OPEN call, or if we can use |
| 1990 | * a delegation instead. |
| 1991 | */ |
| 1992 | if (data->state != NULL) { |
| 1993 | struct nfs_delegation *delegation; |
| 1994 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1995 | 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] | 1996 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1997 | rcu_read_lock(); |
| 1998 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1999 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2000 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2001 | rcu_read_unlock(); |
| 2002 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2003 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2004 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2005 | switch (claim) { |
| 2006 | default: |
| 2007 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2008 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2009 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2010 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2011 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2012 | case NFS4_OPEN_CLAIM_FH: |
| 2013 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2014 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2015 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2016 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2017 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2018 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2019 | &data->o_res.seq_res, |
| 2020 | task) != 0) |
| 2021 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2022 | |
| 2023 | /* Set the create mode (note dependency on the session type) */ |
| 2024 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2025 | if (data->o_arg.open_flags & O_EXCL) { |
| 2026 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2027 | if (nfs4_has_persistent_session(clp)) |
| 2028 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2029 | else if (clp->cl_mvops->minor_version > 0) |
| 2030 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2031 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2032 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2033 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2034 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2035 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2036 | out_no_action: |
| 2037 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2038 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2039 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2040 | } |
| 2041 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2042 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2043 | { |
| 2044 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2046 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2047 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2048 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 2049 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2050 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2051 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2052 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2053 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2054 | case S_IFREG: |
| 2055 | break; |
| 2056 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2057 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2058 | break; |
| 2059 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2060 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2061 | break; |
| 2062 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2063 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2064 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2065 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2066 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2067 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2068 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2069 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2070 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2071 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2072 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2073 | static void nfs4_open_release(void *calldata) |
| 2074 | { |
| 2075 | struct nfs4_opendata *data = calldata; |
| 2076 | struct nfs4_state *state = NULL; |
| 2077 | |
| 2078 | /* If this request hasn't been cancelled, do nothing */ |
| 2079 | if (data->cancelled == 0) |
| 2080 | goto out_free; |
| 2081 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2082 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2083 | goto out_free; |
| 2084 | /* In case we need an open_confirm, no cleanup! */ |
| 2085 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2086 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2087 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2088 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2089 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2090 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2091 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2095 | .rpc_call_prepare = nfs4_open_prepare, |
| 2096 | .rpc_call_done = nfs4_open_done, |
| 2097 | .rpc_release = nfs4_open_release, |
| 2098 | }; |
| 2099 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2100 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2101 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2102 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2103 | struct nfs_server *server = NFS_SERVER(dir); |
| 2104 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2105 | struct nfs_openres *o_res = &data->o_res; |
| 2106 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2107 | struct rpc_message msg = { |
| 2108 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2109 | .rpc_argp = o_arg, |
| 2110 | .rpc_resp = o_res, |
| 2111 | .rpc_cred = data->owner->so_cred, |
| 2112 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2113 | struct rpc_task_setup task_setup_data = { |
| 2114 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2115 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2116 | .callback_ops = &nfs4_open_ops, |
| 2117 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2118 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2119 | .flags = RPC_TASK_ASYNC, |
| 2120 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2121 | int status; |
| 2122 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2123 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2124 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2125 | data->rpc_done = 0; |
| 2126 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2127 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2128 | data->is_recover = 0; |
| 2129 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2130 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2131 | data->is_recover = 1; |
| 2132 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2133 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2134 | if (IS_ERR(task)) |
| 2135 | return PTR_ERR(task); |
| 2136 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2137 | if (status != 0) { |
| 2138 | data->cancelled = 1; |
| 2139 | smp_wmb(); |
| 2140 | } else |
| 2141 | status = data->rpc_status; |
| 2142 | rpc_put_task(task); |
| 2143 | |
| 2144 | return status; |
| 2145 | } |
| 2146 | |
| 2147 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2148 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2149 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2150 | struct nfs_openres *o_res = &data->o_res; |
| 2151 | int status; |
| 2152 | |
| 2153 | status = nfs4_run_open_task(data, 1); |
| 2154 | if (status != 0 || !data->rpc_done) |
| 2155 | return status; |
| 2156 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2157 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2158 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2159 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2160 | status = _nfs4_proc_open_confirm(data); |
| 2161 | if (status != 0) |
| 2162 | return status; |
| 2163 | } |
| 2164 | |
| 2165 | return status; |
| 2166 | } |
| 2167 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2168 | /* |
| 2169 | * Additional permission checks in order to distinguish between an |
| 2170 | * open for read, and an open for execute. This works around the |
| 2171 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2172 | * the same. |
| 2173 | * Note that in the non-execute case, we want to turn off permission |
| 2174 | * checking if we just created a new file (POSIX open() semantics). |
| 2175 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2176 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2177 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2178 | struct nfs4_state *state, fmode_t fmode, |
| 2179 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2180 | { |
| 2181 | struct nfs_access_entry cache; |
| 2182 | u32 mask; |
| 2183 | |
| 2184 | /* access call failed or for some reason the server doesn't |
| 2185 | * support any access modes -- defer access call until later */ |
| 2186 | if (opendata->o_res.access_supported == 0) |
| 2187 | return 0; |
| 2188 | |
| 2189 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2190 | /* |
| 2191 | * Use openflags to check for exec, because fmode won't |
| 2192 | * always have FMODE_EXEC set when file open for exec. |
| 2193 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2194 | if (openflags & __FMODE_EXEC) { |
| 2195 | /* ONLY check for exec rights */ |
| 2196 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2197 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2198 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2199 | |
| 2200 | cache.cred = cred; |
| 2201 | cache.jiffies = jiffies; |
| 2202 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2203 | nfs_access_add_cache(state->inode, &cache); |
| 2204 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2205 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2206 | return 0; |
| 2207 | |
| 2208 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2209 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2210 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2211 | } |
| 2212 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2213 | /* |
| 2214 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2215 | */ |
| 2216 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2217 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2218 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2219 | struct nfs_server *server = NFS_SERVER(dir); |
| 2220 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2221 | struct nfs_openres *o_res = &data->o_res; |
| 2222 | int status; |
| 2223 | |
| 2224 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2225 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2226 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2227 | if (status != 0) { |
| 2228 | if (status == -NFS4ERR_BADNAME && |
| 2229 | !(o_arg->open_flags & O_CREAT)) |
| 2230 | return -ENOENT; |
| 2231 | return status; |
| 2232 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2233 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2234 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2235 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2236 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2237 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2238 | if (o_arg->open_flags & O_EXCL) |
| 2239 | data->file_created = 1; |
| 2240 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2241 | data->file_created = 1; |
| 2242 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2243 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2244 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2246 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2248 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | } |
| 2250 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2251 | 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] | 2252 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2255 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2256 | { |
| 2257 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2258 | } |
| 2259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | /* |
| 2261 | * OPEN_EXPIRED: |
| 2262 | * reclaim state on the server after a network partition. |
| 2263 | * Assumes caller holds the appropriate lock |
| 2264 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2265 | 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] | 2266 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2267 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2268 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2270 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2271 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2272 | if (IS_ERR(opendata)) |
| 2273 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2274 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2275 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2276 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2277 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2278 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2281 | 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] | 2282 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2283 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2284 | struct nfs4_exception exception = { }; |
| 2285 | int err; |
| 2286 | |
| 2287 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2288 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2289 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2290 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2291 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2292 | switch (err) { |
| 2293 | default: |
| 2294 | goto out; |
| 2295 | case -NFS4ERR_GRACE: |
| 2296 | case -NFS4ERR_DELAY: |
| 2297 | nfs4_handle_exception(server, err, &exception); |
| 2298 | err = 0; |
| 2299 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2300 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2301 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2302 | return err; |
| 2303 | } |
| 2304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2308 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2310 | ctx = nfs4_state_find_open_context(state); |
| 2311 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2312 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2313 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2314 | put_nfs_open_context(ctx); |
| 2315 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2318 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2319 | { |
| 2320 | nfs_remove_bad_delegation(state->inode); |
| 2321 | write_seqlock(&state->seqlock); |
| 2322 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2323 | write_sequnlock(&state->seqlock); |
| 2324 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2325 | } |
| 2326 | |
| 2327 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2328 | { |
| 2329 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2330 | nfs_finish_clear_delegation_stateid(state); |
| 2331 | } |
| 2332 | |
| 2333 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2334 | { |
| 2335 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2336 | nfs40_clear_delegation_stateid(state); |
| 2337 | return nfs4_open_expired(sp, state); |
| 2338 | } |
| 2339 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2340 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2341 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2342 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2343 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2344 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2345 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2346 | struct rpc_cred *cred; |
| 2347 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2348 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2349 | /* Get the delegation credential for use by test/free_stateid */ |
| 2350 | rcu_read_lock(); |
| 2351 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2352 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2353 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2354 | return; |
| 2355 | } |
| 2356 | |
| 2357 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2358 | cred = get_rpccred(delegation->cred); |
| 2359 | rcu_read_unlock(); |
| 2360 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2361 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2362 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2363 | if (status != NFS_OK) { |
| 2364 | /* Free the stateid unless the server explicitly |
| 2365 | * informs us the stateid is unrecognized. */ |
| 2366 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2367 | nfs41_free_stateid(server, &stateid, cred); |
| 2368 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2369 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2370 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2371 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | /** |
| 2375 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2376 | * |
| 2377 | * @state: NFSv4 state for an inode |
| 2378 | * |
| 2379 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2380 | * Otherwise a negative NFS4ERR value is returned. |
| 2381 | */ |
| 2382 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2383 | { |
| 2384 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2385 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2386 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2387 | int status; |
| 2388 | |
| 2389 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2390 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2391 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2392 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2393 | return -NFS4ERR_BAD_STATEID; |
| 2394 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2395 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2396 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2397 | if (status != NFS_OK) { |
| 2398 | /* Free the stateid unless the server explicitly |
| 2399 | * informs us the stateid is unrecognized. */ |
| 2400 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2401 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2402 | |
| 2403 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2404 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2405 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2406 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2407 | } |
| 2408 | return status; |
| 2409 | } |
| 2410 | |
| 2411 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2412 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2413 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2414 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2415 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2416 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2417 | if (status != NFS_OK) |
| 2418 | status = nfs4_open_expired(sp, state); |
| 2419 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2420 | } |
| 2421 | #endif |
| 2422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2424 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2425 | * fields corresponding to attributes that were used to store the verifier. |
| 2426 | * Make sure we clobber those fields in the later setattr call |
| 2427 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2428 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2429 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2430 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2431 | const u32 *attrset = opendata->o_res.attrset; |
| 2432 | |
| 2433 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2434 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2435 | sattr->ia_valid |= ATTR_ATIME; |
| 2436 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2437 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2438 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2439 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2440 | |
| 2441 | /* Except MODE, it seems harmless of setting twice. */ |
| 2442 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2443 | sattr->ia_valid &= ~ATTR_MODE; |
| 2444 | |
| 2445 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2446 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2449 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2450 | fmode_t fmode, |
| 2451 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2452 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2453 | { |
| 2454 | struct nfs4_state_owner *sp = opendata->owner; |
| 2455 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2456 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2457 | struct nfs4_state *state; |
| 2458 | unsigned int seq; |
| 2459 | int ret; |
| 2460 | |
| 2461 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2462 | |
| 2463 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2464 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2465 | goto out; |
| 2466 | |
| 2467 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2468 | ret = PTR_ERR(state); |
| 2469 | if (IS_ERR(state)) |
| 2470 | goto out; |
| 2471 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2472 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2473 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2474 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2475 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2476 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2477 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2478 | alias = d_exact_alias(dentry, state->inode); |
| 2479 | if (!alias) |
| 2480 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2481 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2482 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2483 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2484 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2485 | } |
| 2486 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2487 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2488 | } |
| 2489 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2490 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2491 | if (ret != 0) |
| 2492 | goto out; |
| 2493 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2494 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2495 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2496 | nfs_inode_attach_open_context(ctx); |
| 2497 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2498 | nfs4_schedule_stateid_recovery(server, state); |
| 2499 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2500 | out: |
| 2501 | return ret; |
| 2502 | } |
| 2503 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2504 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2505 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2507 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2508 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2509 | int flags, |
| 2510 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2511 | struct nfs4_label *label, |
| 2512 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | { |
| 2514 | struct nfs4_state_owner *sp; |
| 2515 | struct nfs4_state *state = NULL; |
| 2516 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2517 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2518 | struct dentry *dentry = ctx->dentry; |
| 2519 | struct rpc_cred *cred = ctx->cred; |
| 2520 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2521 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2522 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2523 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2524 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | |
| 2526 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2528 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2529 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2531 | goto out_err; |
| 2532 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2533 | status = nfs4_recover_expired_lease(server); |
| 2534 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2535 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2536 | if (d_really_is_positive(dentry)) |
| 2537 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2538 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2539 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2540 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2541 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2542 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2543 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2544 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2546 | if (label) { |
| 2547 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2548 | if (IS_ERR(olabel)) { |
| 2549 | status = PTR_ERR(olabel); |
| 2550 | goto err_opendata_put; |
| 2551 | } |
| 2552 | } |
| 2553 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2554 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2555 | if (!opendata->f_attr.mdsthreshold) { |
| 2556 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2557 | if (!opendata->f_attr.mdsthreshold) |
| 2558 | goto err_free_label; |
| 2559 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2560 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2561 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2562 | if (d_really_is_positive(dentry)) |
| 2563 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2564 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2565 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2566 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2567 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2568 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2569 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2570 | 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] | 2571 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2572 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2573 | /* |
| 2574 | * send create attributes which was not set by open |
| 2575 | * with an extra setattr. |
| 2576 | */ |
| 2577 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2578 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2579 | status = nfs4_do_setattr(state->inode, cred, |
| 2580 | opendata->o_res.f_attr, sattr, |
| 2581 | state, label, olabel); |
| 2582 | if (status == 0) { |
| 2583 | nfs_setattr_update_inode(state->inode, sattr, |
| 2584 | opendata->o_res.f_attr); |
| 2585 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2586 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2587 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2588 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2589 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2590 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2591 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2592 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2593 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2594 | opendata->f_attr.mdsthreshold = NULL; |
| 2595 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2596 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2597 | nfs4_label_free(olabel); |
| 2598 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2599 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2602 | err_free_label: |
| 2603 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2604 | err_opendata_put: |
| 2605 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2606 | err_put_state_owner: |
| 2607 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | return status; |
| 2610 | } |
| 2611 | |
| 2612 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2613 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2614 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2615 | int flags, |
| 2616 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2617 | struct nfs4_label *label, |
| 2618 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2620 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | struct nfs4_exception exception = { }; |
| 2622 | struct nfs4_state *res; |
| 2623 | int status; |
| 2624 | |
| 2625 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2626 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2627 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2628 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | if (status == 0) |
| 2630 | break; |
| 2631 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2632 | * book-keeping w.r.t. state-changing operations |
| 2633 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2634 | * It is actually a sign of a bug on the client or on the server. |
| 2635 | * |
| 2636 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2637 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | * have unhashed the old state_owner for us, and that we can |
| 2639 | * therefore safely retry using a new one. We should still warn |
| 2640 | * the user though... |
| 2641 | */ |
| 2642 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2643 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2644 | " returned a bad sequence-id error!\n", |
| 2645 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | exception.retry = 1; |
| 2647 | continue; |
| 2648 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2649 | /* |
| 2650 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2651 | * state before it received the OPEN_CONFIRM. |
| 2652 | * Recover by retrying the request as per the discussion |
| 2653 | * on Page 181 of RFC3530. |
| 2654 | */ |
| 2655 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2656 | exception.retry = 1; |
| 2657 | continue; |
| 2658 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2659 | if (status == -EAGAIN) { |
| 2660 | /* We must have found a delegation */ |
| 2661 | exception.retry = 1; |
| 2662 | continue; |
| 2663 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2664 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2665 | continue; |
| 2666 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | status, &exception)); |
| 2668 | } while (exception.retry); |
| 2669 | return res; |
| 2670 | } |
| 2671 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2672 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2673 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2674 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2675 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2677 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2679 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | .iap = sattr, |
| 2681 | .server = server, |
| 2682 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2683 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | }; |
| 2685 | struct nfs_setattrres res = { |
| 2686 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2687 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | .server = server, |
| 2689 | }; |
| 2690 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2691 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2692 | .rpc_argp = &arg, |
| 2693 | .rpc_resp = &res, |
| 2694 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | }; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 2696 | struct rpc_cred *delegation_cred = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2697 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2698 | fmode_t fmode; |
| 2699 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2700 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2702 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2703 | if (ilabel) |
| 2704 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2705 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2706 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2708 | /* Servers should only apply open mode checks for file size changes */ |
| 2709 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2710 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2711 | |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 2712 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg.stateid, &delegation_cred)) { |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2713 | /* Use that stateid */ |
Trond Myklebust | 0418dae1 | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2714 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2715 | struct nfs_lockowner lockowner = { |
| 2716 | .l_owner = current->files, |
| 2717 | .l_pid = current->tgid, |
| 2718 | }; |
Trond Myklebust | 0418dae1 | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2719 | if (!nfs4_valid_open_stateid(state)) |
| 2720 | return -EBADF; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 2721 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2722 | &arg.stateid, &delegation_cred) == -EIO) |
Trond Myklebust | 0418dae1 | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2723 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2724 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2725 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 2726 | if (delegation_cred) |
| 2727 | msg.rpc_cred = delegation_cred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2729 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 2730 | |
| 2731 | put_rpccred(delegation_cred); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2732 | if (status == 0 && state != NULL) |
| 2733 | renew_lease(server, timestamp); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 2734 | trace_nfs4_setattr(inode, &arg.stateid, status); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2735 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2738 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2739 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2740 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2741 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2743 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2744 | struct nfs4_exception exception = { |
| 2745 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2746 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2747 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | int err; |
| 2749 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2750 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2751 | switch (err) { |
| 2752 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2753 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2754 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2755 | "applying open mode checks to " |
| 2756 | "a SETATTR that is not " |
| 2757 | "changing file size.\n", |
| 2758 | server->nfs_client->cl_hostname); |
| 2759 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2760 | if (state && !(state->state & FMODE_WRITE)) { |
| 2761 | err = -EBADF; |
| 2762 | if (sattr->ia_valid & ATTR_OPEN) |
| 2763 | err = -EACCES; |
| 2764 | goto out; |
| 2765 | } |
| 2766 | } |
| 2767 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2769 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | return err; |
| 2771 | } |
| 2772 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2773 | static bool |
| 2774 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2775 | { |
| 2776 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2777 | return false; |
| 2778 | |
| 2779 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2780 | } |
| 2781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | struct nfs4_closedata { |
| 2783 | struct inode *inode; |
| 2784 | struct nfs4_state *state; |
| 2785 | struct nfs_closeargs arg; |
| 2786 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2787 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2788 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2789 | bool roc; |
| 2790 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | }; |
| 2792 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2793 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2794 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2795 | struct nfs4_closedata *calldata = data; |
| 2796 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2797 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2798 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2799 | if (calldata->roc) |
| 2800 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2801 | nfs4_put_open_state(calldata->state); |
| 2802 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2803 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2804 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2805 | kfree(calldata); |
| 2806 | } |
| 2807 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2808 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2810 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2813 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2815 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2816 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2817 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2818 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | /* hmm. we are done with the inode, and in the process of freeing |
| 2820 | * the state_owner. we keep this around to process errors |
| 2821 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | switch (task->tk_status) { |
| 2823 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2824 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2825 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2826 | pnfs_roc_set_barrier(state->inode, |
| 2827 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2828 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2829 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2830 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2832 | case -NFS4ERR_OLD_STATEID: |
| 2833 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2835 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2836 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2837 | rpc_restart_call_prepare(task); |
| 2838 | goto out_release; |
| 2839 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2840 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2841 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2843 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2844 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2845 | goto out_release; |
| 2846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2848 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2849 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2850 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2851 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2852 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2853 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2856 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2858 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2859 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2860 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2861 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2862 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2863 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2864 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2865 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2866 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2867 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2868 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2869 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2870 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2871 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2872 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2873 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2874 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2875 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2876 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2877 | if (state->n_rdonly == 0) |
| 2878 | call_close |= is_rdonly; |
| 2879 | else if (is_rdonly) |
| 2880 | calldata->arg.fmode |= FMODE_READ; |
| 2881 | if (state->n_wronly == 0) |
| 2882 | call_close |= is_wronly; |
| 2883 | else if (is_wronly) |
| 2884 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 2885 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 2886 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2887 | } else if (is_rdwr) |
| 2888 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2889 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2890 | if (!nfs4_valid_open_stateid(state)) |
| 2891 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2892 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2893 | |
| 2894 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2895 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2896 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2897 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2898 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2899 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2900 | nfs_release_seqid(calldata->arg.seqid); |
| 2901 | goto out_wait; |
| 2902 | } |
| 2903 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2904 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2905 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2906 | if (calldata->roc) |
| 2907 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2908 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2909 | calldata->arg.share_access = |
| 2910 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2911 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2912 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2913 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2914 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2915 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2916 | &calldata->arg.seq_args, |
| 2917 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2918 | task) != 0) |
| 2919 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2920 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2921 | return; |
| 2922 | out_no_action: |
| 2923 | task->tk_action = NULL; |
| 2924 | out_wait: |
| 2925 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | } |
| 2927 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2928 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2929 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2930 | .rpc_call_done = nfs4_close_done, |
| 2931 | .rpc_release = nfs4_free_closedata, |
| 2932 | }; |
| 2933 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2934 | static bool nfs4_roc(struct inode *inode) |
| 2935 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 2936 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2937 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2938 | return pnfs_roc(inode); |
| 2939 | } |
| 2940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | /* |
| 2942 | * It is possible for data to be read/written from a mem-mapped file |
| 2943 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2944 | * This means that we can't safely call nfsv4 close on a file until |
| 2945 | * the inode is cleared. This in turn means that we are not good |
| 2946 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2947 | * share state even when we are done with one of the three share |
| 2948 | * stateid's in the inode. |
| 2949 | * |
| 2950 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2951 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2952 | 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] | 2953 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2954 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2955 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2957 | struct nfs4_state_owner *sp = state->owner; |
| 2958 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2959 | struct rpc_message msg = { |
| 2960 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2961 | .rpc_cred = state->owner->so_cred, |
| 2962 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2963 | struct rpc_task_setup task_setup_data = { |
| 2964 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2965 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2966 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2967 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2968 | .flags = RPC_TASK_ASYNC, |
| 2969 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2970 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2972 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2973 | &task_setup_data.rpc_client, &msg); |
| 2974 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2975 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2977 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2978 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2979 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2981 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2983 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 2984 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 2985 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2986 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2987 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2988 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2989 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2990 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2991 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2992 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2993 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2994 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2995 | msg.rpc_argp = &calldata->arg; |
| 2996 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2997 | task_setup_data.callback_data = calldata; |
| 2998 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2999 | if (IS_ERR(task)) |
| 3000 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3001 | status = 0; |
| 3002 | if (wait) |
| 3003 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3004 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3005 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3006 | out_free_calldata: |
| 3007 | kfree(calldata); |
| 3008 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3009 | nfs4_put_open_state(state); |
| 3010 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3011 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3014 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3015 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3016 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3019 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3020 | |
| 3021 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3023 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3024 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3025 | |
| 3026 | nfs4_label_release_security(label); |
| 3027 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3028 | if (IS_ERR(state)) |
| 3029 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3030 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3033 | 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] | 3034 | { |
| 3035 | if (ctx->state == NULL) |
| 3036 | return; |
| 3037 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3038 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3039 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3040 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3041 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3043 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3044 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3045 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3048 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3049 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3050 | struct nfs4_server_caps_arg args = { |
| 3051 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3052 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3053 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | struct nfs4_server_caps_res res = {}; |
| 3055 | struct rpc_message msg = { |
| 3056 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3057 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | .rpc_resp = &res, |
| 3059 | }; |
| 3060 | int status; |
| 3061 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3062 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3063 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3064 | FATTR4_WORD0_LINK_SUPPORT | |
| 3065 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3066 | FATTR4_WORD0_ACLSUPPORT; |
| 3067 | if (minorversion) |
| 3068 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3069 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3070 | 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] | 3071 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3072 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3073 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3074 | case 0: |
| 3075 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3076 | res.attr_bitmask[2] = 0; |
| 3077 | break; |
| 3078 | case 1: |
| 3079 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3080 | break; |
| 3081 | case 2: |
| 3082 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3083 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3085 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3086 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3087 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3088 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3089 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3090 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3091 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3092 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | server->caps |= NFS_CAP_ACLS; |
| 3094 | if (res.has_links != 0) |
| 3095 | server->caps |= NFS_CAP_HARDLINKS; |
| 3096 | if (res.has_symlinks != 0) |
| 3097 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3098 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3099 | server->caps |= NFS_CAP_FILEID; |
| 3100 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3101 | server->caps |= NFS_CAP_MODE; |
| 3102 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3103 | server->caps |= NFS_CAP_NLINK; |
| 3104 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3105 | server->caps |= NFS_CAP_OWNER; |
| 3106 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3107 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3108 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3109 | server->caps |= NFS_CAP_ATIME; |
| 3110 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3111 | server->caps |= NFS_CAP_CTIME; |
| 3112 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3113 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3114 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3115 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3116 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3117 | #endif |
| 3118 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3119 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3120 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3121 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3122 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3123 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3124 | 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] | 3125 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3126 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3127 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3129 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | return status; |
| 3133 | } |
| 3134 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3135 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | { |
| 3137 | struct nfs4_exception exception = { }; |
| 3138 | int err; |
| 3139 | do { |
| 3140 | err = nfs4_handle_exception(server, |
| 3141 | _nfs4_server_capabilities(server, fhandle), |
| 3142 | &exception); |
| 3143 | } while (exception.retry); |
| 3144 | return err; |
| 3145 | } |
| 3146 | |
| 3147 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3148 | struct nfs_fsinfo *info) |
| 3149 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3150 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3152 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | }; |
| 3154 | struct nfs4_lookup_res res = { |
| 3155 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3156 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | .fh = fhandle, |
| 3158 | }; |
| 3159 | struct rpc_message msg = { |
| 3160 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3161 | .rpc_argp = &args, |
| 3162 | .rpc_resp = &res, |
| 3163 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3164 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3165 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3166 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3167 | /* |
| 3168 | * Process the label in the upcoming getfattr |
| 3169 | */ |
| 3170 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3171 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3172 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3173 | 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] | 3174 | } |
| 3175 | |
| 3176 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3177 | struct nfs_fsinfo *info) |
| 3178 | { |
| 3179 | struct nfs4_exception exception = { }; |
| 3180 | int err; |
| 3181 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3182 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3183 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3184 | switch (err) { |
| 3185 | case 0: |
| 3186 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3187 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3188 | default: |
| 3189 | err = nfs4_handle_exception(server, err, &exception); |
| 3190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3192 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | return err; |
| 3194 | } |
| 3195 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3196 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3197 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3198 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3199 | struct rpc_auth_create_args auth_args = { |
| 3200 | .pseudoflavor = flavor, |
| 3201 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3202 | struct rpc_auth *auth; |
| 3203 | int ret; |
| 3204 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3205 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3206 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3207 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3208 | goto out; |
| 3209 | } |
| 3210 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3211 | out: |
| 3212 | return ret; |
| 3213 | } |
| 3214 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3215 | /* |
| 3216 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3217 | * |
| 3218 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3219 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3220 | * |
| 3221 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3222 | * negative errno value. |
| 3223 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3224 | 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] | 3225 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3227 | /* Per 3530bis 15.33.5 */ |
| 3228 | static const rpc_authflavor_t flav_array[] = { |
| 3229 | RPC_AUTH_GSS_KRB5P, |
| 3230 | RPC_AUTH_GSS_KRB5I, |
| 3231 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3232 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3233 | RPC_AUTH_NULL, |
| 3234 | }; |
| 3235 | int status = -EPERM; |
| 3236 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3238 | if (server->auth_info.flavor_len > 0) { |
| 3239 | /* try each flavor specified by user */ |
| 3240 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3241 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3242 | server->auth_info.flavors[i]); |
| 3243 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3244 | continue; |
| 3245 | break; |
| 3246 | } |
| 3247 | } else { |
| 3248 | /* no flavors specified by user, try default list */ |
| 3249 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3250 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3251 | flav_array[i]); |
| 3252 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3253 | continue; |
| 3254 | break; |
| 3255 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3256 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3257 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3258 | /* |
| 3259 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3260 | * to access the mount. It could also mean that we tried to mount |
| 3261 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3262 | * existing mount programs don't handle -EACCES very well so it should |
| 3263 | * be mapped to -EPERM instead. |
| 3264 | */ |
| 3265 | if (status == -EACCES) |
| 3266 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3267 | return status; |
| 3268 | } |
| 3269 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3270 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3271 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3272 | { |
| 3273 | int mv = server->nfs_client->cl_minorversion; |
| 3274 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3275 | } |
| 3276 | |
| 3277 | /** |
| 3278 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3279 | * @server: initialized nfs_server handle |
| 3280 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3281 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3282 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3283 | * |
| 3284 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3285 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3286 | 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] | 3287 | struct nfs_fsinfo *info, |
| 3288 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3289 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3290 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3291 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3292 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3293 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3294 | |
| 3295 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3296 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 3297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | if (status == 0) |
| 3299 | status = nfs4_server_capabilities(server, fhandle); |
| 3300 | if (status == 0) |
| 3301 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3302 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3303 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3306 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3307 | struct nfs_fsinfo *info) |
| 3308 | { |
| 3309 | int error; |
| 3310 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3311 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3312 | |
| 3313 | error = nfs4_server_capabilities(server, mntfh); |
| 3314 | if (error < 0) { |
| 3315 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3316 | return error; |
| 3317 | } |
| 3318 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3319 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3320 | if (IS_ERR(label)) |
| 3321 | return PTR_ERR(label); |
| 3322 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3323 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3324 | if (error < 0) { |
| 3325 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3326 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3330 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3331 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3332 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3333 | err_free_label: |
| 3334 | nfs4_label_free(label); |
| 3335 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3336 | return error; |
| 3337 | } |
| 3338 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3339 | /* |
| 3340 | * Get locations and (maybe) other attributes of a referral. |
| 3341 | * Note that we'll actually follow the referral later when |
| 3342 | * we detect fsid mismatch in inode revalidation |
| 3343 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3344 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3345 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3346 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3347 | { |
| 3348 | int status = -ENOMEM; |
| 3349 | struct page *page = NULL; |
| 3350 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3351 | |
| 3352 | page = alloc_page(GFP_KERNEL); |
| 3353 | if (page == NULL) |
| 3354 | goto out; |
| 3355 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3356 | if (locations == NULL) |
| 3357 | goto out; |
| 3358 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3359 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3360 | if (status != 0) |
| 3361 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3362 | |
| 3363 | /* |
| 3364 | * If the fsid didn't change, this is a migration event, not a |
| 3365 | * referral. Cause us to drop into the exception handler, which |
| 3366 | * will kick off migration recovery. |
| 3367 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3368 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3369 | dprintk("%s: server did not return a different fsid for" |
| 3370 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3371 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3372 | goto out; |
| 3373 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3374 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3375 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3376 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3377 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3378 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3379 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3380 | out: |
| 3381 | if (page) |
| 3382 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3383 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3384 | return status; |
| 3385 | } |
| 3386 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3387 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3388 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | { |
| 3390 | struct nfs4_getattr_arg args = { |
| 3391 | .fh = fhandle, |
| 3392 | .bitmask = server->attr_bitmask, |
| 3393 | }; |
| 3394 | struct nfs4_getattr_res res = { |
| 3395 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3396 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | .server = server, |
| 3398 | }; |
| 3399 | struct rpc_message msg = { |
| 3400 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3401 | .rpc_argp = &args, |
| 3402 | .rpc_resp = &res, |
| 3403 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3404 | |
| 3405 | args.bitmask = nfs4_bitmask(server, label); |
| 3406 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3407 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3408 | 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] | 3409 | } |
| 3410 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3411 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3412 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | { |
| 3414 | struct nfs4_exception exception = { }; |
| 3415 | int err; |
| 3416 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3417 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3418 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3419 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | &exception); |
| 3421 | } while (exception.retry); |
| 3422 | return err; |
| 3423 | } |
| 3424 | |
| 3425 | /* |
| 3426 | * The file is not closed if it is opened due to the a request to change |
| 3427 | * the size of the file. The open call will not be needed once the |
| 3428 | * VFS layer lookup-intents are implemented. |
| 3429 | * |
| 3430 | * Close is called when the inode is destroyed. |
| 3431 | * If we haven't opened the file for O_WRONLY, we |
| 3432 | * need to in the size_change case to obtain a stateid. |
| 3433 | * |
| 3434 | * Got race? |
| 3435 | * Because OPEN is always done by name in nfsv4, it is |
| 3436 | * possible that we opened a different file by the same |
| 3437 | * name. We can recognize this race condition, but we |
| 3438 | * can't do anything about it besides returning an error. |
| 3439 | * |
| 3440 | * This will be fixed with VFS changes (lookup-intent). |
| 3441 | */ |
| 3442 | static int |
| 3443 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3444 | struct iattr *sattr) |
| 3445 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3446 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3447 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3448 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3449 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | int status; |
| 3451 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3452 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3453 | sattr->ia_valid & ATTR_SIZE && |
| 3454 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3455 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3456 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3457 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3459 | /* Deal with open(O_TRUNC) */ |
| 3460 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3461 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3462 | |
| 3463 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3464 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3465 | return 0; |
| 3466 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3467 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3468 | if (sattr->ia_valid & ATTR_FILE) { |
| 3469 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3470 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3471 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3472 | if (ctx) { |
| 3473 | cred = ctx->cred; |
| 3474 | state = ctx->state; |
| 3475 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3476 | } |
| 3477 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3478 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3479 | if (IS_ERR(label)) |
| 3480 | return PTR_ERR(label); |
| 3481 | |
| 3482 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3483 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3484 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3485 | nfs_setsecurity(inode, fattr, label); |
| 3486 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3487 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | return status; |
| 3489 | } |
| 3490 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3491 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3492 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3493 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3494 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3495 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3496 | int status; |
| 3497 | struct nfs4_lookup_arg args = { |
| 3498 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3499 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3500 | .name = name, |
| 3501 | }; |
| 3502 | struct nfs4_lookup_res res = { |
| 3503 | .server = server, |
| 3504 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3505 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3506 | .fh = fhandle, |
| 3507 | }; |
| 3508 | struct rpc_message msg = { |
| 3509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3510 | .rpc_argp = &args, |
| 3511 | .rpc_resp = &res, |
| 3512 | }; |
| 3513 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3514 | args.bitmask = nfs4_bitmask(server, label); |
| 3515 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3516 | nfs_fattr_init(fattr); |
| 3517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3519 | 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] | 3520 | dprintk("NFS reply lookup: %d\n", status); |
| 3521 | return status; |
| 3522 | } |
| 3523 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3524 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3525 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3526 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3527 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3528 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3529 | fattr->nlink = 2; |
| 3530 | } |
| 3531 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3532 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3533 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3534 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3535 | { |
| 3536 | struct nfs4_exception exception = { }; |
| 3537 | struct rpc_clnt *client = *clnt; |
| 3538 | int err; |
| 3539 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3540 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3541 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3542 | switch (err) { |
| 3543 | case -NFS4ERR_BADNAME: |
| 3544 | err = -ENOENT; |
| 3545 | goto out; |
| 3546 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3547 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3548 | if (err == -NFS4ERR_MOVED) |
| 3549 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3550 | goto out; |
| 3551 | case -NFS4ERR_WRONGSEC: |
| 3552 | err = -EPERM; |
| 3553 | if (client != *clnt) |
| 3554 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3555 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3556 | if (IS_ERR(client)) |
| 3557 | return PTR_ERR(client); |
| 3558 | |
| 3559 | exception.retry = 1; |
| 3560 | break; |
| 3561 | default: |
| 3562 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3563 | } |
| 3564 | } while (exception.retry); |
| 3565 | |
| 3566 | out: |
| 3567 | if (err == 0) |
| 3568 | *clnt = client; |
| 3569 | else if (client != *clnt) |
| 3570 | rpc_shutdown_client(client); |
| 3571 | |
| 3572 | return err; |
| 3573 | } |
| 3574 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3575 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3576 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3577 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3579 | int status; |
| 3580 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3581 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3582 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3583 | if (client != NFS_CLIENT(dir)) { |
| 3584 | rpc_shutdown_client(client); |
| 3585 | nfs_fixup_secinfo_attributes(fattr); |
| 3586 | } |
| 3587 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3590 | struct rpc_clnt * |
| 3591 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3592 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3593 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3594 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3595 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3596 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3597 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3598 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3599 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3600 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3601 | } |
| 3602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3604 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3605 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | struct nfs4_accessargs args = { |
| 3607 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3608 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3610 | struct nfs4_accessres res = { |
| 3611 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3612 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | struct rpc_message msg = { |
| 3614 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3615 | .rpc_argp = &args, |
| 3616 | .rpc_resp = &res, |
| 3617 | .rpc_cred = entry->cred, |
| 3618 | }; |
| 3619 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3620 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | |
| 3622 | /* |
| 3623 | * Determine which access bits we want to ask for... |
| 3624 | */ |
| 3625 | if (mode & MAY_READ) |
| 3626 | args.access |= NFS4_ACCESS_READ; |
| 3627 | if (S_ISDIR(inode->i_mode)) { |
| 3628 | if (mode & MAY_WRITE) |
| 3629 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3630 | if (mode & MAY_EXEC) |
| 3631 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3632 | } else { |
| 3633 | if (mode & MAY_WRITE) |
| 3634 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3635 | if (mode & MAY_EXEC) |
| 3636 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3637 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3638 | |
| 3639 | res.fattr = nfs_alloc_fattr(); |
| 3640 | if (res.fattr == NULL) |
| 3641 | return -ENOMEM; |
| 3642 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3643 | 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] | 3644 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3645 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3646 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3648 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | return status; |
| 3650 | } |
| 3651 | |
| 3652 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3653 | { |
| 3654 | struct nfs4_exception exception = { }; |
| 3655 | int err; |
| 3656 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3657 | err = _nfs4_proc_access(inode, entry); |
| 3658 | trace_nfs4_access(inode, err); |
| 3659 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | &exception); |
| 3661 | } while (exception.retry); |
| 3662 | return err; |
| 3663 | } |
| 3664 | |
| 3665 | /* |
| 3666 | * TODO: For the time being, we don't try to get any attributes |
| 3667 | * along with any of the zero-copy operations READ, READDIR, |
| 3668 | * READLINK, WRITE. |
| 3669 | * |
| 3670 | * In the case of the first three, we want to put the GETATTR |
| 3671 | * after the read-type operation -- this is because it is hard |
| 3672 | * to predict the length of a GETATTR response in v4, and thus |
| 3673 | * align the READ data correctly. This means that the GETATTR |
| 3674 | * may end up partially falling into the page cache, and we should |
| 3675 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3676 | * To do this efficiently, we need to know the total length |
| 3677 | * of data received, which doesn't seem to be available outside |
| 3678 | * of the RPC layer. |
| 3679 | * |
| 3680 | * In the case of WRITE, we also want to put the GETATTR after |
| 3681 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3682 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | * |
| 3684 | * Both of these changes to the XDR layer would in fact be quite |
| 3685 | * minor, but I decided to leave them for a subsequent patch. |
| 3686 | */ |
| 3687 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3688 | unsigned int pgbase, unsigned int pglen) |
| 3689 | { |
| 3690 | struct nfs4_readlink args = { |
| 3691 | .fh = NFS_FH(inode), |
| 3692 | .pgbase = pgbase, |
| 3693 | .pglen = pglen, |
| 3694 | .pages = &page, |
| 3695 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3696 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | struct rpc_message msg = { |
| 3698 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3699 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3700 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | }; |
| 3702 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3703 | 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] | 3704 | } |
| 3705 | |
| 3706 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3707 | unsigned int pgbase, unsigned int pglen) |
| 3708 | { |
| 3709 | struct nfs4_exception exception = { }; |
| 3710 | int err; |
| 3711 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3712 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3713 | trace_nfs4_readlink(inode, err); |
| 3714 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | &exception); |
| 3716 | } while (exception.retry); |
| 3717 | return err; |
| 3718 | } |
| 3719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3721 | * 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] | 3722 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | static int |
| 3724 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3725 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3727 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3728 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | int status = 0; |
| 3731 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3732 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3733 | if (IS_ERR(ctx)) |
| 3734 | return PTR_ERR(ctx); |
| 3735 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3736 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3737 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3738 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3739 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | if (IS_ERR(state)) { |
| 3741 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3742 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3745 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3746 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | return status; |
| 3748 | } |
| 3749 | |
| 3750 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3751 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3752 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3753 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3755 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3757 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3758 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3759 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3761 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3762 | .rpc_argp = &args, |
| 3763 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3765 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3766 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3767 | 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] | 3768 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3769 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | return status; |
| 3771 | } |
| 3772 | |
| 3773 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3774 | { |
| 3775 | struct nfs4_exception exception = { }; |
| 3776 | int err; |
| 3777 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3778 | err = _nfs4_proc_remove(dir, name); |
| 3779 | trace_nfs4_remove(dir, name, err); |
| 3780 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | &exception); |
| 3782 | } while (exception.retry); |
| 3783 | return err; |
| 3784 | } |
| 3785 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3786 | 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] | 3787 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3788 | struct nfs_server *server = NFS_SERVER(dir); |
| 3789 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3790 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3792 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3794 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3795 | |
| 3796 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3799 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3800 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3801 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3802 | &data->args.seq_args, |
| 3803 | &data->res.seq_res, |
| 3804 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | } |
| 3806 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3807 | 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] | 3808 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3809 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3810 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3811 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3812 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3813 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3814 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3815 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3816 | return 0; |
| 3817 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3818 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3821 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3822 | { |
| 3823 | struct nfs_server *server = NFS_SERVER(dir); |
| 3824 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3825 | struct nfs_renameres *res = msg->rpc_resp; |
| 3826 | |
| 3827 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3828 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3829 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3830 | } |
| 3831 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3832 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3833 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3834 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3835 | &data->args.seq_args, |
| 3836 | &data->res.seq_res, |
| 3837 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3841 | struct inode *new_dir) |
| 3842 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3843 | struct nfs_renamedata *data = task->tk_calldata; |
| 3844 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3845 | |
| 3846 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3847 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3848 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3849 | return 0; |
| 3850 | |
| 3851 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3852 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3853 | return 1; |
| 3854 | } |
| 3855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3857 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3858 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | struct nfs4_link_arg arg = { |
| 3860 | .fh = NFS_FH(inode), |
| 3861 | .dir_fh = NFS_FH(dir), |
| 3862 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3863 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3865 | struct nfs4_link_res res = { |
| 3866 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3867 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3868 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | struct rpc_message msg = { |
| 3870 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3871 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3872 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3874 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3876 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3877 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3878 | goto out; |
| 3879 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3880 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3881 | if (IS_ERR(res.label)) { |
| 3882 | status = PTR_ERR(res.label); |
| 3883 | goto out; |
| 3884 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3885 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3886 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3887 | 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] | 3888 | if (!status) { |
| 3889 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3890 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3891 | if (!status) |
| 3892 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3893 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3894 | |
| 3895 | |
| 3896 | nfs4_label_free(res.label); |
| 3897 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3898 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3899 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | return status; |
| 3901 | } |
| 3902 | |
| 3903 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3904 | { |
| 3905 | struct nfs4_exception exception = { }; |
| 3906 | int err; |
| 3907 | do { |
| 3908 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3909 | _nfs4_proc_link(inode, dir, name), |
| 3910 | &exception); |
| 3911 | } while (exception.retry); |
| 3912 | return err; |
| 3913 | } |
| 3914 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3915 | struct nfs4_createdata { |
| 3916 | struct rpc_message msg; |
| 3917 | struct nfs4_create_arg arg; |
| 3918 | struct nfs4_create_res res; |
| 3919 | struct nfs_fh fh; |
| 3920 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3921 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3922 | }; |
| 3923 | |
| 3924 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3925 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3926 | { |
| 3927 | struct nfs4_createdata *data; |
| 3928 | |
| 3929 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3930 | if (data != NULL) { |
| 3931 | struct nfs_server *server = NFS_SERVER(dir); |
| 3932 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3933 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3934 | if (IS_ERR(data->label)) |
| 3935 | goto out_free; |
| 3936 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3937 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3938 | data->msg.rpc_argp = &data->arg; |
| 3939 | data->msg.rpc_resp = &data->res; |
| 3940 | data->arg.dir_fh = NFS_FH(dir); |
| 3941 | data->arg.server = server; |
| 3942 | data->arg.name = name; |
| 3943 | data->arg.attrs = sattr; |
| 3944 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3945 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3946 | data->res.server = server; |
| 3947 | data->res.fh = &data->fh; |
| 3948 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3949 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3950 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3951 | } |
| 3952 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3953 | out_free: |
| 3954 | kfree(data); |
| 3955 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3959 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3960 | 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] | 3961 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3962 | if (status == 0) { |
| 3963 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3964 | 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] | 3965 | } |
| 3966 | return status; |
| 3967 | } |
| 3968 | |
| 3969 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3970 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3971 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3972 | kfree(data); |
| 3973 | } |
| 3974 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3975 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3976 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3977 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3979 | struct nfs4_createdata *data; |
| 3980 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3982 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3983 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3984 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3985 | status = -ENOMEM; |
| 3986 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3987 | if (data == NULL) |
| 3988 | goto out; |
| 3989 | |
| 3990 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3991 | data->arg.u.symlink.pages = &page; |
| 3992 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3993 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3995 | status = nfs4_do_create(dir, dentry, data); |
| 3996 | |
| 3997 | nfs4_free_createdata(data); |
| 3998 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | return status; |
| 4000 | } |
| 4001 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4002 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4003 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | { |
| 4005 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4006 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4008 | |
| 4009 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4012 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4013 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4014 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | &exception); |
| 4016 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4017 | |
| 4018 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | return err; |
| 4020 | } |
| 4021 | |
| 4022 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4023 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4025 | struct nfs4_createdata *data; |
| 4026 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4028 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4029 | if (data == NULL) |
| 4030 | goto out; |
| 4031 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4032 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4033 | status = nfs4_do_create(dir, dentry, data); |
| 4034 | |
| 4035 | nfs4_free_createdata(data); |
| 4036 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | return status; |
| 4038 | } |
| 4039 | |
| 4040 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4041 | struct iattr *sattr) |
| 4042 | { |
| 4043 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4044 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4046 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4047 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4048 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4049 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4051 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4052 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4053 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | &exception); |
| 4055 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4056 | nfs4_label_release_security(label); |
| 4057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | return err; |
| 4059 | } |
| 4060 | |
| 4061 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4062 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4064 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | struct nfs4_readdir_arg args = { |
| 4066 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4067 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | .pgbase = 0, |
| 4069 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4070 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4071 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | }; |
| 4073 | struct nfs4_readdir_res res; |
| 4074 | struct rpc_message msg = { |
| 4075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4076 | .rpc_argp = &args, |
| 4077 | .rpc_resp = &res, |
| 4078 | .rpc_cred = cred, |
| 4079 | }; |
| 4080 | int status; |
| 4081 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4082 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4083 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4084 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4085 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4087 | 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] | 4088 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4089 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4090 | status += args.pgbase; |
| 4091 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4092 | |
| 4093 | nfs_invalidate_atime(dir); |
| 4094 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4095 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | return status; |
| 4097 | } |
| 4098 | |
| 4099 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4100 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | { |
| 4102 | struct nfs4_exception exception = { }; |
| 4103 | int err; |
| 4104 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4105 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4106 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4107 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4108 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | &exception); |
| 4110 | } while (exception.retry); |
| 4111 | return err; |
| 4112 | } |
| 4113 | |
| 4114 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4115 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4117 | struct nfs4_createdata *data; |
| 4118 | int mode = sattr->ia_mode; |
| 4119 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4121 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4122 | if (data == NULL) |
| 4123 | goto out; |
| 4124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4126 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4128 | data->arg.ftype = NF4BLK; |
| 4129 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4130 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | } |
| 4132 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4133 | data->arg.ftype = NF4CHR; |
| 4134 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4135 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4136 | } else if (!S_ISSOCK(mode)) { |
| 4137 | status = -EINVAL; |
| 4138 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4140 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4141 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4142 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4143 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4144 | nfs4_free_createdata(data); |
| 4145 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | return status; |
| 4147 | } |
| 4148 | |
| 4149 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4150 | struct iattr *sattr, dev_t rdev) |
| 4151 | { |
| 4152 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4153 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4155 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4156 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4157 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4158 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4160 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4161 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4162 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | &exception); |
| 4164 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4165 | |
| 4166 | nfs4_label_release_security(label); |
| 4167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | return err; |
| 4169 | } |
| 4170 | |
| 4171 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4172 | struct nfs_fsstat *fsstat) |
| 4173 | { |
| 4174 | struct nfs4_statfs_arg args = { |
| 4175 | .fh = fhandle, |
| 4176 | .bitmask = server->attr_bitmask, |
| 4177 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4178 | struct nfs4_statfs_res res = { |
| 4179 | .fsstat = fsstat, |
| 4180 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | struct rpc_message msg = { |
| 4182 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4183 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4184 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | }; |
| 4186 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4187 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4188 | 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] | 4189 | } |
| 4190 | |
| 4191 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4192 | { |
| 4193 | struct nfs4_exception exception = { }; |
| 4194 | int err; |
| 4195 | do { |
| 4196 | err = nfs4_handle_exception(server, |
| 4197 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4198 | &exception); |
| 4199 | } while (exception.retry); |
| 4200 | return err; |
| 4201 | } |
| 4202 | |
| 4203 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4204 | struct nfs_fsinfo *fsinfo) |
| 4205 | { |
| 4206 | struct nfs4_fsinfo_arg args = { |
| 4207 | .fh = fhandle, |
| 4208 | .bitmask = server->attr_bitmask, |
| 4209 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4210 | struct nfs4_fsinfo_res res = { |
| 4211 | .fsinfo = fsinfo, |
| 4212 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | struct rpc_message msg = { |
| 4214 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4215 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4216 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | }; |
| 4218 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4219 | 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] | 4220 | } |
| 4221 | |
| 4222 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4223 | { |
| 4224 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4225 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | int err; |
| 4227 | |
| 4228 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4229 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4230 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4231 | if (err == 0) { |
| 4232 | struct nfs_client *clp = server->nfs_client; |
| 4233 | |
| 4234 | spin_lock(&clp->cl_lock); |
| 4235 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4236 | clp->cl_last_renewal = now; |
| 4237 | spin_unlock(&clp->cl_lock); |
| 4238 | break; |
| 4239 | } |
| 4240 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | } while (exception.retry); |
| 4242 | return err; |
| 4243 | } |
| 4244 | |
| 4245 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4246 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4247 | int error; |
| 4248 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4249 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4250 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4251 | if (error == 0) { |
| 4252 | /* block layout checks this! */ |
| 4253 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4254 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4255 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4256 | |
| 4257 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4261 | struct nfs_pathconf *pathconf) |
| 4262 | { |
| 4263 | struct nfs4_pathconf_arg args = { |
| 4264 | .fh = fhandle, |
| 4265 | .bitmask = server->attr_bitmask, |
| 4266 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4267 | struct nfs4_pathconf_res res = { |
| 4268 | .pathconf = pathconf, |
| 4269 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | struct rpc_message msg = { |
| 4271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4272 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4273 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | }; |
| 4275 | |
| 4276 | /* None of the pathconf attributes are mandatory to implement */ |
| 4277 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4278 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4279 | return 0; |
| 4280 | } |
| 4281 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4282 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4283 | 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] | 4284 | } |
| 4285 | |
| 4286 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4287 | struct nfs_pathconf *pathconf) |
| 4288 | { |
| 4289 | struct nfs4_exception exception = { }; |
| 4290 | int err; |
| 4291 | |
| 4292 | do { |
| 4293 | err = nfs4_handle_exception(server, |
| 4294 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4295 | &exception); |
| 4296 | } while (exception.retry); |
| 4297 | return err; |
| 4298 | } |
| 4299 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4300 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4301 | const struct nfs_open_context *ctx, |
| 4302 | const struct nfs_lock_context *l_ctx, |
| 4303 | fmode_t fmode) |
| 4304 | { |
| 4305 | const struct nfs_lockowner *lockowner = NULL; |
| 4306 | |
| 4307 | if (l_ctx != NULL) |
| 4308 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4309 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4310 | } |
| 4311 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4312 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4313 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4314 | const struct nfs_open_context *ctx, |
| 4315 | const struct nfs_lock_context *l_ctx, |
| 4316 | fmode_t fmode) |
| 4317 | { |
| 4318 | nfs4_stateid current_stateid; |
| 4319 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4320 | /* If the current stateid represents a lost lock, then exit */ |
| 4321 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4322 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4323 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4324 | } |
| 4325 | |
| 4326 | static bool nfs4_error_stateid_expired(int err) |
| 4327 | { |
| 4328 | switch (err) { |
| 4329 | case -NFS4ERR_DELEG_REVOKED: |
| 4330 | case -NFS4ERR_ADMIN_REVOKED: |
| 4331 | case -NFS4ERR_BAD_STATEID: |
| 4332 | case -NFS4ERR_STALE_STATEID: |
| 4333 | case -NFS4ERR_OLD_STATEID: |
| 4334 | case -NFS4ERR_OPENMODE: |
| 4335 | case -NFS4ERR_EXPIRED: |
| 4336 | return true; |
| 4337 | } |
| 4338 | return false; |
| 4339 | } |
| 4340 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4341 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4342 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4343 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4344 | } |
| 4345 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4346 | 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] | 4347 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4348 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4350 | trace_nfs4_read(hdr, task->tk_status); |
| 4351 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4352 | hdr->args.context->state, |
| 4353 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4354 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4355 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4357 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4358 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4360 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4361 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4364 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4365 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4366 | { |
| 4367 | |
| 4368 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4369 | nfs4_stateid_is_current(&args->stateid, |
| 4370 | args->context, |
| 4371 | args->lock_context, |
| 4372 | FMODE_READ)) |
| 4373 | return false; |
| 4374 | rpc_restart_call_prepare(task); |
| 4375 | return true; |
| 4376 | } |
| 4377 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4378 | 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] | 4379 | { |
| 4380 | |
| 4381 | dprintk("--> %s\n", __func__); |
| 4382 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4383 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4384 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4385 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4386 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4387 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4388 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4391 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4392 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4394 | hdr->timestamp = jiffies; |
| 4395 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4396 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4397 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | } |
| 4399 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4400 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4401 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4402 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4403 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4404 | &hdr->args.seq_args, |
| 4405 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4406 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4407 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4408 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4409 | hdr->args.lock_context, |
| 4410 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4411 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4412 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4413 | return -EIO; |
| 4414 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4417 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4418 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4420 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4421 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4422 | trace_nfs4_write(hdr, task->tk_status); |
| 4423 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4424 | hdr->args.context->state, |
| 4425 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4426 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4427 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4429 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4430 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4431 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4432 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4433 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | } |
| 4435 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4436 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4437 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4438 | { |
| 4439 | |
| 4440 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4441 | nfs4_stateid_is_current(&args->stateid, |
| 4442 | args->context, |
| 4443 | args->lock_context, |
| 4444 | FMODE_WRITE)) |
| 4445 | return false; |
| 4446 | rpc_restart_call_prepare(task); |
| 4447 | return true; |
| 4448 | } |
| 4449 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4450 | 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] | 4451 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4452 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4453 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4454 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4455 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4456 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4457 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4460 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4461 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4462 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4463 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4464 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4465 | return false; |
| 4466 | /* Otherwise, request attributes if and only if we don't hold |
| 4467 | * a delegation |
| 4468 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4469 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4470 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4471 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4472 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4473 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4475 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4476 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4477 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4478 | hdr->args.bitmask = NULL; |
| 4479 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4480 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4481 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4482 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4483 | if (!hdr->pgio_done_cb) |
| 4484 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4485 | hdr->res.server = server; |
| 4486 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4488 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4489 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4492 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4493 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4494 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4495 | &data->args.seq_args, |
| 4496 | &data->res.seq_res, |
| 4497 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4500 | 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] | 4501 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4503 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4504 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4505 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4506 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4507 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4508 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4510 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4513 | 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] | 4514 | { |
| 4515 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4516 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4517 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4518 | } |
| 4519 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4520 | 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] | 4521 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4522 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4523 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4524 | if (data->commit_done_cb == NULL) |
| 4525 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4526 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4527 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4528 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | } |
| 4530 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4531 | struct nfs4_renewdata { |
| 4532 | struct nfs_client *client; |
| 4533 | unsigned long timestamp; |
| 4534 | }; |
| 4535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | /* |
| 4537 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4538 | * standalone procedure for queueing an asynchronous RENEW. |
| 4539 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4540 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4541 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4542 | struct nfs4_renewdata *data = calldata; |
| 4543 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4544 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4545 | if (atomic_read(&clp->cl_count) > 1) |
| 4546 | nfs4_schedule_state_renewal(clp); |
| 4547 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4548 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4549 | } |
| 4550 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4551 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4553 | struct nfs4_renewdata *data = calldata; |
| 4554 | struct nfs_client *clp = data->client; |
| 4555 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4557 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4558 | switch (task->tk_status) { |
| 4559 | case 0: |
| 4560 | break; |
| 4561 | case -NFS4ERR_LEASE_MOVED: |
| 4562 | nfs4_schedule_lease_moved_recovery(clp); |
| 4563 | break; |
| 4564 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4565 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4566 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4567 | return; |
| 4568 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4569 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4570 | return; |
| 4571 | } |
| 4572 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4574 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | } |
| 4576 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4577 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4578 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4579 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4580 | }; |
| 4581 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4582 | 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] | 4583 | { |
| 4584 | struct rpc_message msg = { |
| 4585 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4586 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4587 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4589 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4591 | if (renew_flags == 0) |
| 4592 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4593 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4594 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4595 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4596 | if (data == NULL) |
| 4597 | return -ENOMEM; |
| 4598 | data->client = clp; |
| 4599 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4600 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4601 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | } |
| 4603 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4604 | 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] | 4605 | { |
| 4606 | struct rpc_message msg = { |
| 4607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4608 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4609 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | }; |
| 4611 | unsigned long now = jiffies; |
| 4612 | int status; |
| 4613 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4614 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | if (status < 0) |
| 4616 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4617 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | return 0; |
| 4619 | } |
| 4620 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4621 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4622 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4623 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4626 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4627 | * 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] | 4628 | * the stack. |
| 4629 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4630 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4631 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4632 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4633 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4634 | { |
| 4635 | struct page *newpage, **spages; |
| 4636 | int rc = 0; |
| 4637 | size_t len; |
| 4638 | spages = pages; |
| 4639 | |
| 4640 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4641 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4642 | newpage = alloc_page(GFP_KERNEL); |
| 4643 | |
| 4644 | if (newpage == NULL) |
| 4645 | goto unwind; |
| 4646 | memcpy(page_address(newpage), buf, len); |
| 4647 | buf += len; |
| 4648 | buflen -= len; |
| 4649 | *pages++ = newpage; |
| 4650 | rc++; |
| 4651 | } while (buflen != 0); |
| 4652 | |
| 4653 | return rc; |
| 4654 | |
| 4655 | unwind: |
| 4656 | for(; rc > 0; rc--) |
| 4657 | __free_page(spages[rc-1]); |
| 4658 | return -ENOMEM; |
| 4659 | } |
| 4660 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4661 | struct nfs4_cached_acl { |
| 4662 | int cached; |
| 4663 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4664 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4665 | }; |
| 4666 | |
| 4667 | 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] | 4668 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4669 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4670 | |
| 4671 | spin_lock(&inode->i_lock); |
| 4672 | kfree(nfsi->nfs4_acl); |
| 4673 | nfsi->nfs4_acl = acl; |
| 4674 | spin_unlock(&inode->i_lock); |
| 4675 | } |
| 4676 | |
| 4677 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4678 | { |
| 4679 | nfs4_set_cached_acl(inode, NULL); |
| 4680 | } |
| 4681 | |
| 4682 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4683 | { |
| 4684 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4685 | struct nfs4_cached_acl *acl; |
| 4686 | int ret = -ENOENT; |
| 4687 | |
| 4688 | spin_lock(&inode->i_lock); |
| 4689 | acl = nfsi->nfs4_acl; |
| 4690 | if (acl == NULL) |
| 4691 | goto out; |
| 4692 | if (buf == NULL) /* user is just asking for length */ |
| 4693 | goto out_len; |
| 4694 | if (acl->cached == 0) |
| 4695 | goto out; |
| 4696 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4697 | if (acl->len > buflen) |
| 4698 | goto out; |
| 4699 | memcpy(buf, acl->data, acl->len); |
| 4700 | out_len: |
| 4701 | ret = acl->len; |
| 4702 | out: |
| 4703 | spin_unlock(&inode->i_lock); |
| 4704 | return ret; |
| 4705 | } |
| 4706 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4707 | 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] | 4708 | { |
| 4709 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4710 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4711 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4712 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4713 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4714 | if (acl == NULL) |
| 4715 | goto out; |
| 4716 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4717 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4718 | } else { |
| 4719 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4720 | if (acl == NULL) |
| 4721 | goto out; |
| 4722 | acl->cached = 0; |
| 4723 | } |
| 4724 | acl->len = acl_len; |
| 4725 | out: |
| 4726 | nfs4_set_cached_acl(inode, acl); |
| 4727 | } |
| 4728 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4729 | /* |
| 4730 | * The getxattr API returns the required buffer length when called with a |
| 4731 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4732 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4733 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4734 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4735 | * the cache. If not so, we throw away the page, and cache the required |
| 4736 | * length. The next getxattr call will then produce another round trip to |
| 4737 | * the server, this time with the input buf of the required size. |
| 4738 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4739 | 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] | 4740 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4741 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4742 | struct nfs_getaclargs args = { |
| 4743 | .fh = NFS_FH(inode), |
| 4744 | .acl_pages = pages, |
| 4745 | .acl_len = buflen, |
| 4746 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4747 | struct nfs_getaclres res = { |
| 4748 | .acl_len = buflen, |
| 4749 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4750 | struct rpc_message msg = { |
| 4751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4752 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4753 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4754 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4755 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4756 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4757 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4758 | /* As long as we're doing a round trip to the server anyway, |
| 4759 | * let's be prepared for a page of acl data. */ |
| 4760 | if (npages == 0) |
| 4761 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4762 | if (npages > ARRAY_SIZE(pages)) |
| 4763 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4764 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4765 | for (i = 0; i < npages; i++) { |
| 4766 | pages[i] = alloc_page(GFP_KERNEL); |
| 4767 | if (!pages[i]) |
| 4768 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4769 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4770 | |
| 4771 | /* for decoding across pages */ |
| 4772 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4773 | if (!res.acl_scratch) |
| 4774 | goto out_free; |
| 4775 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4776 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4777 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4778 | 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] | 4779 | __func__, buf, buflen, npages, args.acl_len); |
| 4780 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4781 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4782 | if (ret) |
| 4783 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4784 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4785 | /* Handle the case where the passed-in buffer is too short */ |
| 4786 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4787 | /* Did the user only issue a request for the acl length? */ |
| 4788 | if (buf == NULL) |
| 4789 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4790 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4791 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4792 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4793 | 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] | 4794 | if (buf) { |
| 4795 | if (res.acl_len > buflen) { |
| 4796 | ret = -ERANGE; |
| 4797 | goto out_free; |
| 4798 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4799 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4800 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4801 | out_ok: |
| 4802 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4803 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4804 | for (i = 0; i < npages; i++) |
| 4805 | if (pages[i]) |
| 4806 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4807 | if (res.acl_scratch) |
| 4808 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4809 | return ret; |
| 4810 | } |
| 4811 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4812 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4813 | { |
| 4814 | struct nfs4_exception exception = { }; |
| 4815 | ssize_t ret; |
| 4816 | do { |
| 4817 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4818 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4819 | if (ret >= 0) |
| 4820 | break; |
| 4821 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4822 | } while (exception.retry); |
| 4823 | return ret; |
| 4824 | } |
| 4825 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4826 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4827 | { |
| 4828 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4829 | int ret; |
| 4830 | |
| 4831 | if (!nfs4_server_supports_acls(server)) |
| 4832 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4833 | ret = nfs_revalidate_inode(server, inode); |
| 4834 | if (ret < 0) |
| 4835 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4836 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4837 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4838 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4839 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4840 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4841 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4842 | return ret; |
| 4843 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4846 | 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] | 4847 | { |
| 4848 | struct nfs_server *server = NFS_SERVER(inode); |
| 4849 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4850 | struct nfs_setaclargs arg = { |
| 4851 | .fh = NFS_FH(inode), |
| 4852 | .acl_pages = pages, |
| 4853 | .acl_len = buflen, |
| 4854 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4855 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4856 | struct rpc_message msg = { |
| 4857 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4858 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4859 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4860 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4861 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4862 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4863 | |
| 4864 | if (!nfs4_server_supports_acls(server)) |
| 4865 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4866 | if (npages > ARRAY_SIZE(pages)) |
| 4867 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4868 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4869 | if (i < 0) |
| 4870 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4871 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4872 | 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] | 4873 | |
| 4874 | /* |
| 4875 | * Free each page after tx, so the only ref left is |
| 4876 | * held by the network stack |
| 4877 | */ |
| 4878 | for (; i > 0; i--) |
| 4879 | put_page(pages[i-1]); |
| 4880 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4881 | /* |
| 4882 | * Acl update can result in inode attribute update. |
| 4883 | * so mark the attribute cache invalid. |
| 4884 | */ |
| 4885 | spin_lock(&inode->i_lock); |
| 4886 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4887 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4888 | nfs_access_zap_cache(inode); |
| 4889 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4890 | return ret; |
| 4891 | } |
| 4892 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4893 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4894 | { |
| 4895 | struct nfs4_exception exception = { }; |
| 4896 | int err; |
| 4897 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4898 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4899 | trace_nfs4_set_acl(inode, err); |
| 4900 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4901 | &exception); |
| 4902 | } while (exception.retry); |
| 4903 | return err; |
| 4904 | } |
| 4905 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4906 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4907 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4908 | size_t buflen) |
| 4909 | { |
| 4910 | struct nfs_server *server = NFS_SERVER(inode); |
| 4911 | struct nfs_fattr fattr; |
| 4912 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4913 | |
| 4914 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4915 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4916 | .fh = NFS_FH(inode), |
| 4917 | .bitmask = bitmask, |
| 4918 | }; |
| 4919 | struct nfs4_getattr_res res = { |
| 4920 | .fattr = &fattr, |
| 4921 | .label = &label, |
| 4922 | .server = server, |
| 4923 | }; |
| 4924 | struct rpc_message msg = { |
| 4925 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4926 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4927 | .rpc_resp = &res, |
| 4928 | }; |
| 4929 | int ret; |
| 4930 | |
| 4931 | nfs_fattr_init(&fattr); |
| 4932 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4933 | 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] | 4934 | if (ret) |
| 4935 | return ret; |
| 4936 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4937 | return -ENOENT; |
| 4938 | if (buflen < label.len) |
| 4939 | return -ERANGE; |
| 4940 | return 0; |
| 4941 | } |
| 4942 | |
| 4943 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4944 | size_t buflen) |
| 4945 | { |
| 4946 | struct nfs4_exception exception = { }; |
| 4947 | int err; |
| 4948 | |
| 4949 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4950 | return -EOPNOTSUPP; |
| 4951 | |
| 4952 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4953 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4954 | trace_nfs4_get_security_label(inode, err); |
| 4955 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4956 | &exception); |
| 4957 | } while (exception.retry); |
| 4958 | return err; |
| 4959 | } |
| 4960 | |
| 4961 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4962 | struct nfs4_label *ilabel, |
| 4963 | struct nfs_fattr *fattr, |
| 4964 | struct nfs4_label *olabel) |
| 4965 | { |
| 4966 | |
| 4967 | struct iattr sattr = {0}; |
| 4968 | struct nfs_server *server = NFS_SERVER(inode); |
| 4969 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4970 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4971 | .fh = NFS_FH(inode), |
| 4972 | .iap = &sattr, |
| 4973 | .server = server, |
| 4974 | .bitmask = bitmask, |
| 4975 | .label = ilabel, |
| 4976 | }; |
| 4977 | struct nfs_setattrres res = { |
| 4978 | .fattr = fattr, |
| 4979 | .label = olabel, |
| 4980 | .server = server, |
| 4981 | }; |
| 4982 | struct rpc_message msg = { |
| 4983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4984 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4985 | .rpc_resp = &res, |
| 4986 | }; |
| 4987 | int status; |
| 4988 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4989 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4990 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4991 | 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] | 4992 | if (status) |
| 4993 | dprintk("%s failed: %d\n", __func__, status); |
| 4994 | |
| 4995 | return status; |
| 4996 | } |
| 4997 | |
| 4998 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4999 | struct nfs4_label *ilabel, |
| 5000 | struct nfs_fattr *fattr, |
| 5001 | struct nfs4_label *olabel) |
| 5002 | { |
| 5003 | struct nfs4_exception exception = { }; |
| 5004 | int err; |
| 5005 | |
| 5006 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5007 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5008 | fattr, olabel); |
| 5009 | trace_nfs4_set_security_label(inode, err); |
| 5010 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5011 | &exception); |
| 5012 | } while (exception.retry); |
| 5013 | return err; |
| 5014 | } |
| 5015 | |
| 5016 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5017 | 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] | 5018 | { |
| 5019 | struct nfs4_label ilabel, *olabel = NULL; |
| 5020 | struct nfs_fattr fattr; |
| 5021 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5022 | int status; |
| 5023 | |
| 5024 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5025 | return -EOPNOTSUPP; |
| 5026 | |
| 5027 | nfs_fattr_init(&fattr); |
| 5028 | |
| 5029 | ilabel.pi = 0; |
| 5030 | ilabel.lfs = 0; |
| 5031 | ilabel.label = (char *)buf; |
| 5032 | ilabel.len = buflen; |
| 5033 | |
| 5034 | cred = rpc_lookup_cred(); |
| 5035 | if (IS_ERR(cred)) |
| 5036 | return PTR_ERR(cred); |
| 5037 | |
| 5038 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5039 | if (IS_ERR(olabel)) { |
| 5040 | status = -PTR_ERR(olabel); |
| 5041 | goto out; |
| 5042 | } |
| 5043 | |
| 5044 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5045 | if (status == 0) |
| 5046 | nfs_setsecurity(inode, &fattr, olabel); |
| 5047 | |
| 5048 | nfs4_label_free(olabel); |
| 5049 | out: |
| 5050 | put_rpccred(cred); |
| 5051 | return status; |
| 5052 | } |
| 5053 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5054 | |
| 5055 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5056 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5057 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5058 | { |
| 5059 | __be32 verf[2]; |
| 5060 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5061 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5062 | /* An impossible timestamp guarantees this value |
| 5063 | * will never match a generated boot time. */ |
| 5064 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5065 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5066 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5067 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5068 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5069 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5070 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5071 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5072 | } |
| 5073 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5074 | static int |
| 5075 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5076 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5077 | size_t len; |
| 5078 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5079 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5080 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5081 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5082 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5083 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5084 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5085 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5086 | 1 + |
| 5087 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5088 | 1; |
| 5089 | rcu_read_unlock(); |
| 5090 | |
| 5091 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5092 | return -EINVAL; |
| 5093 | |
| 5094 | /* |
| 5095 | * Since this string is allocated at mount time, and held until the |
| 5096 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5097 | * about a memory-reclaim deadlock. |
| 5098 | */ |
| 5099 | str = kmalloc(len, GFP_KERNEL); |
| 5100 | if (!str) |
| 5101 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5102 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5103 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5104 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5105 | clp->cl_ipaddr, |
| 5106 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5107 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5108 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5109 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5110 | clp->cl_owner_id = str; |
| 5111 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5112 | } |
| 5113 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5114 | static int |
| 5115 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5116 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5117 | size_t len; |
| 5118 | char *str; |
| 5119 | |
| 5120 | len = 10 + 10 + 1 + 10 + 1 + |
| 5121 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5122 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5123 | |
| 5124 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5125 | return -EINVAL; |
| 5126 | |
| 5127 | /* |
| 5128 | * Since this string is allocated at mount time, and held until the |
| 5129 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5130 | * about a memory-reclaim deadlock. |
| 5131 | */ |
| 5132 | str = kmalloc(len, GFP_KERNEL); |
| 5133 | if (!str) |
| 5134 | return -ENOMEM; |
| 5135 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5136 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5137 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5138 | nfs4_client_id_uniquifier, |
| 5139 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5140 | clp->cl_owner_id = str; |
| 5141 | return 0; |
| 5142 | } |
| 5143 | |
| 5144 | static int |
| 5145 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5146 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5147 | size_t len; |
| 5148 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5149 | |
| 5150 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5151 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5152 | |
| 5153 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5154 | return nfs4_init_uniquifier_client_string(clp); |
| 5155 | |
| 5156 | len = 10 + 10 + 1 + 10 + 1 + |
| 5157 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5158 | |
| 5159 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5160 | return -EINVAL; |
| 5161 | |
| 5162 | /* |
| 5163 | * Since this string is allocated at mount time, and held until the |
| 5164 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5165 | * about a memory-reclaim deadlock. |
| 5166 | */ |
| 5167 | str = kmalloc(len, GFP_KERNEL); |
| 5168 | if (!str) |
| 5169 | return -ENOMEM; |
| 5170 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5171 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5172 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5173 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5174 | clp->cl_owner_id = str; |
| 5175 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5176 | } |
| 5177 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5178 | /* |
| 5179 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5180 | * services. Advertise one based on the address family of the |
| 5181 | * clientaddr. |
| 5182 | */ |
| 5183 | static unsigned int |
| 5184 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5185 | { |
| 5186 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5187 | return scnprintf(buf, len, "tcp6"); |
| 5188 | else |
| 5189 | return scnprintf(buf, len, "tcp"); |
| 5190 | } |
| 5191 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5192 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5193 | { |
| 5194 | struct nfs4_setclientid *sc = calldata; |
| 5195 | |
| 5196 | if (task->tk_status == 0) |
| 5197 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5198 | } |
| 5199 | |
| 5200 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5201 | .rpc_call_done = nfs4_setclientid_done, |
| 5202 | }; |
| 5203 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5204 | /** |
| 5205 | * nfs4_proc_setclientid - Negotiate client ID |
| 5206 | * @clp: state data structure |
| 5207 | * @program: RPC program for NFSv4 callback service |
| 5208 | * @port: IP port number for NFS4 callback service |
| 5209 | * @cred: RPC credential to use for this call |
| 5210 | * @res: where to place the result |
| 5211 | * |
| 5212 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5213 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5214 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5215 | unsigned short port, struct rpc_cred *cred, |
| 5216 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | { |
| 5218 | nfs4_verifier sc_verifier; |
| 5219 | struct nfs4_setclientid setclientid = { |
| 5220 | .sc_verifier = &sc_verifier, |
| 5221 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5222 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | }; |
| 5224 | struct rpc_message msg = { |
| 5225 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5226 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5227 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5228 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5230 | struct rpc_task *task; |
| 5231 | struct rpc_task_setup task_setup_data = { |
| 5232 | .rpc_client = clp->cl_rpcclient, |
| 5233 | .rpc_message = &msg, |
| 5234 | .callback_ops = &nfs4_setclientid_ops, |
| 5235 | .callback_data = &setclientid, |
| 5236 | .flags = RPC_TASK_TIMEOUT, |
| 5237 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5238 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5240 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5241 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5242 | |
| 5243 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5244 | status = nfs4_init_uniform_client_string(clp); |
| 5245 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5246 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5247 | |
| 5248 | if (status) |
| 5249 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5250 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5251 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5252 | setclientid.sc_netid_len = |
| 5253 | nfs4_init_callback_netid(clp, |
| 5254 | setclientid.sc_netid, |
| 5255 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5256 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5257 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5259 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5260 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5261 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5262 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5263 | task = rpc_run_task(&task_setup_data); |
| 5264 | if (IS_ERR(task)) { |
| 5265 | status = PTR_ERR(task); |
| 5266 | goto out; |
| 5267 | } |
| 5268 | status = task->tk_status; |
| 5269 | if (setclientid.sc_cred) { |
| 5270 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5271 | put_rpccred(setclientid.sc_cred); |
| 5272 | } |
| 5273 | rpc_put_task(task); |
| 5274 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5275 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5276 | dprintk("NFS reply setclientid: %d\n", status); |
| 5277 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | } |
| 5279 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5280 | /** |
| 5281 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5282 | * @clp: state data structure |
| 5283 | * @res: result of a previous SETCLIENTID |
| 5284 | * @cred: RPC credential to use for this call |
| 5285 | * |
| 5286 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5287 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5288 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5289 | struct nfs4_setclientid_res *arg, |
| 5290 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | struct rpc_message msg = { |
| 5293 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5294 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5295 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5297 | int status; |
| 5298 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5299 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5300 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5301 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5302 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5303 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5304 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | return status; |
| 5306 | } |
| 5307 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5308 | struct nfs4_delegreturndata { |
| 5309 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5310 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5311 | struct nfs_fh fh; |
| 5312 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5313 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5314 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5315 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5316 | struct inode *inode; |
| 5317 | bool roc; |
| 5318 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5319 | }; |
| 5320 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5321 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5322 | { |
| 5323 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5324 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5325 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5326 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5327 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5328 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5329 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5330 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5331 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5332 | case -NFS4ERR_ADMIN_REVOKED: |
| 5333 | case -NFS4ERR_DELEG_REVOKED: |
| 5334 | case -NFS4ERR_BAD_STATEID: |
| 5335 | case -NFS4ERR_OLD_STATEID: |
| 5336 | case -NFS4ERR_STALE_STATEID: |
| 5337 | case -NFS4ERR_EXPIRED: |
| 5338 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5339 | if (data->roc) |
| 5340 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5341 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5342 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5343 | if (nfs4_async_handle_error(task, data->res.server, |
| 5344 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5345 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5346 | return; |
| 5347 | } |
| 5348 | } |
| 5349 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | static void nfs4_delegreturn_release(void *calldata) |
| 5353 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5354 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5355 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5356 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5357 | if (inode) { |
| 5358 | if (data->roc) |
| 5359 | pnfs_roc_release(inode); |
| 5360 | nfs_iput_and_deactive(inode); |
| 5361 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5362 | kfree(calldata); |
| 5363 | } |
| 5364 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5365 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5366 | { |
| 5367 | struct nfs4_delegreturndata *d_data; |
| 5368 | |
| 5369 | d_data = (struct nfs4_delegreturndata *)data; |
| 5370 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5371 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5372 | return; |
| 5373 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5374 | if (d_data->roc) |
| 5375 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5376 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5377 | nfs4_setup_sequence(d_data->res.server, |
| 5378 | &d_data->args.seq_args, |
| 5379 | &d_data->res.seq_res, |
| 5380 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5381 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5382 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5383 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5384 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5385 | .rpc_call_done = nfs4_delegreturn_done, |
| 5386 | .rpc_release = nfs4_delegreturn_release, |
| 5387 | }; |
| 5388 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5389 | 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] | 5390 | { |
| 5391 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5392 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5393 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5394 | struct rpc_message msg = { |
| 5395 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5396 | .rpc_cred = cred, |
| 5397 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5398 | struct rpc_task_setup task_setup_data = { |
| 5399 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5400 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5401 | .callback_ops = &nfs4_delegreturn_ops, |
| 5402 | .flags = RPC_TASK_ASYNC, |
| 5403 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5404 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5405 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5406 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5407 | if (data == NULL) |
| 5408 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5409 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5410 | |
| 5411 | nfs4_state_protect(server->nfs_client, |
| 5412 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5413 | &task_setup_data.rpc_client, &msg); |
| 5414 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5415 | data->args.fhandle = &data->fh; |
| 5416 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5417 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5418 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5419 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5420 | data->res.fattr = &data->fattr; |
| 5421 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5422 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5423 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5424 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5425 | data->inode = nfs_igrab_and_active(inode); |
| 5426 | if (data->inode) |
| 5427 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5428 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5429 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5430 | msg.rpc_argp = &data->args; |
| 5431 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5432 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5433 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5434 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5435 | if (!issync) |
| 5436 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5437 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5438 | if (status != 0) |
| 5439 | goto out; |
| 5440 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5441 | if (status == 0) |
| 5442 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5443 | else |
| 5444 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5445 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5446 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5447 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | } |
| 5449 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5450 | 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] | 5451 | { |
| 5452 | struct nfs_server *server = NFS_SERVER(inode); |
| 5453 | struct nfs4_exception exception = { }; |
| 5454 | int err; |
| 5455 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5456 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5457 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | switch (err) { |
| 5459 | case -NFS4ERR_STALE_STATEID: |
| 5460 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | case 0: |
| 5462 | return 0; |
| 5463 | } |
| 5464 | err = nfs4_handle_exception(server, err, &exception); |
| 5465 | } while (exception.retry); |
| 5466 | return err; |
| 5467 | } |
| 5468 | |
| 5469 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5470 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5471 | |
| 5472 | /* |
| 5473 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5474 | */ |
| 5475 | static unsigned long |
| 5476 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5477 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5478 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | timeout <<= 1; |
| 5480 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5481 | return NFS4_LOCK_MAXTIMEOUT; |
| 5482 | return timeout; |
| 5483 | } |
| 5484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5486 | { |
| 5487 | struct inode *inode = state->inode; |
| 5488 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5489 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5490 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5492 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5494 | struct nfs_lockt_res res = { |
| 5495 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | }; |
| 5497 | struct rpc_message msg = { |
| 5498 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5499 | .rpc_argp = &arg, |
| 5500 | .rpc_resp = &res, |
| 5501 | .rpc_cred = state->owner->so_cred, |
| 5502 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | struct nfs4_lock_state *lsp; |
| 5504 | int status; |
| 5505 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5506 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5507 | status = nfs4_set_lock_state(state, request); |
| 5508 | if (status != 0) |
| 5509 | goto out; |
| 5510 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5511 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5512 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5513 | 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] | 5514 | switch (status) { |
| 5515 | case 0: |
| 5516 | request->fl_type = F_UNLCK; |
| 5517 | break; |
| 5518 | case -NFS4ERR_DENIED: |
| 5519 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5521 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5522 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5523 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | return status; |
| 5525 | } |
| 5526 | |
| 5527 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5528 | { |
| 5529 | struct nfs4_exception exception = { }; |
| 5530 | int err; |
| 5531 | |
| 5532 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5533 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5534 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5535 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | &exception); |
| 5537 | } while (exception.retry); |
| 5538 | return err; |
| 5539 | } |
| 5540 | |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5541 | static int do_vfs_lock(struct inode *inode, struct file_lock *fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | { |
Benjamin Coddington | 4f65636 | 2015-10-22 13:38:14 -0400 | [diff] [blame] | 5543 | return locks_lock_inode_wait(inode, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5546 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5547 | struct nfs_locku_args arg; |
| 5548 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5549 | struct nfs4_lock_state *lsp; |
| 5550 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5551 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5552 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5553 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5554 | }; |
| 5555 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5556 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5557 | struct nfs_open_context *ctx, |
| 5558 | struct nfs4_lock_state *lsp, |
| 5559 | struct nfs_seqid *seqid) |
| 5560 | { |
| 5561 | struct nfs4_unlockdata *p; |
| 5562 | struct inode *inode = lsp->ls_state->inode; |
| 5563 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5564 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5565 | if (p == NULL) |
| 5566 | return NULL; |
| 5567 | p->arg.fh = NFS_FH(inode); |
| 5568 | p->arg.fl = &p->fl; |
| 5569 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5570 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5571 | p->lsp = lsp; |
| 5572 | atomic_inc(&lsp->ls_count); |
| 5573 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5574 | p->ctx = get_nfs_open_context(ctx); |
| 5575 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5576 | p->server = NFS_SERVER(inode); |
| 5577 | return p; |
| 5578 | } |
| 5579 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5580 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5581 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5582 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5583 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5584 | nfs4_put_lock_state(calldata->lsp); |
| 5585 | put_nfs_open_context(calldata->ctx); |
| 5586 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5589 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5590 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5591 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5592 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5593 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5594 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5595 | switch (task->tk_status) { |
| 5596 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5597 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5598 | do_vfs_lock(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5599 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5600 | &calldata->res.stateid)) |
| 5601 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5602 | case -NFS4ERR_BAD_STATEID: |
| 5603 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5604 | case -NFS4ERR_STALE_STATEID: |
| 5605 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5606 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5607 | &calldata->lsp->ls_stateid)) |
| 5608 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5609 | break; |
| 5610 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5611 | if (nfs4_async_handle_error(task, calldata->server, |
| 5612 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5613 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5614 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5615 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5616 | } |
| 5617 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5618 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5619 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5620 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5621 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5622 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5623 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5624 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5625 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5626 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5627 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5628 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5629 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5630 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5631 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5632 | &calldata->res.seq_res, |
| 5633 | task) != 0) |
| 5634 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5635 | return; |
| 5636 | out_no_action: |
| 5637 | task->tk_action = NULL; |
| 5638 | out_wait: |
| 5639 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | } |
| 5641 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5642 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5643 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5644 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5645 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5646 | }; |
| 5647 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5648 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5649 | struct nfs_open_context *ctx, |
| 5650 | struct nfs4_lock_state *lsp, |
| 5651 | struct nfs_seqid *seqid) |
| 5652 | { |
| 5653 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5654 | struct rpc_message msg = { |
| 5655 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5656 | .rpc_cred = ctx->cred, |
| 5657 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5658 | struct rpc_task_setup task_setup_data = { |
| 5659 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5660 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5661 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5662 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5663 | .flags = RPC_TASK_ASYNC, |
| 5664 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5665 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5666 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5667 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5668 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5669 | /* Ensure this is an unlock - when canceling a lock, the |
| 5670 | * canceled lock is passed in, and it won't be an unlock. |
| 5671 | */ |
| 5672 | fl->fl_type = F_UNLCK; |
| 5673 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5674 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5675 | if (data == NULL) { |
| 5676 | nfs_free_seqid(seqid); |
| 5677 | return ERR_PTR(-ENOMEM); |
| 5678 | } |
| 5679 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5680 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5681 | msg.rpc_argp = &data->arg; |
| 5682 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5683 | task_setup_data.callback_data = data; |
| 5684 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5685 | } |
| 5686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5688 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5689 | struct inode *inode = state->inode; |
| 5690 | struct nfs4_state_owner *sp = state->owner; |
| 5691 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5692 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5693 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5694 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5695 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5696 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5697 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5699 | status = nfs4_set_lock_state(state, request); |
| 5700 | /* Unlock _before_ we do the RPC call */ |
| 5701 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5702 | /* Exclude nfs_delegation_claim_locks() */ |
| 5703 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5704 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5705 | down_read(&nfsi->rwsem); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5706 | if (do_vfs_lock(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5707 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5708 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5709 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5710 | } |
| 5711 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5712 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5713 | if (status != 0) |
| 5714 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5715 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5716 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5717 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5718 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5719 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5720 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5721 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5722 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5723 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5724 | 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] | 5725 | status = PTR_ERR(task); |
| 5726 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5727 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5728 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5729 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5730 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5731 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5732 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5733 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | } |
| 5735 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5736 | struct nfs4_lockdata { |
| 5737 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5738 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5739 | struct nfs4_lock_state *lsp; |
| 5740 | struct nfs_open_context *ctx; |
| 5741 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5742 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5743 | int rpc_status; |
| 5744 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5745 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5746 | }; |
| 5747 | |
| 5748 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5749 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5750 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5751 | { |
| 5752 | struct nfs4_lockdata *p; |
| 5753 | struct inode *inode = lsp->ls_state->inode; |
| 5754 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5755 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5756 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5757 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5758 | if (p == NULL) |
| 5759 | return NULL; |
| 5760 | |
| 5761 | p->arg.fh = NFS_FH(inode); |
| 5762 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5763 | 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] | 5764 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5765 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5766 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5767 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5768 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5769 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5770 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5771 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5772 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5773 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5774 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5775 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5776 | atomic_inc(&lsp->ls_count); |
| 5777 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5778 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5779 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5780 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5781 | out_free_seqid: |
| 5782 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5783 | out_free: |
| 5784 | kfree(p); |
| 5785 | return NULL; |
| 5786 | } |
| 5787 | |
| 5788 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5789 | { |
| 5790 | struct nfs4_lockdata *data = calldata; |
| 5791 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5793 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5794 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5795 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5796 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5797 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5798 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5799 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5800 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5801 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5802 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5803 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5804 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5805 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5806 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5807 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5808 | &data->lsp->ls_stateid); |
| 5809 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5810 | if (!nfs4_valid_open_stateid(state)) { |
| 5811 | data->rpc_status = -EBADF; |
| 5812 | task->tk_action = NULL; |
| 5813 | goto out_release_open_seqid; |
| 5814 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5815 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5816 | if (nfs4_setup_sequence(data->server, |
| 5817 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5818 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5819 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5820 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5821 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5822 | nfs_release_seqid(data->arg.open_seqid); |
| 5823 | out_release_lock_seqid: |
| 5824 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5825 | out_wait: |
| 5826 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5827 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5828 | } |
| 5829 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5830 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5831 | { |
| 5832 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5833 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5834 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5835 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5836 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5837 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5838 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5839 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5840 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5841 | switch (task->tk_status) { |
| 5842 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5843 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5844 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5845 | if (data->arg.new_lock) { |
| 5846 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 5847 | if (do_vfs_lock(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5848 | rpc_restart_call_prepare(task); |
| 5849 | break; |
| 5850 | } |
| 5851 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5852 | if (data->arg.new_lock_owner != 0) { |
| 5853 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5854 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5855 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5856 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5857 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5858 | break; |
| 5859 | case -NFS4ERR_BAD_STATEID: |
| 5860 | case -NFS4ERR_OLD_STATEID: |
| 5861 | case -NFS4ERR_STALE_STATEID: |
| 5862 | case -NFS4ERR_EXPIRED: |
| 5863 | if (data->arg.new_lock_owner != 0) { |
| 5864 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5865 | &lsp->ls_state->open_stateid)) |
| 5866 | rpc_restart_call_prepare(task); |
| 5867 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5868 | &lsp->ls_stateid)) |
| 5869 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5870 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5871 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | static void nfs4_lock_release(void *calldata) |
| 5875 | { |
| 5876 | struct nfs4_lockdata *data = calldata; |
| 5877 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5878 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5879 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5880 | if (data->cancelled != 0) { |
| 5881 | struct rpc_task *task; |
| 5882 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5883 | data->arg.lock_seqid); |
| 5884 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5885 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5886 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5887 | } else |
| 5888 | nfs_free_seqid(data->arg.lock_seqid); |
| 5889 | nfs4_put_lock_state(data->lsp); |
| 5890 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5891 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5892 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5893 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5897 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5898 | .rpc_call_done = nfs4_lock_done, |
| 5899 | .rpc_release = nfs4_lock_release, |
| 5900 | }; |
| 5901 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5902 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5903 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5904 | switch (error) { |
| 5905 | case -NFS4ERR_ADMIN_REVOKED: |
| 5906 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5907 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5908 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5909 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5910 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5911 | break; |
| 5912 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5913 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5914 | case -NFS4ERR_EXPIRED: |
| 5915 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5916 | }; |
| 5917 | } |
| 5918 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5919 | 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] | 5920 | { |
| 5921 | struct nfs4_lockdata *data; |
| 5922 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5923 | struct rpc_message msg = { |
| 5924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5925 | .rpc_cred = state->owner->so_cred, |
| 5926 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5927 | struct rpc_task_setup task_setup_data = { |
| 5928 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5929 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5930 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5931 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5932 | .flags = RPC_TASK_ASYNC, |
| 5933 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5934 | int ret; |
| 5935 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5936 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5937 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5938 | fl->fl_u.nfs4_fl.owner, |
| 5939 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5940 | if (data == NULL) |
| 5941 | return -ENOMEM; |
| 5942 | if (IS_SETLKW(cmd)) |
| 5943 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5944 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5945 | msg.rpc_argp = &data->arg; |
| 5946 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5947 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5948 | if (recovery_type > NFS_LOCK_NEW) { |
| 5949 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5950 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5951 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5952 | } else |
| 5953 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5954 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5955 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5956 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5957 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5958 | if (ret == 0) { |
| 5959 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5960 | if (ret) |
| 5961 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5962 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5963 | } else |
| 5964 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5965 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5966 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5967 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5968 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5972 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5973 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5974 | struct nfs4_exception exception = { |
| 5975 | .inode = state->inode, |
| 5976 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5977 | int err; |
| 5978 | |
| 5979 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5980 | /* Cache the lock if possible... */ |
| 5981 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5982 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5983 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5984 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5985 | break; |
| 5986 | nfs4_handle_exception(server, err, &exception); |
| 5987 | } while (exception.retry); |
| 5988 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | } |
| 5990 | |
| 5991 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5992 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5993 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5994 | struct nfs4_exception exception = { |
| 5995 | .inode = state->inode, |
| 5996 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5997 | int err; |
| 5998 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5999 | err = nfs4_set_lock_state(state, request); |
| 6000 | if (err != 0) |
| 6001 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6002 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6003 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6004 | return 0; |
| 6005 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6006 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6007 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6008 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6009 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6010 | switch (err) { |
| 6011 | default: |
| 6012 | goto out; |
| 6013 | case -NFS4ERR_GRACE: |
| 6014 | case -NFS4ERR_DELAY: |
| 6015 | nfs4_handle_exception(server, err, &exception); |
| 6016 | err = 0; |
| 6017 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6018 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6019 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6020 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6021 | } |
| 6022 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6023 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6024 | /** |
| 6025 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6026 | * |
| 6027 | * @state: NFSv4 state for an inode |
| 6028 | * |
| 6029 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6030 | * Otherwise a negative NFS4ERR value is returned. |
| 6031 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6032 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6033 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6034 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6035 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6036 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6037 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6038 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6039 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6040 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6041 | |
| 6042 | status = nfs41_test_stateid(server, |
| 6043 | &lsp->ls_stateid, |
| 6044 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6045 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6046 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6047 | /* Free the stateid unless the server |
| 6048 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 6049 | if (status != -NFS4ERR_BAD_STATEID) |
| 6050 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6051 | &lsp->ls_stateid, |
| 6052 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6053 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6054 | ret = status; |
| 6055 | } |
| 6056 | } |
| 6057 | }; |
| 6058 | |
| 6059 | return ret; |
| 6060 | } |
| 6061 | |
| 6062 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6063 | { |
| 6064 | int status = NFS_OK; |
| 6065 | |
| 6066 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6067 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6068 | if (status != NFS_OK) |
| 6069 | status = nfs4_lock_expired(state, request); |
| 6070 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6071 | } |
| 6072 | #endif |
| 6073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6074 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6075 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6076 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6077 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6078 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 6079 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6080 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 6081 | if ((fl_flags & FL_POSIX) && |
| 6082 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6083 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6084 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6085 | status = nfs4_set_lock_state(state, request); |
| 6086 | if (status != 0) |
| 6087 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6088 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 6089 | status = do_vfs_lock(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6090 | if (status < 0) |
| 6091 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6092 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6093 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6094 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6095 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6096 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6097 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 83bfff2 | 2015-07-11 06:43:03 -0400 | [diff] [blame] | 6098 | status = do_vfs_lock(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6099 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6100 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6101 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6102 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6103 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6104 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6105 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6106 | out: |
| 6107 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | return status; |
| 6109 | } |
| 6110 | |
| 6111 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6112 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6113 | struct nfs4_exception exception = { |
| 6114 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6115 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6116 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | int err; |
| 6118 | |
| 6119 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6120 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6121 | if (err == -NFS4ERR_DENIED) |
| 6122 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6123 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6124 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | } while (exception.retry); |
| 6126 | return err; |
| 6127 | } |
| 6128 | |
| 6129 | static int |
| 6130 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6131 | { |
| 6132 | struct nfs_open_context *ctx; |
| 6133 | struct nfs4_state *state; |
| 6134 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6135 | int status; |
| 6136 | |
| 6137 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6138 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6139 | state = ctx->state; |
| 6140 | |
| 6141 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6142 | return -EINVAL; |
| 6143 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6144 | if (IS_GETLK(cmd)) { |
| 6145 | if (state != NULL) |
| 6146 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6147 | return 0; |
| 6148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6149 | |
| 6150 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6151 | return -EINVAL; |
| 6152 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6153 | if (request->fl_type == F_UNLCK) { |
| 6154 | if (state != NULL) |
| 6155 | return nfs4_proc_unlck(state, cmd, request); |
| 6156 | return 0; |
| 6157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6158 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6159 | if (state == NULL) |
| 6160 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6161 | /* |
| 6162 | * Don't rely on the VFS having checked the file open mode, |
| 6163 | * since it won't do this for flock() locks. |
| 6164 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6165 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6166 | case F_RDLCK: |
| 6167 | if (!(filp->f_mode & FMODE_READ)) |
| 6168 | return -EBADF; |
| 6169 | break; |
| 6170 | case F_WRLCK: |
| 6171 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6172 | return -EBADF; |
| 6173 | } |
| 6174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6175 | do { |
| 6176 | status = nfs4_proc_setlk(state, cmd, request); |
| 6177 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6178 | break; |
| 6179 | timeout = nfs4_set_lock_task_retry(timeout); |
| 6180 | status = -ERESTARTSYS; |
| 6181 | if (signalled()) |
| 6182 | break; |
| 6183 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | return status; |
| 6185 | } |
| 6186 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6187 | 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] | 6188 | { |
| 6189 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6190 | int err; |
| 6191 | |
| 6192 | err = nfs4_set_lock_state(state, fl); |
| 6193 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6194 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6195 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6196 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6197 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6198 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6199 | struct nfs_release_lockowner_data { |
| 6200 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6201 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6202 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6203 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6204 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6205 | }; |
| 6206 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6207 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6208 | { |
| 6209 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6210 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6211 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6212 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6213 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6214 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6218 | { |
| 6219 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6220 | struct nfs_server *server = data->server; |
| 6221 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6222 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6223 | |
| 6224 | switch (task->tk_status) { |
| 6225 | case 0: |
| 6226 | renew_lease(server, data->timestamp); |
| 6227 | break; |
| 6228 | case -NFS4ERR_STALE_CLIENTID: |
| 6229 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6230 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6231 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6232 | case -NFS4ERR_LEASE_MOVED: |
| 6233 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6234 | if (nfs4_async_handle_error(task, server, |
| 6235 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6236 | rpc_restart_call_prepare(task); |
| 6237 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6238 | } |
| 6239 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6240 | static void nfs4_release_lockowner_release(void *calldata) |
| 6241 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6242 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6243 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6244 | kfree(calldata); |
| 6245 | } |
| 6246 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6247 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6248 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6249 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6250 | .rpc_release = nfs4_release_lockowner_release, |
| 6251 | }; |
| 6252 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6253 | static void |
| 6254 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6255 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6256 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6257 | struct rpc_message msg = { |
| 6258 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6259 | }; |
| 6260 | |
| 6261 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6262 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6263 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6264 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6265 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6266 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6267 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6268 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6269 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6270 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6271 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6272 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6273 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6274 | msg.rpc_resp = &data->res; |
| 6275 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6276 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6277 | } |
| 6278 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6279 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6280 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6281 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6282 | struct dentry *unused, struct inode *inode, |
| 6283 | const char *key, const void *buf, |
| 6284 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6285 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6286 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6289 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6290 | struct dentry *unused, struct inode *inode, |
| 6291 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6292 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6293 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6294 | } |
| 6295 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6296 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6297 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6298 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6299 | } |
| 6300 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6301 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6302 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6303 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6304 | struct dentry *unused, struct inode *inode, |
| 6305 | const char *key, const void *buf, |
| 6306 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6307 | { |
| 6308 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6309 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6310 | |
| 6311 | return -EOPNOTSUPP; |
| 6312 | } |
| 6313 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6314 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6315 | struct dentry *unused, struct inode *inode, |
| 6316 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6317 | { |
| 6318 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6319 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6320 | return -EOPNOTSUPP; |
| 6321 | } |
| 6322 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6323 | static ssize_t |
| 6324 | 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] | 6325 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6326 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6327 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6328 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6329 | len = security_inode_listsecurity(inode, list, list_len); |
| 6330 | if (list_len && len > list_len) |
| 6331 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6332 | } |
| 6333 | return len; |
| 6334 | } |
| 6335 | |
| 6336 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6337 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6338 | .get = nfs4_xattr_get_nfs4_label, |
| 6339 | .set = nfs4_xattr_set_nfs4_label, |
| 6340 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6341 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6342 | #else |
| 6343 | |
| 6344 | static ssize_t |
| 6345 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6346 | { |
| 6347 | return 0; |
| 6348 | } |
| 6349 | |
| 6350 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6351 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6352 | /* |
| 6353 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6354 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6355 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6356 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6357 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6358 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6359 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6360 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6361 | return; |
| 6362 | |
| 6363 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6364 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6365 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6366 | fattr->nlink = 2; |
| 6367 | } |
| 6368 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6369 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6370 | const struct qstr *name, |
| 6371 | struct nfs4_fs_locations *fs_locations, |
| 6372 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6373 | { |
| 6374 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6375 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6376 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6377 | }; |
| 6378 | struct nfs4_fs_locations_arg args = { |
| 6379 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6380 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6381 | .page = page, |
| 6382 | .bitmask = bitmask, |
| 6383 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6384 | struct nfs4_fs_locations_res res = { |
| 6385 | .fs_locations = fs_locations, |
| 6386 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6387 | struct rpc_message msg = { |
| 6388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6389 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6390 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6391 | }; |
| 6392 | int status; |
| 6393 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6394 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6395 | |
| 6396 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6397 | * is not supported */ |
| 6398 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6399 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6400 | else |
| 6401 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6402 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6403 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6404 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6405 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6406 | 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] | 6407 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6408 | return status; |
| 6409 | } |
| 6410 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6411 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6412 | const struct qstr *name, |
| 6413 | struct nfs4_fs_locations *fs_locations, |
| 6414 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6415 | { |
| 6416 | struct nfs4_exception exception = { }; |
| 6417 | int err; |
| 6418 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6419 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6420 | fs_locations, page); |
| 6421 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6422 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6423 | &exception); |
| 6424 | } while (exception.retry); |
| 6425 | return err; |
| 6426 | } |
| 6427 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6428 | /* |
| 6429 | * This operation also signals the server that this client is |
| 6430 | * performing migration recovery. The server can stop returning |
| 6431 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6432 | * appended to this compound to identify the client ID which is |
| 6433 | * performing recovery. |
| 6434 | */ |
| 6435 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6436 | struct nfs4_fs_locations *locations, |
| 6437 | struct page *page, struct rpc_cred *cred) |
| 6438 | { |
| 6439 | struct nfs_server *server = NFS_SERVER(inode); |
| 6440 | struct rpc_clnt *clnt = server->client; |
| 6441 | u32 bitmask[2] = { |
| 6442 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6443 | }; |
| 6444 | struct nfs4_fs_locations_arg args = { |
| 6445 | .clientid = server->nfs_client->cl_clientid, |
| 6446 | .fh = NFS_FH(inode), |
| 6447 | .page = page, |
| 6448 | .bitmask = bitmask, |
| 6449 | .migration = 1, /* skip LOOKUP */ |
| 6450 | .renew = 1, /* append RENEW */ |
| 6451 | }; |
| 6452 | struct nfs4_fs_locations_res res = { |
| 6453 | .fs_locations = locations, |
| 6454 | .migration = 1, |
| 6455 | .renew = 1, |
| 6456 | }; |
| 6457 | struct rpc_message msg = { |
| 6458 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6459 | .rpc_argp = &args, |
| 6460 | .rpc_resp = &res, |
| 6461 | .rpc_cred = cred, |
| 6462 | }; |
| 6463 | unsigned long now = jiffies; |
| 6464 | int status; |
| 6465 | |
| 6466 | nfs_fattr_init(&locations->fattr); |
| 6467 | locations->server = server; |
| 6468 | locations->nlocations = 0; |
| 6469 | |
| 6470 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6471 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6472 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6473 | &args.seq_args, &res.seq_res); |
| 6474 | if (status) |
| 6475 | return status; |
| 6476 | |
| 6477 | renew_lease(server, now); |
| 6478 | return 0; |
| 6479 | } |
| 6480 | |
| 6481 | #ifdef CONFIG_NFS_V4_1 |
| 6482 | |
| 6483 | /* |
| 6484 | * This operation also signals the server that this client is |
| 6485 | * performing migration recovery. The server can stop asserting |
| 6486 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6487 | * performing this operation is identified in the SEQUENCE |
| 6488 | * operation in this compound. |
| 6489 | * |
| 6490 | * When the client supports GETATTR(fs_locations_info), it can |
| 6491 | * be plumbed in here. |
| 6492 | */ |
| 6493 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6494 | struct nfs4_fs_locations *locations, |
| 6495 | struct page *page, struct rpc_cred *cred) |
| 6496 | { |
| 6497 | struct nfs_server *server = NFS_SERVER(inode); |
| 6498 | struct rpc_clnt *clnt = server->client; |
| 6499 | u32 bitmask[2] = { |
| 6500 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6501 | }; |
| 6502 | struct nfs4_fs_locations_arg args = { |
| 6503 | .fh = NFS_FH(inode), |
| 6504 | .page = page, |
| 6505 | .bitmask = bitmask, |
| 6506 | .migration = 1, /* skip LOOKUP */ |
| 6507 | }; |
| 6508 | struct nfs4_fs_locations_res res = { |
| 6509 | .fs_locations = locations, |
| 6510 | .migration = 1, |
| 6511 | }; |
| 6512 | struct rpc_message msg = { |
| 6513 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6514 | .rpc_argp = &args, |
| 6515 | .rpc_resp = &res, |
| 6516 | .rpc_cred = cred, |
| 6517 | }; |
| 6518 | int status; |
| 6519 | |
| 6520 | nfs_fattr_init(&locations->fattr); |
| 6521 | locations->server = server; |
| 6522 | locations->nlocations = 0; |
| 6523 | |
| 6524 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6525 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6526 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6527 | &args.seq_args, &res.seq_res); |
| 6528 | if (status == NFS4_OK && |
| 6529 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6530 | status = -NFS4ERR_LEASE_MOVED; |
| 6531 | return status; |
| 6532 | } |
| 6533 | |
| 6534 | #endif /* CONFIG_NFS_V4_1 */ |
| 6535 | |
| 6536 | /** |
| 6537 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6538 | * @inode: inode on FSID that is migrating |
| 6539 | * @locations: result of query |
| 6540 | * @page: buffer |
| 6541 | * @cred: credential to use for this operation |
| 6542 | * |
| 6543 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6544 | * operation failed, or a negative errno if a local error occurred. |
| 6545 | * |
| 6546 | * On success, "locations" is filled in, but if the server has |
| 6547 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6548 | * asserted. |
| 6549 | * |
| 6550 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6551 | * from this client that require migration recovery. |
| 6552 | */ |
| 6553 | int nfs4_proc_get_locations(struct inode *inode, |
| 6554 | struct nfs4_fs_locations *locations, |
| 6555 | struct page *page, struct rpc_cred *cred) |
| 6556 | { |
| 6557 | struct nfs_server *server = NFS_SERVER(inode); |
| 6558 | struct nfs_client *clp = server->nfs_client; |
| 6559 | const struct nfs4_mig_recovery_ops *ops = |
| 6560 | clp->cl_mvops->mig_recovery_ops; |
| 6561 | struct nfs4_exception exception = { }; |
| 6562 | int status; |
| 6563 | |
| 6564 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6565 | (unsigned long long)server->fsid.major, |
| 6566 | (unsigned long long)server->fsid.minor, |
| 6567 | clp->cl_hostname); |
| 6568 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6569 | |
| 6570 | do { |
| 6571 | status = ops->get_locations(inode, locations, page, cred); |
| 6572 | if (status != -NFS4ERR_DELAY) |
| 6573 | break; |
| 6574 | nfs4_handle_exception(server, status, &exception); |
| 6575 | } while (exception.retry); |
| 6576 | return status; |
| 6577 | } |
| 6578 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6579 | /* |
| 6580 | * This operation also signals the server that this client is |
| 6581 | * performing "lease moved" recovery. The server can stop |
| 6582 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6583 | * is appended to this compound to identify the client ID which is |
| 6584 | * performing recovery. |
| 6585 | */ |
| 6586 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6587 | { |
| 6588 | struct nfs_server *server = NFS_SERVER(inode); |
| 6589 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6590 | struct rpc_clnt *clnt = server->client; |
| 6591 | struct nfs4_fsid_present_arg args = { |
| 6592 | .fh = NFS_FH(inode), |
| 6593 | .clientid = clp->cl_clientid, |
| 6594 | .renew = 1, /* append RENEW */ |
| 6595 | }; |
| 6596 | struct nfs4_fsid_present_res res = { |
| 6597 | .renew = 1, |
| 6598 | }; |
| 6599 | struct rpc_message msg = { |
| 6600 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6601 | .rpc_argp = &args, |
| 6602 | .rpc_resp = &res, |
| 6603 | .rpc_cred = cred, |
| 6604 | }; |
| 6605 | unsigned long now = jiffies; |
| 6606 | int status; |
| 6607 | |
| 6608 | res.fh = nfs_alloc_fhandle(); |
| 6609 | if (res.fh == NULL) |
| 6610 | return -ENOMEM; |
| 6611 | |
| 6612 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6613 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6614 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6615 | &args.seq_args, &res.seq_res); |
| 6616 | nfs_free_fhandle(res.fh); |
| 6617 | if (status) |
| 6618 | return status; |
| 6619 | |
| 6620 | do_renew_lease(clp, now); |
| 6621 | return 0; |
| 6622 | } |
| 6623 | |
| 6624 | #ifdef CONFIG_NFS_V4_1 |
| 6625 | |
| 6626 | /* |
| 6627 | * This operation also signals the server that this client is |
| 6628 | * performing "lease moved" recovery. The server can stop asserting |
| 6629 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6630 | * this operation is identified in the SEQUENCE operation in this |
| 6631 | * compound. |
| 6632 | */ |
| 6633 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6634 | { |
| 6635 | struct nfs_server *server = NFS_SERVER(inode); |
| 6636 | struct rpc_clnt *clnt = server->client; |
| 6637 | struct nfs4_fsid_present_arg args = { |
| 6638 | .fh = NFS_FH(inode), |
| 6639 | }; |
| 6640 | struct nfs4_fsid_present_res res = { |
| 6641 | }; |
| 6642 | struct rpc_message msg = { |
| 6643 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6644 | .rpc_argp = &args, |
| 6645 | .rpc_resp = &res, |
| 6646 | .rpc_cred = cred, |
| 6647 | }; |
| 6648 | int status; |
| 6649 | |
| 6650 | res.fh = nfs_alloc_fhandle(); |
| 6651 | if (res.fh == NULL) |
| 6652 | return -ENOMEM; |
| 6653 | |
| 6654 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6655 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6656 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6657 | &args.seq_args, &res.seq_res); |
| 6658 | nfs_free_fhandle(res.fh); |
| 6659 | if (status == NFS4_OK && |
| 6660 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6661 | status = -NFS4ERR_LEASE_MOVED; |
| 6662 | return status; |
| 6663 | } |
| 6664 | |
| 6665 | #endif /* CONFIG_NFS_V4_1 */ |
| 6666 | |
| 6667 | /** |
| 6668 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6669 | * @inode: inode on FSID to check |
| 6670 | * @cred: credential to use for this operation |
| 6671 | * |
| 6672 | * Server indicates whether the FSID is present, moved, or not |
| 6673 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6674 | * condition for this client ID. |
| 6675 | * |
| 6676 | * Returns NFS4_OK if the FSID is present on this server, |
| 6677 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6678 | * NFS4ERR code if some error occurred on the server, or a |
| 6679 | * negative errno if a local failure occurred. |
| 6680 | */ |
| 6681 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6682 | { |
| 6683 | struct nfs_server *server = NFS_SERVER(inode); |
| 6684 | struct nfs_client *clp = server->nfs_client; |
| 6685 | const struct nfs4_mig_recovery_ops *ops = |
| 6686 | clp->cl_mvops->mig_recovery_ops; |
| 6687 | struct nfs4_exception exception = { }; |
| 6688 | int status; |
| 6689 | |
| 6690 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6691 | (unsigned long long)server->fsid.major, |
| 6692 | (unsigned long long)server->fsid.minor, |
| 6693 | clp->cl_hostname); |
| 6694 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6695 | |
| 6696 | do { |
| 6697 | status = ops->fsid_present(inode, cred); |
| 6698 | if (status != -NFS4ERR_DELAY) |
| 6699 | break; |
| 6700 | nfs4_handle_exception(server, status, &exception); |
| 6701 | } while (exception.retry); |
| 6702 | return status; |
| 6703 | } |
| 6704 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6705 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6706 | * If 'use_integrity' is true and the state managment nfs_client |
| 6707 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6708 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6709 | * Considerations sections. Otherwise, just use the user cred with the |
| 6710 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6711 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6712 | 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] | 6713 | { |
| 6714 | int status; |
| 6715 | struct nfs4_secinfo_arg args = { |
| 6716 | .dir_fh = NFS_FH(dir), |
| 6717 | .name = name, |
| 6718 | }; |
| 6719 | struct nfs4_secinfo_res res = { |
| 6720 | .flavors = flavors, |
| 6721 | }; |
| 6722 | struct rpc_message msg = { |
| 6723 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6724 | .rpc_argp = &args, |
| 6725 | .rpc_resp = &res, |
| 6726 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6727 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6728 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6729 | |
| 6730 | if (use_integrity) { |
| 6731 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6732 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6733 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6734 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6735 | |
| 6736 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6737 | |
| 6738 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6739 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6740 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6741 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6742 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6743 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6744 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6745 | if (cred) |
| 6746 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6747 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6748 | return status; |
| 6749 | } |
| 6750 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6751 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6752 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6753 | { |
| 6754 | struct nfs4_exception exception = { }; |
| 6755 | int err; |
| 6756 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6757 | err = -NFS4ERR_WRONGSEC; |
| 6758 | |
| 6759 | /* try to use integrity protection with machine cred */ |
| 6760 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6761 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6762 | |
| 6763 | /* |
| 6764 | * if unable to use integrity protection, or SECINFO with |
| 6765 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6766 | * disallowed by spec, but exists in deployed servers) use |
| 6767 | * the current filesystem's rpc_client and the user cred. |
| 6768 | */ |
| 6769 | if (err == -NFS4ERR_WRONGSEC) |
| 6770 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6771 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6772 | trace_nfs4_secinfo(dir, name, err); |
| 6773 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6774 | &exception); |
| 6775 | } while (exception.retry); |
| 6776 | return err; |
| 6777 | } |
| 6778 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6779 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6780 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6781 | * Check the exchange flags returned by the server for invalid flags, having |
| 6782 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6783 | * DS flags set. |
| 6784 | */ |
| 6785 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6786 | { |
| 6787 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6788 | goto out_inval; |
| 6789 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6790 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6791 | goto out_inval; |
| 6792 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6793 | goto out_inval; |
| 6794 | return NFS_OK; |
| 6795 | out_inval: |
| 6796 | return -NFS4ERR_INVAL; |
| 6797 | } |
| 6798 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6799 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6800 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6801 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6802 | { |
| 6803 | if (a->server_scope_sz == b->server_scope_sz && |
| 6804 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6805 | return true; |
| 6806 | |
| 6807 | return false; |
| 6808 | } |
| 6809 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6810 | static void |
| 6811 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 6812 | { |
| 6813 | } |
| 6814 | |
| 6815 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 6816 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 6817 | }; |
| 6818 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6819 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6820 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6821 | * |
| 6822 | * The 4.1 client currently uses the same TCP connection for the |
| 6823 | * fore and backchannel. |
| 6824 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6825 | static |
| 6826 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 6827 | struct rpc_xprt *xprt, |
| 6828 | struct nfs_client *clp, |
| 6829 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6830 | { |
| 6831 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6832 | struct nfs41_bind_conn_to_session_args args = { |
| 6833 | .client = clp, |
| 6834 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6835 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6836 | struct nfs41_bind_conn_to_session_res res; |
| 6837 | struct rpc_message msg = { |
| 6838 | .rpc_proc = |
| 6839 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6840 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6841 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6842 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6843 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6844 | struct rpc_task_setup task_setup_data = { |
| 6845 | .rpc_client = clnt, |
| 6846 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6847 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6848 | .rpc_message = &msg, |
| 6849 | .flags = RPC_TASK_TIMEOUT, |
| 6850 | }; |
| 6851 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6852 | |
| 6853 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6854 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6855 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 6856 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 6857 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6858 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6859 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 6860 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 6861 | args.dir = NFS4_CDFC4_FORE; |
| 6862 | |
| 6863 | task = rpc_run_task(&task_setup_data); |
| 6864 | if (!IS_ERR(task)) { |
| 6865 | status = task->tk_status; |
| 6866 | rpc_put_task(task); |
| 6867 | } else |
| 6868 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6869 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6870 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6871 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6872 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6873 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6874 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6875 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6876 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6877 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6878 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6879 | __func__); |
| 6880 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6881 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6882 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6883 | 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] | 6884 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6885 | __func__); |
| 6886 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6887 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6888 | } |
| 6889 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6890 | out: |
| 6891 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6892 | return status; |
| 6893 | } |
| 6894 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6895 | struct rpc_bind_conn_calldata { |
| 6896 | struct nfs_client *clp; |
| 6897 | struct rpc_cred *cred; |
| 6898 | }; |
| 6899 | |
| 6900 | static int |
| 6901 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 6902 | struct rpc_xprt *xprt, |
| 6903 | void *calldata) |
| 6904 | { |
| 6905 | struct rpc_bind_conn_calldata *p = calldata; |
| 6906 | |
| 6907 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 6908 | } |
| 6909 | |
| 6910 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 6911 | { |
| 6912 | struct rpc_bind_conn_calldata data = { |
| 6913 | .clp = clp, |
| 6914 | .cred = cred, |
| 6915 | }; |
| 6916 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 6917 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 6918 | } |
| 6919 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6920 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6921 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6922 | * 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] | 6923 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6924 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6925 | .how = SP4_MACH_CRED, |
| 6926 | .enforce.u.words = { |
| 6927 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6928 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6929 | 1 << (OP_CREATE_SESSION - 32) | |
| 6930 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6931 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6932 | }, |
| 6933 | .allow.u.words = { |
| 6934 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6935 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6936 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6937 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6938 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6939 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6940 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 6941 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6942 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6943 | 1 << (OP_FREE_STATEID - 32) | |
| 6944 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6945 | } |
| 6946 | }; |
| 6947 | |
| 6948 | /* |
| 6949 | * Select the state protection mode for client `clp' given the server results |
| 6950 | * from exchange_id in `sp'. |
| 6951 | * |
| 6952 | * Returns 0 on success, negative errno otherwise. |
| 6953 | */ |
| 6954 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6955 | struct nfs41_state_protection *sp) |
| 6956 | { |
| 6957 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6958 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6959 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6960 | 1 << (OP_CREATE_SESSION - 32) | |
| 6961 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6962 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6963 | }; |
| 6964 | unsigned int i; |
| 6965 | |
| 6966 | if (sp->how == SP4_MACH_CRED) { |
| 6967 | /* Print state protect result */ |
| 6968 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6969 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6970 | if (test_bit(i, sp->enforce.u.longs)) |
| 6971 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6972 | if (test_bit(i, sp->allow.u.longs)) |
| 6973 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6974 | } |
| 6975 | |
| 6976 | /* make sure nothing is on enforce list that isn't supported */ |
| 6977 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6978 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6979 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6980 | return -EINVAL; |
| 6981 | } |
| 6982 | } |
| 6983 | |
| 6984 | /* |
| 6985 | * Minimal mode - state operations are allowed to use machine |
| 6986 | * credential. Note this already happens by default, so the |
| 6987 | * client doesn't have to do anything more than the negotiation. |
| 6988 | * |
| 6989 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6990 | * we're already using the machine cred for exchange_id |
| 6991 | * and will never use a different cred. |
| 6992 | */ |
| 6993 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6994 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6995 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6996 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6997 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6998 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6999 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7000 | } else { |
| 7001 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7002 | return -EINVAL; |
| 7003 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7004 | |
| 7005 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7006 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7007 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7008 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7009 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7010 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7011 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7012 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7013 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7014 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7015 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7016 | &clp->cl_sp4_flags); |
| 7017 | } |
| 7018 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7019 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7020 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7021 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7022 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7023 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7024 | |
| 7025 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7026 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7027 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7028 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7029 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7030 | |
| 7031 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7032 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7033 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7034 | } |
| 7035 | |
| 7036 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7037 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7038 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7039 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7040 | } |
| 7041 | |
| 7042 | return 0; |
| 7043 | } |
| 7044 | |
| 7045 | /* |
| 7046 | * _nfs4_proc_exchange_id() |
| 7047 | * |
| 7048 | * Wrapper for EXCHANGE_ID operation. |
| 7049 | */ |
| 7050 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7051 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7052 | { |
| 7053 | nfs4_verifier verifier; |
| 7054 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 7055 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7056 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 7057 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 7058 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 7059 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7060 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7061 | #else |
| 7062 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7063 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7064 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7065 | }; |
| 7066 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7067 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7068 | }; |
| 7069 | int status; |
| 7070 | struct rpc_message msg = { |
| 7071 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 7072 | .rpc_argp = &args, |
| 7073 | .rpc_resp = &res, |
| 7074 | .rpc_cred = cred, |
| 7075 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7076 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 7077 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7078 | |
| 7079 | status = nfs4_init_uniform_client_string(clp); |
| 7080 | if (status) |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7081 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7082 | |
| 7083 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7084 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7085 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7086 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7087 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7088 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7089 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7090 | status = -ENOMEM; |
| 7091 | goto out; |
| 7092 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7093 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7094 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7095 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7096 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7097 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7098 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7099 | } |
| 7100 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7101 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7102 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7103 | status = -ENOMEM; |
| 7104 | goto out_server_scope; |
| 7105 | } |
| 7106 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7107 | switch (sp4_how) { |
| 7108 | case SP4_NONE: |
| 7109 | args.state_protect.how = SP4_NONE; |
| 7110 | break; |
| 7111 | |
| 7112 | case SP4_MACH_CRED: |
| 7113 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 7114 | break; |
| 7115 | |
| 7116 | default: |
| 7117 | /* unsupported! */ |
| 7118 | WARN_ON_ONCE(1); |
| 7119 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7120 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7121 | } |
| 7122 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7123 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7124 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7125 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7126 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7127 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7128 | if (status == 0) |
| 7129 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 7130 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7131 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7132 | clp->cl_clientid = res.clientid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7133 | clp->cl_exchange_flags = res.flags; |
| 7134 | /* Client ID is not confirmed */ |
| 7135 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7136 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7137 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7138 | clp->cl_seqid = res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7139 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7140 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7141 | kfree(clp->cl_serverowner); |
| 7142 | clp->cl_serverowner = res.server_owner; |
| 7143 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7144 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7145 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7146 | kfree(clp->cl_implid); |
| 7147 | clp->cl_implid = res.impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7148 | res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7149 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7150 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7151 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7152 | res.server_scope)) { |
| 7153 | dprintk("%s: server_scope mismatch detected\n", |
| 7154 | __func__); |
| 7155 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7156 | kfree(clp->cl_serverscope); |
| 7157 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7158 | } |
| 7159 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7160 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7161 | clp->cl_serverscope = res.server_scope; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7162 | res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7163 | } |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7164 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7165 | |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7166 | out_impl_id: |
| 7167 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7168 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7169 | kfree(res.server_scope); |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7170 | out_server_owner: |
| 7171 | kfree(res.server_owner); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7172 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7173 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7174 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7175 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7176 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7177 | clp->cl_implid->date.seconds, |
| 7178 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7179 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7180 | return status; |
| 7181 | } |
| 7182 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7183 | /* |
| 7184 | * nfs4_proc_exchange_id() |
| 7185 | * |
| 7186 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7187 | * |
| 7188 | * Since the clientid has expired, all compounds using sessions |
| 7189 | * associated with the stale clientid will be returning |
| 7190 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7191 | * be in some phase of session reset. |
| 7192 | * |
| 7193 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7194 | */ |
| 7195 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7196 | { |
| 7197 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7198 | int status; |
| 7199 | |
| 7200 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7201 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7202 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 7203 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 7204 | if (!status) |
| 7205 | return 0; |
| 7206 | } |
| 7207 | |
| 7208 | /* try SP4_NONE */ |
| 7209 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 7210 | } |
| 7211 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7212 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7213 | struct rpc_cred *cred) |
| 7214 | { |
| 7215 | struct rpc_message msg = { |
| 7216 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7217 | .rpc_argp = clp, |
| 7218 | .rpc_cred = cred, |
| 7219 | }; |
| 7220 | int status; |
| 7221 | |
| 7222 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7223 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7224 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7225 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7226 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7227 | return status; |
| 7228 | } |
| 7229 | |
| 7230 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7231 | struct rpc_cred *cred) |
| 7232 | { |
| 7233 | unsigned int loop; |
| 7234 | int ret; |
| 7235 | |
| 7236 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7237 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7238 | switch (ret) { |
| 7239 | case -NFS4ERR_DELAY: |
| 7240 | case -NFS4ERR_CLIENTID_BUSY: |
| 7241 | ssleep(1); |
| 7242 | break; |
| 7243 | default: |
| 7244 | return ret; |
| 7245 | } |
| 7246 | } |
| 7247 | return 0; |
| 7248 | } |
| 7249 | |
| 7250 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7251 | { |
| 7252 | struct rpc_cred *cred; |
| 7253 | int ret = 0; |
| 7254 | |
| 7255 | if (clp->cl_mvops->minor_version < 1) |
| 7256 | goto out; |
| 7257 | if (clp->cl_exchange_flags == 0) |
| 7258 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7259 | if (clp->cl_preserve_clid) |
| 7260 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7261 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7262 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7263 | if (cred) |
| 7264 | put_rpccred(cred); |
| 7265 | switch (ret) { |
| 7266 | case 0: |
| 7267 | case -NFS4ERR_STALE_CLIENTID: |
| 7268 | clp->cl_exchange_flags = 0; |
| 7269 | } |
| 7270 | out: |
| 7271 | return ret; |
| 7272 | } |
| 7273 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7274 | struct nfs4_get_lease_time_data { |
| 7275 | struct nfs4_get_lease_time_args *args; |
| 7276 | struct nfs4_get_lease_time_res *res; |
| 7277 | struct nfs_client *clp; |
| 7278 | }; |
| 7279 | |
| 7280 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7281 | void *calldata) |
| 7282 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7283 | struct nfs4_get_lease_time_data *data = |
| 7284 | (struct nfs4_get_lease_time_data *)calldata; |
| 7285 | |
| 7286 | dprintk("--> %s\n", __func__); |
| 7287 | /* just setup sequence, do not trigger session recovery |
| 7288 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7289 | nfs41_setup_sequence(data->clp->cl_session, |
| 7290 | &data->args->la_seq_args, |
| 7291 | &data->res->lr_seq_res, |
| 7292 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7293 | dprintk("<-- %s\n", __func__); |
| 7294 | } |
| 7295 | |
| 7296 | /* |
| 7297 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7298 | * from sequence operation or clientid errors. |
| 7299 | */ |
| 7300 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7301 | { |
| 7302 | struct nfs4_get_lease_time_data *data = |
| 7303 | (struct nfs4_get_lease_time_data *)calldata; |
| 7304 | |
| 7305 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7306 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7307 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7308 | switch (task->tk_status) { |
| 7309 | case -NFS4ERR_DELAY: |
| 7310 | case -NFS4ERR_GRACE: |
| 7311 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7312 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7313 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7314 | /* fall through */ |
| 7315 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7316 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7317 | return; |
| 7318 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7319 | dprintk("<-- %s\n", __func__); |
| 7320 | } |
| 7321 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7322 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7323 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7324 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7325 | }; |
| 7326 | |
| 7327 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7328 | { |
| 7329 | struct rpc_task *task; |
| 7330 | struct nfs4_get_lease_time_args args; |
| 7331 | struct nfs4_get_lease_time_res res = { |
| 7332 | .lr_fsinfo = fsinfo, |
| 7333 | }; |
| 7334 | struct nfs4_get_lease_time_data data = { |
| 7335 | .args = &args, |
| 7336 | .res = &res, |
| 7337 | .clp = clp, |
| 7338 | }; |
| 7339 | struct rpc_message msg = { |
| 7340 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7341 | .rpc_argp = &args, |
| 7342 | .rpc_resp = &res, |
| 7343 | }; |
| 7344 | struct rpc_task_setup task_setup = { |
| 7345 | .rpc_client = clp->cl_rpcclient, |
| 7346 | .rpc_message = &msg, |
| 7347 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7348 | .callback_data = &data, |
| 7349 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7350 | }; |
| 7351 | int status; |
| 7352 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7353 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7354 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7355 | dprintk("--> %s\n", __func__); |
| 7356 | task = rpc_run_task(&task_setup); |
| 7357 | |
| 7358 | if (IS_ERR(task)) |
| 7359 | status = PTR_ERR(task); |
| 7360 | else { |
| 7361 | status = task->tk_status; |
| 7362 | rpc_put_task(task); |
| 7363 | } |
| 7364 | dprintk("<-- %s return %d\n", __func__, status); |
| 7365 | |
| 7366 | return status; |
| 7367 | } |
| 7368 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7369 | /* |
| 7370 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7371 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7372 | * use them. |
| 7373 | * |
| 7374 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7375 | * always set csa_cachethis to FALSE because the current implementation |
| 7376 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7377 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7378 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7379 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7380 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7381 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7382 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7383 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7384 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7385 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7386 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7387 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7388 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7389 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7390 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7391 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7392 | |
| 7393 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7394 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7395 | __func__, |
| 7396 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7397 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7398 | |
| 7399 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7400 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7401 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7402 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7403 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | f4f58ed | 2016-01-23 14:12:52 -0500 | [diff] [blame] | 7404 | args->bc_attrs.max_reqs = NFS41_BC_MAX_CALLBACKS; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7405 | |
| 7406 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7407 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7408 | __func__, |
| 7409 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7410 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7411 | args->bc_attrs.max_reqs); |
| 7412 | } |
| 7413 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7414 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7415 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7416 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7417 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7418 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7419 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7420 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7421 | return -EINVAL; |
| 7422 | /* |
| 7423 | * Our requested max_ops is the minimum we need; we're not |
| 7424 | * prepared to break up compounds into smaller pieces than that. |
| 7425 | * So, no point even trying to continue if the server won't |
| 7426 | * cooperate: |
| 7427 | */ |
| 7428 | if (rcvd->max_ops < sent->max_ops) |
| 7429 | return -EINVAL; |
| 7430 | if (rcvd->max_reqs == 0) |
| 7431 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7432 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7433 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7434 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7435 | } |
| 7436 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7437 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7438 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7439 | { |
| 7440 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7441 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7442 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7443 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7444 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7445 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7446 | return -EINVAL; |
| 7447 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7448 | return -EINVAL; |
| 7449 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7450 | return -EINVAL; |
| 7451 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7452 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7453 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7454 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7455 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7456 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7457 | return 0; |
| 7458 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7459 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7460 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7461 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7462 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7463 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7464 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7465 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7466 | if (ret) |
| 7467 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7468 | return nfs4_verify_back_channel_attrs(args, res); |
| 7469 | } |
| 7470 | |
| 7471 | static void nfs4_update_session(struct nfs4_session *session, |
| 7472 | struct nfs41_create_session_res *res) |
| 7473 | { |
| 7474 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7475 | /* Mark client id and session as being confirmed */ |
| 7476 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7477 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7478 | session->flags = res->flags; |
| 7479 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7480 | if (res->flags & SESSION4_BACK_CHAN) |
| 7481 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7482 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7483 | } |
| 7484 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7485 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7486 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7487 | { |
| 7488 | struct nfs4_session *session = clp->cl_session; |
| 7489 | struct nfs41_create_session_args args = { |
| 7490 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7491 | .clientid = clp->cl_clientid, |
| 7492 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7493 | .cb_program = NFS4_CALLBACK, |
| 7494 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7495 | struct nfs41_create_session_res res; |
| 7496 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7497 | struct rpc_message msg = { |
| 7498 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7499 | .rpc_argp = &args, |
| 7500 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7501 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7502 | }; |
| 7503 | int status; |
| 7504 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7505 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7506 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7507 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7508 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7509 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7510 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7511 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7512 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7513 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7514 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7515 | if (clp->cl_seqid == res.seqid) |
| 7516 | clp->cl_seqid++; |
| 7517 | if (status) |
| 7518 | goto out; |
| 7519 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7520 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7521 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7522 | return status; |
| 7523 | } |
| 7524 | |
| 7525 | /* |
| 7526 | * Issues a CREATE_SESSION operation to the server. |
| 7527 | * It is the responsibility of the caller to verify the session is |
| 7528 | * expired before calling this routine. |
| 7529 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7530 | 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] | 7531 | { |
| 7532 | int status; |
| 7533 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7534 | struct nfs4_session *session = clp->cl_session; |
| 7535 | |
| 7536 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7537 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7538 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7539 | if (status) |
| 7540 | goto out; |
| 7541 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7542 | /* Init or reset the session slot tables */ |
| 7543 | status = nfs4_setup_session_slot_tables(session); |
| 7544 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7545 | if (status) |
| 7546 | goto out; |
| 7547 | |
| 7548 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7549 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7550 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7551 | out: |
| 7552 | dprintk("<-- %s\n", __func__); |
| 7553 | return status; |
| 7554 | } |
| 7555 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7556 | /* |
| 7557 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7558 | * The caller must serialize access to this routine. |
| 7559 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7560 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7561 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7562 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7563 | struct rpc_message msg = { |
| 7564 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7565 | .rpc_argp = session, |
| 7566 | .rpc_cred = cred, |
| 7567 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7568 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7569 | |
| 7570 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7571 | |
| 7572 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7573 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7574 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7575 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7576 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7577 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7578 | |
| 7579 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7580 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7581 | "Session has been destroyed regardless...\n", status); |
| 7582 | |
| 7583 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7584 | return status; |
| 7585 | } |
| 7586 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7587 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7588 | * Renew the cl_session lease. |
| 7589 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7590 | struct nfs4_sequence_data { |
| 7591 | struct nfs_client *clp; |
| 7592 | struct nfs4_sequence_args args; |
| 7593 | struct nfs4_sequence_res res; |
| 7594 | }; |
| 7595 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7596 | static void nfs41_sequence_release(void *data) |
| 7597 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7598 | struct nfs4_sequence_data *calldata = data; |
| 7599 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7600 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7601 | if (atomic_read(&clp->cl_count) > 1) |
| 7602 | nfs4_schedule_state_renewal(clp); |
| 7603 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7604 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7605 | } |
| 7606 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7607 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7608 | { |
| 7609 | switch(task->tk_status) { |
| 7610 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7611 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7612 | return -EAGAIN; |
| 7613 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7614 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7615 | } |
| 7616 | return 0; |
| 7617 | } |
| 7618 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7619 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7620 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7621 | struct nfs4_sequence_data *calldata = data; |
| 7622 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7623 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7624 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7625 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7626 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7627 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7628 | if (task->tk_status < 0) { |
| 7629 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7630 | if (atomic_read(&clp->cl_count) == 1) |
| 7631 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7632 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7633 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7634 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7635 | return; |
| 7636 | } |
| 7637 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7638 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7639 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7640 | dprintk("<-- %s\n", __func__); |
| 7641 | } |
| 7642 | |
| 7643 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7644 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7645 | struct nfs4_sequence_data *calldata = data; |
| 7646 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7647 | struct nfs4_sequence_args *args; |
| 7648 | struct nfs4_sequence_res *res; |
| 7649 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7650 | args = task->tk_msg.rpc_argp; |
| 7651 | res = task->tk_msg.rpc_resp; |
| 7652 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7653 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7657 | .rpc_call_done = nfs41_sequence_call_done, |
| 7658 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7659 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7660 | }; |
| 7661 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7662 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7663 | struct rpc_cred *cred, |
| 7664 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7665 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7666 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7667 | struct rpc_message msg = { |
| 7668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7669 | .rpc_cred = cred, |
| 7670 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7671 | struct rpc_task_setup task_setup_data = { |
| 7672 | .rpc_client = clp->cl_rpcclient, |
| 7673 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7674 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7675 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7676 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7677 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7678 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7679 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7680 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7681 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7682 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7683 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7684 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7685 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7686 | if (is_privileged) |
| 7687 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7688 | msg.rpc_argp = &calldata->args; |
| 7689 | msg.rpc_resp = &calldata->res; |
| 7690 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7691 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7692 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7693 | return rpc_run_task(&task_setup_data); |
| 7694 | } |
| 7695 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7696 | 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] | 7697 | { |
| 7698 | struct rpc_task *task; |
| 7699 | int ret = 0; |
| 7700 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7701 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7702 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7703 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7704 | if (IS_ERR(task)) |
| 7705 | ret = PTR_ERR(task); |
| 7706 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7707 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7708 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7709 | return ret; |
| 7710 | } |
| 7711 | |
| 7712 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7713 | { |
| 7714 | struct rpc_task *task; |
| 7715 | int ret; |
| 7716 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7717 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7718 | if (IS_ERR(task)) { |
| 7719 | ret = PTR_ERR(task); |
| 7720 | goto out; |
| 7721 | } |
| 7722 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 7723 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7724 | ret = task->tk_status; |
| 7725 | rpc_put_task(task); |
| 7726 | out: |
| 7727 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7728 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7729 | } |
| 7730 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7731 | struct nfs4_reclaim_complete_data { |
| 7732 | struct nfs_client *clp; |
| 7733 | struct nfs41_reclaim_complete_args arg; |
| 7734 | struct nfs41_reclaim_complete_res res; |
| 7735 | }; |
| 7736 | |
| 7737 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7738 | { |
| 7739 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7740 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7741 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7742 | &calldata->arg.seq_args, |
| 7743 | &calldata->res.seq_res, |
| 7744 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7745 | } |
| 7746 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7747 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7748 | { |
| 7749 | switch(task->tk_status) { |
| 7750 | case 0: |
| 7751 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7752 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7753 | break; |
| 7754 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7755 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7756 | /* fall through */ |
| 7757 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7758 | return -EAGAIN; |
| 7759 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7760 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7761 | } |
| 7762 | return 0; |
| 7763 | } |
| 7764 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7765 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7766 | { |
| 7767 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7768 | struct nfs_client *clp = calldata->clp; |
| 7769 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7770 | |
| 7771 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7772 | if (!nfs41_sequence_done(task, res)) |
| 7773 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7774 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7775 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7776 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7777 | rpc_restart_call_prepare(task); |
| 7778 | return; |
| 7779 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7780 | dprintk("<-- %s\n", __func__); |
| 7781 | } |
| 7782 | |
| 7783 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7784 | { |
| 7785 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7786 | |
| 7787 | kfree(calldata); |
| 7788 | } |
| 7789 | |
| 7790 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7791 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7792 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7793 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7794 | }; |
| 7795 | |
| 7796 | /* |
| 7797 | * Issue a global reclaim complete. |
| 7798 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7799 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7800 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7801 | { |
| 7802 | struct nfs4_reclaim_complete_data *calldata; |
| 7803 | struct rpc_task *task; |
| 7804 | struct rpc_message msg = { |
| 7805 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7806 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7807 | }; |
| 7808 | struct rpc_task_setup task_setup_data = { |
| 7809 | .rpc_client = clp->cl_rpcclient, |
| 7810 | .rpc_message = &msg, |
| 7811 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7812 | .flags = RPC_TASK_ASYNC, |
| 7813 | }; |
| 7814 | int status = -ENOMEM; |
| 7815 | |
| 7816 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7817 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7818 | if (calldata == NULL) |
| 7819 | goto out; |
| 7820 | calldata->clp = clp; |
| 7821 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7822 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7823 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7824 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7825 | msg.rpc_argp = &calldata->arg; |
| 7826 | msg.rpc_resp = &calldata->res; |
| 7827 | task_setup_data.callback_data = calldata; |
| 7828 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7829 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7830 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7831 | goto out; |
| 7832 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7833 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7834 | if (status == 0) |
| 7835 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7836 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7837 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7838 | out: |
| 7839 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7840 | return status; |
| 7841 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7842 | |
| 7843 | static void |
| 7844 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7845 | { |
| 7846 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7847 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7848 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7849 | |
| 7850 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7851 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 7852 | &lgp->res.seq_res, task); |
| 7853 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7854 | } |
| 7855 | |
| 7856 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7857 | { |
| 7858 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7859 | |
| 7860 | dprintk("--> %s\n", __func__); |
| 7861 | nfs41_sequence_done(task, &lgp->res.seq_res); |
| 7862 | dprintk("<-- %s\n", __func__); |
| 7863 | } |
| 7864 | |
| 7865 | static int |
| 7866 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 7867 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 7868 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7869 | struct inode *inode = lgp->args.inode; |
| 7870 | struct nfs_server *server = NFS_SERVER(inode); |
| 7871 | struct pnfs_layout_hdr *lo; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7872 | int status = task->tk_status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7873 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7874 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7875 | |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7876 | switch (status) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7877 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7878 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 7879 | |
| 7880 | /* |
| 7881 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 7882 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 7883 | * retry go inband. |
| 7884 | */ |
| 7885 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7886 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 7887 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7888 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7889 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 7890 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 7891 | */ |
| 7892 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7893 | status = -EOVERFLOW; |
| 7894 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7895 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7896 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 7897 | * (or clients) writing to the same RAID stripe except when |
| 7898 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7899 | * |
| 7900 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 7901 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7902 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7903 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7904 | if (lgp->args.minlength == 0) { |
| 7905 | status = -EOVERFLOW; |
| 7906 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7907 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7908 | /* Fallthrough */ |
| 7909 | case -NFS4ERR_RECALLCONFLICT: |
| 7910 | nfs4_handle_exception(server, -NFS4ERR_RECALLCONFLICT, |
| 7911 | exception); |
| 7912 | status = -ERECALLCONFLICT; |
| 7913 | goto out; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7914 | case -NFS4ERR_EXPIRED: |
| 7915 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7916 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7917 | spin_lock(&inode->i_lock); |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7918 | if (nfs4_stateid_match(&lgp->args.stateid, |
| 7919 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7920 | spin_unlock(&inode->i_lock); |
| 7921 | /* If the open stateid was bad, then recover it. */ |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7922 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7923 | break; |
| 7924 | } |
| 7925 | lo = NFS_I(inode)->layout; |
Trond Myklebust | dd1beb3 | 2016-06-17 16:48:21 -0400 | [diff] [blame] | 7926 | if (lo && !test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) && |
| 7927 | nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7928 | LIST_HEAD(head); |
| 7929 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7930 | /* |
| 7931 | * Mark the bad layout state as invalid, then retry |
| 7932 | * with the current stateid. |
| 7933 | */ |
Kinglong Mee | 8714d46 | 2015-09-20 23:04:22 +0800 | [diff] [blame] | 7934 | set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags); |
Jeff Layton | 6d597e1 | 2016-05-17 12:28:42 -0400 | [diff] [blame] | 7935 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL, 0); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7936 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7937 | pnfs_free_lseg_list(&head); |
Trond Myklebust | dd1beb3 | 2016-06-17 16:48:21 -0400 | [diff] [blame] | 7938 | status = -EAGAIN; |
| 7939 | goto out; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 7940 | } else |
| 7941 | spin_unlock(&inode->i_lock); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7942 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7943 | |
| 7944 | status = nfs4_handle_exception(server, status, exception); |
| 7945 | if (exception->retry) |
| 7946 | status = -EAGAIN; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7947 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7948 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 7949 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7950 | } |
| 7951 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7952 | static size_t max_response_pages(struct nfs_server *server) |
| 7953 | { |
| 7954 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7955 | return nfs_page_array_len(0, max_resp_sz); |
| 7956 | } |
| 7957 | |
| 7958 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7959 | { |
| 7960 | int i; |
| 7961 | |
| 7962 | if (!pages) |
| 7963 | return; |
| 7964 | |
| 7965 | for (i = 0; i < size; i++) { |
| 7966 | if (!pages[i]) |
| 7967 | break; |
| 7968 | __free_page(pages[i]); |
| 7969 | } |
| 7970 | kfree(pages); |
| 7971 | } |
| 7972 | |
| 7973 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7974 | { |
| 7975 | struct page **pages; |
| 7976 | int i; |
| 7977 | |
| 7978 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7979 | if (!pages) { |
| 7980 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7981 | return NULL; |
| 7982 | } |
| 7983 | |
| 7984 | for (i = 0; i < size; i++) { |
| 7985 | pages[i] = alloc_page(gfp_flags); |
| 7986 | if (!pages[i]) { |
| 7987 | dprintk("%s: failed to allocate page\n", __func__); |
| 7988 | nfs4_free_pages(pages, size); |
| 7989 | return NULL; |
| 7990 | } |
| 7991 | } |
| 7992 | |
| 7993 | return pages; |
| 7994 | } |
| 7995 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7996 | static void nfs4_layoutget_release(void *calldata) |
| 7997 | { |
| 7998 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7999 | struct inode *inode = lgp->args.inode; |
| 8000 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8001 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8002 | |
| 8003 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8004 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8005 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8006 | put_nfs_open_context(lgp->args.ctx); |
| 8007 | kfree(calldata); |
| 8008 | dprintk("<-- %s\n", __func__); |
| 8009 | } |
| 8010 | |
| 8011 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8012 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8013 | .rpc_call_done = nfs4_layoutget_done, |
| 8014 | .rpc_release = nfs4_layoutget_release, |
| 8015 | }; |
| 8016 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8017 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8018 | 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] | 8019 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8020 | struct inode *inode = lgp->args.inode; |
| 8021 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8022 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8023 | struct rpc_task *task; |
| 8024 | struct rpc_message msg = { |
| 8025 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8026 | .rpc_argp = &lgp->args, |
| 8027 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8028 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8029 | }; |
| 8030 | struct rpc_task_setup task_setup_data = { |
| 8031 | .rpc_client = server->client, |
| 8032 | .rpc_message = &msg, |
| 8033 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8034 | .callback_data = lgp, |
| 8035 | .flags = RPC_TASK_ASYNC, |
| 8036 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8037 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8038 | struct nfs4_exception exception = { |
| 8039 | .inode = inode, |
| 8040 | .timeout = *timeout, |
| 8041 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8042 | int status = 0; |
| 8043 | |
| 8044 | dprintk("--> %s\n", __func__); |
| 8045 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8046 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8047 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8048 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8049 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8050 | if (!lgp->args.layout.pages) { |
| 8051 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8052 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8053 | } |
| 8054 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8055 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8056 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8057 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8058 | 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] | 8059 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8060 | task = rpc_run_task(&task_setup_data); |
| 8061 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8062 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8063 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8064 | if (status == 0) { |
| 8065 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8066 | *timeout = exception.timeout; |
| 8067 | } |
| 8068 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8069 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8070 | &lgp->args.range, |
| 8071 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8072 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8073 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8074 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8075 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8076 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8077 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8078 | rpc_put_task(task); |
| 8079 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8080 | if (status) |
| 8081 | return ERR_PTR(status); |
| 8082 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8083 | } |
| 8084 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8085 | static void |
| 8086 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8087 | { |
| 8088 | struct nfs4_layoutreturn *lrp = calldata; |
| 8089 | |
| 8090 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8091 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8092 | &lrp->args.seq_args, |
| 8093 | &lrp->res.seq_res, |
| 8094 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8095 | } |
| 8096 | |
| 8097 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8098 | { |
| 8099 | struct nfs4_layoutreturn *lrp = calldata; |
| 8100 | struct nfs_server *server; |
| 8101 | |
| 8102 | dprintk("--> %s\n", __func__); |
| 8103 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8104 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8105 | return; |
| 8106 | |
| 8107 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8108 | switch (task->tk_status) { |
| 8109 | default: |
| 8110 | task->tk_status = 0; |
| 8111 | case 0: |
| 8112 | break; |
| 8113 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8114 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8115 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8116 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8117 | return; |
| 8118 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8119 | dprintk("<-- %s\n", __func__); |
| 8120 | } |
| 8121 | |
| 8122 | static void nfs4_layoutreturn_release(void *calldata) |
| 8123 | { |
| 8124 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8125 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8126 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8127 | |
| 8128 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8129 | spin_lock(&lo->plh_inode->i_lock); |
Jeff Layton | 6d597e1 | 2016-05-17 12:28:42 -0400 | [diff] [blame] | 8130 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, &lrp->args.range, |
| 8131 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 0654cc7 | 2015-12-28 11:48:14 -0500 | [diff] [blame] | 8132 | pnfs_mark_layout_returned_if_empty(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8133 | if (lrp->res.lrs_present) |
| 8134 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8135 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8136 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8137 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8138 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8139 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8140 | kfree(calldata); |
| 8141 | dprintk("<-- %s\n", __func__); |
| 8142 | } |
| 8143 | |
| 8144 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8145 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8146 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8147 | .rpc_release = nfs4_layoutreturn_release, |
| 8148 | }; |
| 8149 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8150 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8151 | { |
| 8152 | struct rpc_task *task; |
| 8153 | struct rpc_message msg = { |
| 8154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8155 | .rpc_argp = &lrp->args, |
| 8156 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8157 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8158 | }; |
| 8159 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8160 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8161 | .rpc_message = &msg, |
| 8162 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8163 | .callback_data = lrp, |
| 8164 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8165 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8166 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8167 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8168 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8169 | &task_setup_data.rpc_client, &msg); |
| 8170 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8171 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8172 | if (!sync) { |
| 8173 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8174 | if (!lrp->inode) { |
| 8175 | nfs4_layoutreturn_release(lrp); |
| 8176 | return -EAGAIN; |
| 8177 | } |
| 8178 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8179 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8180 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8181 | task = rpc_run_task(&task_setup_data); |
| 8182 | if (IS_ERR(task)) |
| 8183 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8184 | if (sync) |
| 8185 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8186 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8187 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8188 | rpc_put_task(task); |
| 8189 | return status; |
| 8190 | } |
| 8191 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8192 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8193 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8194 | struct pnfs_device *pdev, |
| 8195 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8196 | { |
| 8197 | struct nfs4_getdeviceinfo_args args = { |
| 8198 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8199 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8200 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8201 | }; |
| 8202 | struct nfs4_getdeviceinfo_res res = { |
| 8203 | .pdev = pdev, |
| 8204 | }; |
| 8205 | struct rpc_message msg = { |
| 8206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8207 | .rpc_argp = &args, |
| 8208 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8209 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8210 | }; |
| 8211 | int status; |
| 8212 | |
| 8213 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8214 | 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] | 8215 | if (res.notification & ~args.notify_types) |
| 8216 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8217 | if (res.notification != args.notify_types) |
| 8218 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8219 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8220 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8221 | |
| 8222 | return status; |
| 8223 | } |
| 8224 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8225 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8226 | struct pnfs_device *pdev, |
| 8227 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8228 | { |
| 8229 | struct nfs4_exception exception = { }; |
| 8230 | int err; |
| 8231 | |
| 8232 | do { |
| 8233 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8234 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8235 | &exception); |
| 8236 | } while (exception.retry); |
| 8237 | return err; |
| 8238 | } |
| 8239 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8240 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8241 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8242 | { |
| 8243 | struct nfs4_layoutcommit_data *data = calldata; |
| 8244 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8245 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8246 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8247 | nfs41_setup_sequence(session, |
| 8248 | &data->args.seq_args, |
| 8249 | &data->res.seq_res, |
| 8250 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | static void |
| 8254 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8255 | { |
| 8256 | struct nfs4_layoutcommit_data *data = calldata; |
| 8257 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8258 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8259 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8260 | return; |
| 8261 | |
| 8262 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8263 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8264 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8265 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8266 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8267 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8268 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8269 | break; |
| 8270 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8271 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8272 | rpc_restart_call_prepare(task); |
| 8273 | return; |
| 8274 | } |
| 8275 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8276 | } |
| 8277 | |
| 8278 | static void nfs4_layoutcommit_release(void *calldata) |
| 8279 | { |
| 8280 | struct nfs4_layoutcommit_data *data = calldata; |
| 8281 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8282 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8283 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8284 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8285 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8286 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8287 | kfree(data); |
| 8288 | } |
| 8289 | |
| 8290 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8291 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8292 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8293 | .rpc_release = nfs4_layoutcommit_release, |
| 8294 | }; |
| 8295 | |
| 8296 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8297 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8298 | { |
| 8299 | struct rpc_message msg = { |
| 8300 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8301 | .rpc_argp = &data->args, |
| 8302 | .rpc_resp = &data->res, |
| 8303 | .rpc_cred = data->cred, |
| 8304 | }; |
| 8305 | struct rpc_task_setup task_setup_data = { |
| 8306 | .task = &data->task, |
| 8307 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8308 | .rpc_message = &msg, |
| 8309 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8310 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8311 | }; |
| 8312 | struct rpc_task *task; |
| 8313 | int status = 0; |
| 8314 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8315 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8316 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8317 | data->args.lastbytewritten, |
| 8318 | data->args.inode->i_ino); |
| 8319 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8320 | if (!sync) { |
| 8321 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8322 | if (data->inode == NULL) { |
| 8323 | nfs4_layoutcommit_release(data); |
| 8324 | return -EAGAIN; |
| 8325 | } |
| 8326 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8327 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8328 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8329 | task = rpc_run_task(&task_setup_data); |
| 8330 | if (IS_ERR(task)) |
| 8331 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8332 | if (sync) |
| 8333 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8334 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8335 | dprintk("%s: status %d\n", __func__, status); |
| 8336 | rpc_put_task(task); |
| 8337 | return status; |
| 8338 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8339 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8340 | /** |
| 8341 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8342 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8343 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8344 | static int |
| 8345 | _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] | 8346 | struct nfs_fsinfo *info, |
| 8347 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8348 | { |
| 8349 | struct nfs41_secinfo_no_name_args args = { |
| 8350 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8351 | }; |
| 8352 | struct nfs4_secinfo_res res = { |
| 8353 | .flavors = flavors, |
| 8354 | }; |
| 8355 | struct rpc_message msg = { |
| 8356 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8357 | .rpc_argp = &args, |
| 8358 | .rpc_resp = &res, |
| 8359 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8360 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8361 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8362 | int status; |
| 8363 | |
| 8364 | if (use_integrity) { |
| 8365 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8366 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8367 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8368 | } |
| 8369 | |
| 8370 | dprintk("--> %s\n", __func__); |
| 8371 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8372 | &res.seq_res, 0); |
| 8373 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8374 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8375 | if (cred) |
| 8376 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8377 | |
| 8378 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8379 | } |
| 8380 | |
| 8381 | static int |
| 8382 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8383 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8384 | { |
| 8385 | struct nfs4_exception exception = { }; |
| 8386 | int err; |
| 8387 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8388 | /* first try using integrity protection */ |
| 8389 | err = -NFS4ERR_WRONGSEC; |
| 8390 | |
| 8391 | /* try to use integrity protection with machine cred */ |
| 8392 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8393 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8394 | flavors, true); |
| 8395 | |
| 8396 | /* |
| 8397 | * if unable to use integrity protection, or SECINFO with |
| 8398 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8399 | * disallowed by spec, but exists in deployed servers) use |
| 8400 | * the current filesystem's rpc_client and the user cred. |
| 8401 | */ |
| 8402 | if (err == -NFS4ERR_WRONGSEC) |
| 8403 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8404 | flavors, false); |
| 8405 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8406 | switch (err) { |
| 8407 | case 0: |
| 8408 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8409 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8410 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8411 | default: |
| 8412 | err = nfs4_handle_exception(server, err, &exception); |
| 8413 | } |
| 8414 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8415 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8416 | return err; |
| 8417 | } |
| 8418 | |
| 8419 | static int |
| 8420 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8421 | struct nfs_fsinfo *info) |
| 8422 | { |
| 8423 | int err; |
| 8424 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8425 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8426 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8427 | struct nfs4_secinfo4 *secinfo; |
| 8428 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8429 | |
| 8430 | page = alloc_page(GFP_KERNEL); |
| 8431 | if (!page) { |
| 8432 | err = -ENOMEM; |
| 8433 | goto out; |
| 8434 | } |
| 8435 | |
| 8436 | flavors = page_address(page); |
| 8437 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8438 | |
| 8439 | /* |
| 8440 | * Fall back on "guess and check" method if |
| 8441 | * the server doesn't support SECINFO_NO_NAME |
| 8442 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8443 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8444 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8445 | goto out_freepage; |
| 8446 | } |
| 8447 | if (err) |
| 8448 | goto out_freepage; |
| 8449 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8450 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8451 | secinfo = &flavors->flavors[i]; |
| 8452 | |
| 8453 | switch (secinfo->flavor) { |
| 8454 | case RPC_AUTH_NULL: |
| 8455 | case RPC_AUTH_UNIX: |
| 8456 | case RPC_AUTH_GSS: |
| 8457 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8458 | &secinfo->flavor_info); |
| 8459 | break; |
| 8460 | default: |
| 8461 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8462 | break; |
| 8463 | } |
| 8464 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8465 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8466 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8467 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8468 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8469 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8470 | info, flavor); |
| 8471 | if (!err) |
| 8472 | break; |
| 8473 | } |
| 8474 | } |
| 8475 | |
| 8476 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8477 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8478 | |
| 8479 | out_freepage: |
| 8480 | put_page(page); |
| 8481 | if (err == -EACCES) |
| 8482 | return -EPERM; |
| 8483 | out: |
| 8484 | return err; |
| 8485 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8486 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8487 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8488 | nfs4_stateid *stateid, |
| 8489 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8490 | { |
| 8491 | int status; |
| 8492 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8493 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8494 | }; |
| 8495 | struct nfs41_test_stateid_res res; |
| 8496 | struct rpc_message msg = { |
| 8497 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8498 | .rpc_argp = &args, |
| 8499 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8500 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8501 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8502 | struct rpc_clnt *rpc_client = server->client; |
| 8503 | |
| 8504 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8505 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8506 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8507 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8508 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8509 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8510 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8511 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8512 | if (status != NFS_OK) { |
| 8513 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8514 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8515 | } |
| 8516 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8517 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8518 | } |
| 8519 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8520 | /** |
| 8521 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8522 | * |
| 8523 | * @server: server / transport on which to perform the operation |
| 8524 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8525 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8526 | * |
| 8527 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8528 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8529 | * failed or the state ID is not currently valid. |
| 8530 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8531 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8532 | nfs4_stateid *stateid, |
| 8533 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8534 | { |
| 8535 | struct nfs4_exception exception = { }; |
| 8536 | int err; |
| 8537 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8538 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8539 | if (err != -NFS4ERR_DELAY) |
| 8540 | break; |
| 8541 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8542 | } while (exception.retry); |
| 8543 | return err; |
| 8544 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8545 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8546 | struct nfs_free_stateid_data { |
| 8547 | struct nfs_server *server; |
| 8548 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8549 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8550 | }; |
| 8551 | |
| 8552 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8553 | { |
| 8554 | struct nfs_free_stateid_data *data = calldata; |
| 8555 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8556 | &data->args.seq_args, |
| 8557 | &data->res.seq_res, |
| 8558 | task); |
| 8559 | } |
| 8560 | |
| 8561 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8562 | { |
| 8563 | struct nfs_free_stateid_data *data = calldata; |
| 8564 | |
| 8565 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8566 | |
| 8567 | switch (task->tk_status) { |
| 8568 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8569 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8570 | rpc_restart_call_prepare(task); |
| 8571 | } |
| 8572 | } |
| 8573 | |
| 8574 | static void nfs41_free_stateid_release(void *calldata) |
| 8575 | { |
| 8576 | kfree(calldata); |
| 8577 | } |
| 8578 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8579 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8580 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8581 | .rpc_call_done = nfs41_free_stateid_done, |
| 8582 | .rpc_release = nfs41_free_stateid_release, |
| 8583 | }; |
| 8584 | |
| 8585 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8586 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8587 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8588 | bool privileged) |
| 8589 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8590 | struct rpc_message msg = { |
| 8591 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8592 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8593 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8594 | struct rpc_task_setup task_setup = { |
| 8595 | .rpc_client = server->client, |
| 8596 | .rpc_message = &msg, |
| 8597 | .callback_ops = &nfs41_free_stateid_ops, |
| 8598 | .flags = RPC_TASK_ASYNC, |
| 8599 | }; |
| 8600 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8601 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8602 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8603 | &task_setup.rpc_client, &msg); |
| 8604 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8605 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8606 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8607 | if (!data) |
| 8608 | return ERR_PTR(-ENOMEM); |
| 8609 | data->server = server; |
| 8610 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8611 | |
| 8612 | task_setup.callback_data = data; |
| 8613 | |
| 8614 | msg.rpc_argp = &data->args; |
| 8615 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8616 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8617 | if (privileged) |
| 8618 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8619 | |
| 8620 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8621 | } |
| 8622 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8623 | /** |
| 8624 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8625 | * |
| 8626 | * @server: server / transport on which to perform the operation |
| 8627 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8628 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8629 | * |
| 8630 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8631 | * negative NFS4ERR value is returned. |
| 8632 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8633 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8634 | nfs4_stateid *stateid, |
| 8635 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8636 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8637 | struct rpc_task *task; |
| 8638 | int ret; |
| 8639 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8640 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8641 | if (IS_ERR(task)) |
| 8642 | return PTR_ERR(task); |
| 8643 | ret = rpc_wait_for_completion_task(task); |
| 8644 | if (!ret) |
| 8645 | ret = task->tk_status; |
| 8646 | rpc_put_task(task); |
| 8647 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8648 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8649 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8650 | static void |
| 8651 | 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] | 8652 | { |
| 8653 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8654 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8655 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8656 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8657 | nfs4_free_lock_state(server, lsp); |
| 8658 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8659 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8660 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8661 | } |
| 8662 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8663 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8664 | const nfs4_stateid *s2) |
| 8665 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 8666 | if (s1->type != s2->type) |
| 8667 | return false; |
| 8668 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8669 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8670 | return false; |
| 8671 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8672 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8673 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8674 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8675 | return true; |
| 8676 | |
| 8677 | return false; |
| 8678 | } |
| 8679 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8680 | #endif /* CONFIG_NFS_V4_1 */ |
| 8681 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8682 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8683 | const nfs4_stateid *s2) |
| 8684 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8685 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8686 | } |
| 8687 | |
| 8688 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8689 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8690 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8691 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8692 | .recover_open = nfs4_open_reclaim, |
| 8693 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8694 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8695 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8696 | }; |
| 8697 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8698 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8699 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8700 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8701 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8702 | .recover_open = nfs4_open_reclaim, |
| 8703 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8704 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8705 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8706 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8707 | }; |
| 8708 | #endif /* CONFIG_NFS_V4_1 */ |
| 8709 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8710 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8711 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8712 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8713 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8714 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8715 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8716 | }; |
| 8717 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8718 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8719 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8720 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8721 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8722 | .recover_open = nfs41_open_expired, |
| 8723 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8724 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8725 | }; |
| 8726 | #endif /* CONFIG_NFS_V4_1 */ |
| 8727 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8728 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8729 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8730 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8731 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8732 | }; |
| 8733 | |
| 8734 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8735 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8736 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8737 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8738 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8739 | }; |
| 8740 | #endif |
| 8741 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8742 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8743 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8744 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8745 | }; |
| 8746 | |
| 8747 | #if defined(CONFIG_NFS_V4_1) |
| 8748 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8749 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8750 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8751 | }; |
| 8752 | #endif /* CONFIG_NFS_V4_1 */ |
| 8753 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8754 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8755 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8756 | .init_caps = NFS_CAP_READDIRPLUS |
| 8757 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8758 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8759 | .init_client = nfs40_init_client, |
| 8760 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8761 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8762 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8763 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8764 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8765 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8766 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8767 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8768 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8769 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8770 | }; |
| 8771 | |
| 8772 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8773 | static struct nfs_seqid * |
| 8774 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 8775 | { |
| 8776 | return NULL; |
| 8777 | } |
| 8778 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8779 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8780 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8781 | .init_caps = NFS_CAP_READDIRPLUS |
| 8782 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8783 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8784 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8785 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8786 | .init_client = nfs41_init_client, |
| 8787 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8788 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8789 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8790 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8791 | .alloc_seqid = nfs_alloc_no_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8792 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8793 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8794 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8795 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8796 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8797 | }; |
| 8798 | #endif |
| 8799 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8800 | #if defined(CONFIG_NFS_V4_2) |
| 8801 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8802 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8803 | .init_caps = NFS_CAP_READDIRPLUS |
| 8804 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8805 | | NFS_CAP_POSIX_LOCK |
| 8806 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8807 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 8808 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 8809 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 8810 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 8811 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 8812 | | NFS_CAP_LAYOUTSTATS |
| 8813 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8814 | .init_client = nfs41_init_client, |
| 8815 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8816 | .match_stateid = nfs41_match_stateid, |
| 8817 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8818 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8819 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8820 | .alloc_seqid = nfs_alloc_no_seqid, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8821 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8822 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8823 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 8824 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8825 | }; |
| 8826 | #endif |
| 8827 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8828 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8829 | [0] = &nfs_v4_0_minor_ops, |
| 8830 | #if defined(CONFIG_NFS_V4_1) |
| 8831 | [1] = &nfs_v4_1_minor_ops, |
| 8832 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8833 | #if defined(CONFIG_NFS_V4_2) |
| 8834 | [2] = &nfs_v4_2_minor_ops, |
| 8835 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8836 | }; |
| 8837 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 8838 | ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) |
| 8839 | { |
| 8840 | ssize_t error, error2; |
| 8841 | |
| 8842 | error = generic_listxattr(dentry, list, size); |
| 8843 | if (error < 0) |
| 8844 | return error; |
| 8845 | if (list) { |
| 8846 | list += error; |
| 8847 | size -= error; |
| 8848 | } |
| 8849 | |
| 8850 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 8851 | if (error2 < 0) |
| 8852 | return error2; |
| 8853 | return error + error2; |
| 8854 | } |
| 8855 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8856 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8857 | .create = nfs_create, |
| 8858 | .lookup = nfs_lookup, |
| 8859 | .atomic_open = nfs_atomic_open, |
| 8860 | .link = nfs_link, |
| 8861 | .unlink = nfs_unlink, |
| 8862 | .symlink = nfs_symlink, |
| 8863 | .mkdir = nfs_mkdir, |
| 8864 | .rmdir = nfs_rmdir, |
| 8865 | .mknod = nfs_mknod, |
| 8866 | .rename = nfs_rename, |
| 8867 | .permission = nfs_permission, |
| 8868 | .getattr = nfs_getattr, |
| 8869 | .setattr = nfs_setattr, |
| 8870 | .getxattr = generic_getxattr, |
| 8871 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 8872 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8873 | .removexattr = generic_removexattr, |
| 8874 | }; |
| 8875 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8876 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8877 | .permission = nfs_permission, |
| 8878 | .getattr = nfs_getattr, |
| 8879 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8880 | .getxattr = generic_getxattr, |
| 8881 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 8882 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8883 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8884 | }; |
| 8885 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8886 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8887 | .version = 4, /* protocol version */ |
| 8888 | .dentry_ops = &nfs4_dentry_operations, |
| 8889 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8890 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8891 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8892 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8893 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8894 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8895 | .getattr = nfs4_proc_getattr, |
| 8896 | .setattr = nfs4_proc_setattr, |
| 8897 | .lookup = nfs4_proc_lookup, |
| 8898 | .access = nfs4_proc_access, |
| 8899 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8900 | .create = nfs4_proc_create, |
| 8901 | .remove = nfs4_proc_remove, |
| 8902 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8903 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8904 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8905 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8906 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8907 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8908 | .link = nfs4_proc_link, |
| 8909 | .symlink = nfs4_proc_symlink, |
| 8910 | .mkdir = nfs4_proc_mkdir, |
| 8911 | .rmdir = nfs4_proc_remove, |
| 8912 | .readdir = nfs4_proc_readdir, |
| 8913 | .mknod = nfs4_proc_mknod, |
| 8914 | .statfs = nfs4_proc_statfs, |
| 8915 | .fsinfo = nfs4_proc_fsinfo, |
| 8916 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8917 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8918 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8919 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8920 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8921 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8922 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8923 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8924 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8925 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8926 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8927 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8928 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8929 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8930 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8931 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8932 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8933 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8934 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8935 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8936 | .create_server = nfs4_create_server, |
| 8937 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8938 | }; |
| 8939 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8940 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 8941 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8942 | .list = nfs4_xattr_list_nfs4_acl, |
| 8943 | .get = nfs4_xattr_get_nfs4_acl, |
| 8944 | .set = nfs4_xattr_set_nfs4_acl, |
| 8945 | }; |
| 8946 | |
| 8947 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8948 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8949 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8950 | &nfs4_xattr_nfs4_label_handler, |
| 8951 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8952 | NULL |
| 8953 | }; |
| 8954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8955 | /* |
| 8956 | * Local variables: |
| 8957 | * c-basic-offset: 8 |
| 8958 | * End: |
| 8959 | */ |