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 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 81 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *, long *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 82 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 83 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 84 | 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] | 85 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 86 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 87 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 88 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 90 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 91 | struct rpc_cred *); |
| 92 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 93 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 94 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 97 | static inline struct nfs4_label * |
| 98 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 99 | struct iattr *sattr, struct nfs4_label *label) |
| 100 | { |
| 101 | int err; |
| 102 | |
| 103 | if (label == NULL) |
| 104 | return NULL; |
| 105 | |
| 106 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 107 | return NULL; |
| 108 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 109 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 110 | &dentry->d_name, (void **)&label->label, &label->len); |
| 111 | if (err == 0) |
| 112 | return label; |
| 113 | |
| 114 | return NULL; |
| 115 | } |
| 116 | static inline void |
| 117 | nfs4_label_release_security(struct nfs4_label *label) |
| 118 | { |
| 119 | if (label) |
| 120 | security_release_secctx(label->label, label->len); |
| 121 | } |
| 122 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 123 | { |
| 124 | if (label) |
| 125 | return server->attr_bitmask; |
| 126 | |
| 127 | return server->attr_bitmask_nl; |
| 128 | } |
| 129 | #else |
| 130 | static inline struct nfs4_label * |
| 131 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 132 | struct iattr *sattr, struct nfs4_label *l) |
| 133 | { return NULL; } |
| 134 | static inline void |
| 135 | nfs4_label_release_security(struct nfs4_label *label) |
| 136 | { return; } |
| 137 | static inline u32 * |
| 138 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 139 | { return server->attr_bitmask; } |
| 140 | #endif |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 143 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 145 | if (err >= -1000) |
| 146 | return err; |
| 147 | switch (err) { |
| 148 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 149 | case -NFS4ERR_LAYOUTTRYLATER: |
| 150 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 151 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 152 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 153 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 155 | case -NFS4ERR_BADOWNER: |
| 156 | case -NFS4ERR_BADNAME: |
| 157 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 158 | case -NFS4ERR_SHARE_DENIED: |
| 159 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 160 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 161 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 162 | case -NFS4ERR_FILE_OPEN: |
| 163 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 164 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 166 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 167 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 169 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* |
| 173 | * This is our standard bitmap for GETATTR requests. |
| 174 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 175 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | FATTR4_WORD0_TYPE |
| 177 | | FATTR4_WORD0_CHANGE |
| 178 | | FATTR4_WORD0_SIZE |
| 179 | | FATTR4_WORD0_FSID |
| 180 | | FATTR4_WORD0_FILEID, |
| 181 | FATTR4_WORD1_MODE |
| 182 | | FATTR4_WORD1_NUMLINKS |
| 183 | | FATTR4_WORD1_OWNER |
| 184 | | FATTR4_WORD1_OWNER_GROUP |
| 185 | | FATTR4_WORD1_RAWDEV |
| 186 | | FATTR4_WORD1_SPACE_USED |
| 187 | | FATTR4_WORD1_TIME_ACCESS |
| 188 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 189 | | FATTR4_WORD1_TIME_MODIFY |
| 190 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 191 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 192 | FATTR4_WORD2_SECURITY_LABEL |
| 193 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 196 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 197 | FATTR4_WORD0_TYPE |
| 198 | | FATTR4_WORD0_CHANGE |
| 199 | | FATTR4_WORD0_SIZE |
| 200 | | FATTR4_WORD0_FSID |
| 201 | | FATTR4_WORD0_FILEID, |
| 202 | FATTR4_WORD1_MODE |
| 203 | | FATTR4_WORD1_NUMLINKS |
| 204 | | FATTR4_WORD1_OWNER |
| 205 | | FATTR4_WORD1_OWNER_GROUP |
| 206 | | FATTR4_WORD1_RAWDEV |
| 207 | | FATTR4_WORD1_SPACE_USED |
| 208 | | FATTR4_WORD1_TIME_ACCESS |
| 209 | | FATTR4_WORD1_TIME_METADATA |
| 210 | | FATTR4_WORD1_TIME_MODIFY, |
| 211 | FATTR4_WORD2_MDSTHRESHOLD |
| 212 | }; |
| 213 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 214 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 215 | FATTR4_WORD0_TYPE |
| 216 | | FATTR4_WORD0_CHANGE |
| 217 | | FATTR4_WORD0_FILEID, |
| 218 | }; |
| 219 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 220 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | FATTR4_WORD0_FILES_AVAIL |
| 222 | | FATTR4_WORD0_FILES_FREE |
| 223 | | FATTR4_WORD0_FILES_TOTAL, |
| 224 | FATTR4_WORD1_SPACE_AVAIL |
| 225 | | FATTR4_WORD1_SPACE_FREE |
| 226 | | FATTR4_WORD1_SPACE_TOTAL |
| 227 | }; |
| 228 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 229 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | FATTR4_WORD0_MAXLINK |
| 231 | | FATTR4_WORD0_MAXNAME, |
| 232 | 0 |
| 233 | }; |
| 234 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 235 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | | FATTR4_WORD0_MAXREAD |
| 237 | | FATTR4_WORD0_MAXWRITE |
| 238 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 239 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 240 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 241 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 245 | FATTR4_WORD0_TYPE |
| 246 | | FATTR4_WORD0_CHANGE |
| 247 | | FATTR4_WORD0_SIZE |
| 248 | | FATTR4_WORD0_FSID |
| 249 | | FATTR4_WORD0_FILEID |
| 250 | | FATTR4_WORD0_FS_LOCATIONS, |
| 251 | FATTR4_WORD1_MODE |
| 252 | | FATTR4_WORD1_NUMLINKS |
| 253 | | FATTR4_WORD1_OWNER |
| 254 | | FATTR4_WORD1_OWNER_GROUP |
| 255 | | FATTR4_WORD1_RAWDEV |
| 256 | | FATTR4_WORD1_SPACE_USED |
| 257 | | FATTR4_WORD1_TIME_ACCESS |
| 258 | | FATTR4_WORD1_TIME_METADATA |
| 259 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 260 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 261 | }; |
| 262 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 263 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | struct nfs4_readdir_arg *readdir) |
| 265 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 266 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 269 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | readdir->cookie = 0; |
| 275 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 276 | if (cookie == 2) |
| 277 | return; |
| 278 | |
| 279 | /* |
| 280 | * NFSv4 servers do not return entries for '.' and '..' |
| 281 | * Therefore, we fake these entries here. We let '.' |
| 282 | * have cookie 0 and '..' have cookie 1. Note that |
| 283 | * when talking to the server, we always send cookie 0 |
| 284 | * instead of 1 or 2. |
| 285 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 286 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (cookie == 0) { |
| 289 | *p++ = xdr_one; /* next */ |
| 290 | *p++ = xdr_zero; /* cookie, first word */ |
| 291 | *p++ = xdr_one; /* cookie, second word */ |
| 292 | *p++ = xdr_one; /* entry len */ |
| 293 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 294 | p++; |
| 295 | *p++ = xdr_one; /* bitmap length */ |
| 296 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 297 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 298 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_two; /* cookie, second word */ |
| 304 | *p++ = xdr_two; /* entry len */ |
| 305 | memcpy(p, "..\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | readdir->pgbase = (char *)p - (char *)start; |
| 313 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 314 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 317 | static long nfs4_update_delay(long *timeout) |
| 318 | { |
| 319 | long ret; |
| 320 | if (!timeout) |
| 321 | return NFS4_POLL_RETRY_MAX; |
| 322 | if (*timeout <= 0) |
| 323 | *timeout = NFS4_POLL_RETRY_MIN; |
| 324 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 325 | *timeout = NFS4_POLL_RETRY_MAX; |
| 326 | ret = *timeout; |
| 327 | *timeout <<= 1; |
| 328 | return ret; |
| 329 | } |
| 330 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 331 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 332 | { |
| 333 | int res = 0; |
| 334 | |
| 335 | might_sleep(); |
| 336 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 337 | freezable_schedule_timeout_killable_unsafe( |
| 338 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 339 | if (fatal_signal_pending(current)) |
| 340 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | return res; |
| 342 | } |
| 343 | |
| 344 | /* This is the error handling routine for processes that are allowed |
| 345 | * to sleep. |
| 346 | */ |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 347 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 348 | { |
| 349 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 350 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 351 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 352 | int ret = errorcode; |
| 353 | |
| 354 | exception->retry = 0; |
| 355 | switch(errorcode) { |
| 356 | case 0: |
| 357 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 358 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 359 | case -NFS4ERR_DELEG_REVOKED: |
| 360 | case -NFS4ERR_ADMIN_REVOKED: |
| 361 | case -NFS4ERR_BAD_STATEID: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 362 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 363 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 364 | exception->retry = 1; |
| 365 | return 0; |
| 366 | } |
| 367 | if (state == NULL) |
| 368 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 369 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 370 | if (ret < 0) |
| 371 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 372 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 373 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 374 | if (state != NULL) { |
| 375 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 376 | if (ret < 0) |
| 377 | break; |
| 378 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 379 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 380 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 381 | nfs4_schedule_lease_recovery(clp); |
| 382 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 383 | case -NFS4ERR_MOVED: |
| 384 | ret = nfs4_schedule_migration_recovery(server); |
| 385 | if (ret < 0) |
| 386 | break; |
| 387 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 388 | case -NFS4ERR_LEASE_MOVED: |
| 389 | nfs4_schedule_lease_moved_recovery(clp); |
| 390 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 391 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 392 | case -NFS4ERR_BADSESSION: |
| 393 | case -NFS4ERR_BADSLOT: |
| 394 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 395 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 396 | case -NFS4ERR_DEADSESSION: |
| 397 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 398 | case -NFS4ERR_SEQ_MISORDERED: |
| 399 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 400 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 401 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 402 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 403 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 405 | if (exception->timeout > HZ) { |
| 406 | /* We have retried a decent amount, time to |
| 407 | * fail |
| 408 | */ |
| 409 | ret = -EBUSY; |
| 410 | break; |
| 411 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 412 | case -NFS4ERR_GRACE: |
| 413 | case -NFS4ERR_DELAY: |
| 414 | ret = nfs4_delay(server->client, &exception->timeout); |
| 415 | if (ret != 0) |
| 416 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 417 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 418 | case -NFS4ERR_OLD_STATEID: |
| 419 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 420 | break; |
| 421 | case -NFS4ERR_BADOWNER: |
| 422 | /* The following works around a Linux server bug! */ |
| 423 | case -NFS4ERR_BADNAME: |
| 424 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 425 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 426 | exception->retry = 1; |
| 427 | printk(KERN_WARNING "NFS: v4 server %s " |
| 428 | "does not accept raw " |
| 429 | "uid/gids. " |
| 430 | "Reenabling the idmapper.\n", |
| 431 | server->nfs_client->cl_hostname); |
| 432 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 433 | } |
| 434 | /* We failed to handle the error */ |
| 435 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 436 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 437 | ret = nfs4_wait_clnt_recover(clp); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 438 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 439 | return -EIO; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 440 | if (ret == 0) |
| 441 | exception->retry = 1; |
| 442 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 443 | } |
| 444 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 445 | /* |
| 446 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 447 | * or 'false' otherwise. |
| 448 | */ |
| 449 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 450 | { |
| 451 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 452 | |
| 453 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 454 | flavor == RPC_AUTH_GSS_KRB5P) |
| 455 | return true; |
| 456 | |
| 457 | return false; |
| 458 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 459 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | spin_lock(&clp->cl_lock); |
| 463 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 464 | clp->cl_last_renewal = timestamp; |
| 465 | spin_unlock(&clp->cl_lock); |
| 466 | } |
| 467 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 469 | { |
| 470 | do_renew_lease(server->nfs_client, timestamp); |
| 471 | } |
| 472 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 473 | struct nfs4_call_sync_data { |
| 474 | const struct nfs_server *seq_server; |
| 475 | struct nfs4_sequence_args *seq_args; |
| 476 | struct nfs4_sequence_res *seq_res; |
| 477 | }; |
| 478 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 479 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 480 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 481 | { |
| 482 | args->sa_slot = NULL; |
| 483 | args->sa_cache_this = cache_reply; |
| 484 | args->sa_privileged = 0; |
| 485 | |
| 486 | res->sr_slot = NULL; |
| 487 | } |
| 488 | |
| 489 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 490 | { |
| 491 | args->sa_privileged = 1; |
| 492 | } |
| 493 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 494 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 495 | struct nfs4_sequence_args *args, |
| 496 | struct nfs4_sequence_res *res, |
| 497 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 498 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 499 | struct nfs4_slot *slot; |
| 500 | |
| 501 | /* slot already allocated? */ |
| 502 | if (res->sr_slot != NULL) |
| 503 | goto out_start; |
| 504 | |
| 505 | spin_lock(&tbl->slot_tbl_lock); |
| 506 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 507 | goto out_sleep; |
| 508 | |
| 509 | slot = nfs4_alloc_slot(tbl); |
| 510 | if (IS_ERR(slot)) { |
| 511 | if (slot == ERR_PTR(-ENOMEM)) |
| 512 | task->tk_timeout = HZ >> 2; |
| 513 | goto out_sleep; |
| 514 | } |
| 515 | spin_unlock(&tbl->slot_tbl_lock); |
| 516 | |
| 517 | args->sa_slot = slot; |
| 518 | res->sr_slot = slot; |
| 519 | |
| 520 | out_start: |
| 521 | rpc_call_start(task); |
| 522 | return 0; |
| 523 | |
| 524 | out_sleep: |
| 525 | if (args->sa_privileged) |
| 526 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 527 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 528 | else |
| 529 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 530 | spin_unlock(&tbl->slot_tbl_lock); |
| 531 | return -EAGAIN; |
| 532 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 533 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 534 | |
| 535 | static int nfs40_sequence_done(struct rpc_task *task, |
| 536 | struct nfs4_sequence_res *res) |
| 537 | { |
| 538 | struct nfs4_slot *slot = res->sr_slot; |
| 539 | struct nfs4_slot_table *tbl; |
| 540 | |
Trond Myklebust | cab92c1 | 2014-01-29 12:12:15 -0500 | [diff] [blame] | 541 | if (slot == NULL) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 542 | goto out; |
| 543 | |
| 544 | tbl = slot->table; |
| 545 | spin_lock(&tbl->slot_tbl_lock); |
| 546 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 547 | nfs4_free_slot(tbl, slot); |
| 548 | spin_unlock(&tbl->slot_tbl_lock); |
| 549 | |
| 550 | res->sr_slot = NULL; |
| 551 | out: |
| 552 | return 1; |
| 553 | } |
| 554 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 555 | #if defined(CONFIG_NFS_V4_1) |
| 556 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 557 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 558 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 559 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 560 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 561 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 562 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 563 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 564 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 565 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 566 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 567 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 568 | /* Be nice to the server: try to ensure that the last transmitted |
| 569 | * value for highest_user_slotid <= target_highest_slotid |
| 570 | */ |
| 571 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 572 | send_new_highest_used_slotid = true; |
| 573 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 574 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 575 | send_new_highest_used_slotid = false; |
| 576 | goto out_unlock; |
| 577 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 578 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 579 | |
| 580 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 581 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 582 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 583 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 584 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 585 | if (send_new_highest_used_slotid) |
| 586 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 587 | } |
| 588 | |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 589 | 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] | 590 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 591 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 592 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 593 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 594 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 595 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 596 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 597 | if (slot == NULL) |
| 598 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 599 | /* don't increment the sequence number if the task wasn't sent */ |
| 600 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 601 | goto out; |
| 602 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 603 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 604 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 605 | if (slot->interrupted) { |
| 606 | slot->interrupted = 0; |
| 607 | interrupted = true; |
| 608 | } |
| 609 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 610 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 611 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 612 | switch (res->sr_status) { |
| 613 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 614 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 615 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 616 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 617 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 618 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 619 | if (res->sr_status_flags != 0) |
| 620 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 621 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 622 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 623 | case 1: |
| 624 | /* |
| 625 | * sr_status remains 1 if an RPC level error occurred. |
| 626 | * The server may or may not have processed the sequence |
| 627 | * operation.. |
| 628 | * Mark the slot as having hosted an interrupted RPC call. |
| 629 | */ |
| 630 | slot->interrupted = 1; |
| 631 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 632 | case -NFS4ERR_DELAY: |
| 633 | /* The server detected a resend of the RPC call and |
| 634 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 635 | * of RFC5661. |
| 636 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 637 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 638 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 639 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 640 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 641 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 642 | case -NFS4ERR_BADSLOT: |
| 643 | /* |
| 644 | * The slot id we used was probably retired. Try again |
| 645 | * using a different slot id. |
| 646 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 647 | goto retry_nowait; |
| 648 | case -NFS4ERR_SEQ_MISORDERED: |
| 649 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 650 | * Was the last operation on this sequence interrupted? |
| 651 | * If so, retry after bumping the sequence number. |
| 652 | */ |
| 653 | if (interrupted) { |
| 654 | ++slot->seq_nr; |
| 655 | goto retry_nowait; |
| 656 | } |
| 657 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 658 | * Could this slot have been previously retired? |
| 659 | * If so, then the server may be expecting seq_nr = 1! |
| 660 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 661 | if (slot->seq_nr != 1) { |
| 662 | slot->seq_nr = 1; |
| 663 | goto retry_nowait; |
| 664 | } |
| 665 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 666 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 667 | ++slot->seq_nr; |
| 668 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 669 | default: |
| 670 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 671 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 672 | } |
| 673 | out: |
| 674 | /* The session may be reset by one of the error handlers. */ |
| 675 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 676 | nfs41_sequence_free_slot(res); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 677 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 678 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 679 | retry_nowait: |
| 680 | if (rpc_restart_call_prepare(task)) { |
| 681 | task->tk_status = 0; |
| 682 | ret = 0; |
| 683 | } |
| 684 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 685 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 686 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 687 | goto out; |
| 688 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 689 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 690 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 691 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 692 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 693 | 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] | 694 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 695 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 696 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 697 | if (!res->sr_slot->table->session) |
| 698 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 699 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 701 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 702 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 703 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 704 | struct nfs4_sequence_args *args, |
| 705 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 706 | struct rpc_task *task) |
| 707 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 708 | struct nfs4_slot *slot; |
| 709 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 710 | |
| 711 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 712 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 713 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 714 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 715 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 716 | tbl = &session->fc_slot_table; |
| 717 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 718 | task->tk_timeout = 0; |
| 719 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 720 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 721 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 722 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 723 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 724 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 725 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 726 | } |
| 727 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 728 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 729 | if (IS_ERR(slot)) { |
| 730 | /* If out of memory, try again in 1/4 second */ |
| 731 | if (slot == ERR_PTR(-ENOMEM)) |
| 732 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 733 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 734 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 735 | } |
| 736 | spin_unlock(&tbl->slot_tbl_lock); |
| 737 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 738 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 739 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 740 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 741 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 742 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 743 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 744 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 745 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 746 | /* |
| 747 | * sr_status is only set in decode_sequence, and so will remain |
| 748 | * set to 1 if an rpc level failure occurs. |
| 749 | */ |
| 750 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 751 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 752 | out_success: |
| 753 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 754 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 755 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 756 | /* Privileged tasks are queued with top priority */ |
| 757 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 758 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 759 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 760 | else |
| 761 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 762 | spin_unlock(&tbl->slot_tbl_lock); |
| 763 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 764 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 765 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 766 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 767 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 768 | struct nfs4_sequence_args *args, |
| 769 | struct nfs4_sequence_res *res, |
| 770 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 771 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 772 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 773 | int ret = 0; |
| 774 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 775 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 776 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 777 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 778 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 779 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 780 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 781 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 782 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 783 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 784 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 785 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 786 | return ret; |
| 787 | } |
| 788 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 789 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 790 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 791 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 792 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 793 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 794 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 795 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 796 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 797 | } |
| 798 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 799 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 800 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 801 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 802 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 803 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 804 | } |
| 805 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 806 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 807 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 808 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 809 | }; |
| 810 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 811 | #else /* !CONFIG_NFS_V4_1 */ |
| 812 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 813 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 814 | struct nfs4_sequence_args *args, |
| 815 | struct nfs4_sequence_res *res, |
| 816 | struct rpc_task *task) |
| 817 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 818 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 819 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 820 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 821 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 822 | int nfs4_sequence_done(struct rpc_task *task, |
| 823 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 824 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 825 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 826 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 827 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 828 | |
| 829 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 830 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 831 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 832 | { |
| 833 | struct nfs4_call_sync_data *data = calldata; |
| 834 | nfs4_setup_sequence(data->seq_server, |
| 835 | data->seq_args, data->seq_res, task); |
| 836 | } |
| 837 | |
| 838 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 839 | { |
| 840 | struct nfs4_call_sync_data *data = calldata; |
| 841 | nfs4_sequence_done(task, data->seq_res); |
| 842 | } |
| 843 | |
| 844 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 845 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 846 | .rpc_call_done = nfs40_call_sync_done, |
| 847 | }; |
| 848 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 849 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 850 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 851 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | struct nfs4_sequence_args *args, |
| 853 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 854 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | int ret; |
| 856 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 857 | struct nfs_client *clp = server->nfs_client; |
| 858 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 859 | .seq_server = server, |
| 860 | .seq_args = args, |
| 861 | .seq_res = res, |
| 862 | }; |
| 863 | struct rpc_task_setup task_setup = { |
| 864 | .rpc_client = clnt, |
| 865 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 866 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 867 | .callback_data = &data |
| 868 | }; |
| 869 | |
| 870 | task = rpc_run_task(&task_setup); |
| 871 | if (IS_ERR(task)) |
| 872 | ret = PTR_ERR(task); |
| 873 | else { |
| 874 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 875 | rpc_put_task(task); |
| 876 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 877 | return ret; |
| 878 | } |
| 879 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 880 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 881 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 882 | struct rpc_message *msg, |
| 883 | struct nfs4_sequence_args *args, |
| 884 | struct nfs4_sequence_res *res, |
| 885 | int cache_reply) |
| 886 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 887 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 888 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
| 891 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 892 | { |
| 893 | struct nfs_inode *nfsi = NFS_I(dir); |
| 894 | |
| 895 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 896 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 897 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 899 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 900 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 901 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | spin_unlock(&dir->i_lock); |
| 903 | } |
| 904 | |
| 905 | struct nfs4_opendata { |
| 906 | struct kref kref; |
| 907 | struct nfs_openargs o_arg; |
| 908 | struct nfs_openres o_res; |
| 909 | struct nfs_open_confirmargs c_arg; |
| 910 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 911 | struct nfs4_string owner_name; |
| 912 | struct nfs4_string group_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 914 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 916 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | struct nfs4_state_owner *owner; |
| 918 | struct nfs4_state *state; |
| 919 | struct iattr attrs; |
| 920 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 921 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 922 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 923 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 924 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | int cancelled; |
| 926 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 927 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 928 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 929 | int err, struct nfs4_exception *exception) |
| 930 | { |
| 931 | if (err != -EINVAL) |
| 932 | return false; |
| 933 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 934 | return false; |
| 935 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 936 | exception->retry = 1; |
| 937 | return true; |
| 938 | } |
| 939 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 940 | static u32 |
| 941 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 942 | fmode_t fmode, int openflags) |
| 943 | { |
| 944 | u32 res = 0; |
| 945 | |
| 946 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 947 | case FMODE_READ: |
| 948 | res = NFS4_SHARE_ACCESS_READ; |
| 949 | break; |
| 950 | case FMODE_WRITE: |
| 951 | res = NFS4_SHARE_ACCESS_WRITE; |
| 952 | break; |
| 953 | case FMODE_READ|FMODE_WRITE: |
| 954 | res = NFS4_SHARE_ACCESS_BOTH; |
| 955 | } |
| 956 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 957 | goto out; |
| 958 | /* Want no delegation if we're using O_DIRECT */ |
| 959 | if (openflags & O_DIRECT) |
| 960 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 961 | out: |
| 962 | return res; |
| 963 | } |
| 964 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 965 | static enum open_claim_type4 |
| 966 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 967 | enum open_claim_type4 claim) |
| 968 | { |
| 969 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 970 | return claim; |
| 971 | switch (claim) { |
| 972 | default: |
| 973 | return claim; |
| 974 | case NFS4_OPEN_CLAIM_FH: |
| 975 | return NFS4_OPEN_CLAIM_NULL; |
| 976 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 977 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 978 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 979 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 980 | } |
| 981 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
| 983 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 984 | { |
| 985 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 986 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 987 | p->o_res.seqid = p->o_arg.seqid; |
| 988 | p->c_res.seqid = p->c_arg.seqid; |
| 989 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 990 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 991 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 992 | 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] | 993 | } |
| 994 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 995 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 996 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 997 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 998 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 999 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1000 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1001 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1002 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1003 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1004 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1005 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1006 | struct nfs4_opendata *p; |
| 1007 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1008 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1009 | if (p == NULL) |
| 1010 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1011 | |
| 1012 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1013 | if (IS_ERR(p->f_label)) |
| 1014 | goto err_free_p; |
| 1015 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1016 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1017 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1018 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1019 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1020 | nfs_sb_active(dentry->d_sb); |
| 1021 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1022 | p->dir = parent; |
| 1023 | p->owner = sp; |
| 1024 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | p->o_arg.open_flags = flags; |
| 1026 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1027 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1028 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1029 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1030 | * will return permission denied for all bits until close */ |
| 1031 | if (!(flags & O_EXCL)) { |
| 1032 | /* ask server to check for all possible rights as results |
| 1033 | * are cached */ |
| 1034 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1035 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1036 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1037 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1038 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1039 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1040 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1041 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1042 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1043 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1044 | p->o_arg.label = label; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1045 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1046 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1047 | case NFS4_OPEN_CLAIM_NULL: |
| 1048 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1049 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1050 | p->o_arg.fh = NFS_FH(dir); |
| 1051 | break; |
| 1052 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1053 | case NFS4_OPEN_CLAIM_FH: |
| 1054 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1055 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1056 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1057 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1058 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1059 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1060 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1061 | p->o_arg.u.attrs = &p->attrs; |
| 1062 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1063 | |
| 1064 | verf[0] = jiffies; |
| 1065 | verf[1] = current->pid; |
| 1066 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1067 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1068 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1069 | p->c_arg.fh = &p->o_res.fh; |
| 1070 | p->c_arg.stateid = &p->o_res.stateid; |
| 1071 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1072 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1073 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1074 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1075 | |
| 1076 | err_free_label: |
| 1077 | nfs4_label_free(p->f_label); |
| 1078 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1079 | kfree(p); |
| 1080 | err: |
| 1081 | dput(parent); |
| 1082 | return NULL; |
| 1083 | } |
| 1084 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1085 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1086 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1087 | struct nfs4_opendata *p = container_of(kref, |
| 1088 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1089 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1090 | |
| 1091 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1092 | if (p->state != NULL) |
| 1093 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1094 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1095 | |
| 1096 | nfs4_label_free(p->f_label); |
| 1097 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1098 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1099 | dput(p->dentry); |
| 1100 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1101 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1102 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1103 | kfree(p); |
| 1104 | } |
| 1105 | |
| 1106 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1107 | { |
| 1108 | if (p != NULL) |
| 1109 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1112 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1113 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1114 | int ret; |
| 1115 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1116 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1117 | return ret; |
| 1118 | } |
| 1119 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1120 | 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] | 1121 | { |
| 1122 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1123 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1124 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1125 | goto out; |
| 1126 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1127 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1128 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1129 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1130 | break; |
| 1131 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1132 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1133 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1134 | break; |
| 1135 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1136 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1137 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1138 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1139 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1140 | return ret; |
| 1141 | } |
| 1142 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1143 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1144 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1145 | if (delegation == NULL) |
| 1146 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1147 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1148 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1149 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1150 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1151 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1152 | return 1; |
| 1153 | } |
| 1154 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1155 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1156 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1157 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1158 | case FMODE_WRITE: |
| 1159 | state->n_wronly++; |
| 1160 | break; |
| 1161 | case FMODE_READ: |
| 1162 | state->n_rdonly++; |
| 1163 | break; |
| 1164 | case FMODE_READ|FMODE_WRITE: |
| 1165 | state->n_rdwr++; |
| 1166 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1167 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1168 | } |
| 1169 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1170 | 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] | 1171 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1172 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1173 | bool need_recover = false; |
| 1174 | |
| 1175 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1176 | need_recover = true; |
| 1177 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1178 | need_recover = true; |
| 1179 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1180 | need_recover = true; |
| 1181 | if (need_recover) |
| 1182 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1183 | } |
| 1184 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1185 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1186 | nfs4_stateid *stateid) |
| 1187 | { |
| 1188 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1189 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1190 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1191 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1192 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1193 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1194 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1195 | return true; |
| 1196 | return false; |
| 1197 | } |
| 1198 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1199 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1200 | { |
| 1201 | if (state->n_wronly) |
| 1202 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1203 | if (state->n_rdonly) |
| 1204 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1205 | if (state->n_rdwr) |
| 1206 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1207 | } |
| 1208 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1209 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1210 | nfs4_stateid *stateid, fmode_t fmode) |
| 1211 | { |
| 1212 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1213 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1214 | case FMODE_WRITE: |
| 1215 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1216 | break; |
| 1217 | case FMODE_READ: |
| 1218 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1219 | break; |
| 1220 | case 0: |
| 1221 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1222 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1223 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1224 | } |
| 1225 | if (stateid == NULL) |
| 1226 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1227 | /* Handle races with OPEN */ |
| 1228 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid) || |
| 1229 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1230 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1231 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1232 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1233 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1234 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1235 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | static void nfs_clear_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1239 | { |
| 1240 | write_seqlock(&state->seqlock); |
| 1241 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
| 1242 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1243 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1244 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1245 | } |
| 1246 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1247 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1248 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1249 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1250 | case FMODE_READ: |
| 1251 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1252 | break; |
| 1253 | case FMODE_WRITE: |
| 1254 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1255 | break; |
| 1256 | case FMODE_READ|FMODE_WRITE: |
| 1257 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1258 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1259 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1260 | return; |
| 1261 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1262 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1263 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1264 | } |
| 1265 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1266 | 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] | 1267 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1268 | /* |
| 1269 | * Protect the call to nfs4_state_set_mode_locked and |
| 1270 | * serialise the stateid update |
| 1271 | */ |
| 1272 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1273 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1274 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1275 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1276 | } |
| 1277 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1278 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1279 | write_sequnlock(&state->seqlock); |
| 1280 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1281 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1282 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1285 | 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] | 1286 | { |
| 1287 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1288 | struct nfs_delegation *deleg_cur; |
| 1289 | int ret = 0; |
| 1290 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1291 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1292 | |
| 1293 | rcu_read_lock(); |
| 1294 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1295 | if (deleg_cur == NULL) |
| 1296 | goto no_delegation; |
| 1297 | |
| 1298 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1299 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1300 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1301 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1302 | goto no_delegation_unlock; |
| 1303 | |
| 1304 | if (delegation == NULL) |
| 1305 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1306 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1307 | goto no_delegation_unlock; |
| 1308 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1309 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1310 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1311 | ret = 1; |
| 1312 | no_delegation_unlock: |
| 1313 | spin_unlock(&deleg_cur->lock); |
| 1314 | no_delegation: |
| 1315 | rcu_read_unlock(); |
| 1316 | |
| 1317 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1318 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1319 | ret = 1; |
| 1320 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1321 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1322 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1323 | |
| 1324 | return ret; |
| 1325 | } |
| 1326 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1327 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1328 | const nfs4_stateid *stateid) |
| 1329 | { |
| 1330 | struct nfs4_state *state = lsp->ls_state; |
| 1331 | bool ret = false; |
| 1332 | |
| 1333 | spin_lock(&state->state_lock); |
| 1334 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1335 | goto out_noupdate; |
| 1336 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1337 | goto out_noupdate; |
| 1338 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1339 | ret = true; |
| 1340 | out_noupdate: |
| 1341 | spin_unlock(&state->state_lock); |
| 1342 | return ret; |
| 1343 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1344 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1345 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1346 | { |
| 1347 | struct nfs_delegation *delegation; |
| 1348 | |
| 1349 | rcu_read_lock(); |
| 1350 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1351 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1352 | rcu_read_unlock(); |
| 1353 | return; |
| 1354 | } |
| 1355 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1356 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1357 | } |
| 1358 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1359 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1360 | { |
| 1361 | struct nfs4_state *state = opendata->state; |
| 1362 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1363 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1364 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1365 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1366 | nfs4_stateid stateid; |
| 1367 | int ret = -EAGAIN; |
| 1368 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1369 | for (;;) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1370 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1371 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1372 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1373 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1374 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1375 | } |
Anna Schumaker | 61beef75 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1376 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1377 | rcu_read_lock(); |
| 1378 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1379 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1380 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1381 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1382 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1383 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1384 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1385 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1386 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1387 | if (!opendata->is_recover) { |
| 1388 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1389 | if (ret != 0) |
| 1390 | goto out; |
| 1391 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1392 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1393 | |
| 1394 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1395 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1396 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1397 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1398 | out: |
| 1399 | return ERR_PTR(ret); |
| 1400 | out_return_state: |
| 1401 | atomic_inc(&state->count); |
| 1402 | return state; |
| 1403 | } |
| 1404 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1405 | static void |
| 1406 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1407 | { |
| 1408 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1409 | struct nfs_delegation *delegation; |
| 1410 | int delegation_flags = 0; |
| 1411 | |
| 1412 | rcu_read_lock(); |
| 1413 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1414 | if (delegation) |
| 1415 | delegation_flags = delegation->flags; |
| 1416 | rcu_read_unlock(); |
| 1417 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1418 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1419 | "returning a delegation for " |
| 1420 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1421 | clp->cl_hostname); |
| 1422 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1423 | nfs_inode_set_delegation(state->inode, |
| 1424 | data->owner->so_cred, |
| 1425 | &data->o_res); |
| 1426 | else |
| 1427 | nfs_inode_reclaim_delegation(state->inode, |
| 1428 | data->owner->so_cred, |
| 1429 | &data->o_res); |
| 1430 | } |
| 1431 | |
| 1432 | /* |
| 1433 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1434 | * and update the nfs4_state. |
| 1435 | */ |
| 1436 | static struct nfs4_state * |
| 1437 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1438 | { |
| 1439 | struct inode *inode = data->state->inode; |
| 1440 | struct nfs4_state *state = data->state; |
| 1441 | int ret; |
| 1442 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1443 | if (!data->rpc_done) { |
| 1444 | if (data->rpc_status) { |
| 1445 | ret = data->rpc_status; |
| 1446 | goto err; |
| 1447 | } |
| 1448 | /* cached opens have already been processed */ |
| 1449 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1452 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1453 | if (ret) |
| 1454 | goto err; |
| 1455 | |
| 1456 | if (data->o_res.delegation_type != 0) |
| 1457 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1458 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1459 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1460 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1461 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1462 | |
| 1463 | return state; |
| 1464 | err: |
| 1465 | return ERR_PTR(ret); |
| 1466 | |
| 1467 | } |
| 1468 | |
| 1469 | static struct nfs4_state * |
| 1470 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1471 | { |
| 1472 | struct inode *inode; |
| 1473 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1474 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1476 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1477 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1478 | goto out; |
| 1479 | } |
| 1480 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1481 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1482 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1483 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1484 | 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] | 1485 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1486 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1487 | goto err; |
| 1488 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1489 | state = nfs4_get_open_state(inode, data->owner); |
| 1490 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1491 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1492 | if (data->o_res.delegation_type != 0) |
| 1493 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1494 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1495 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1497 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1498 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1499 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1500 | err_put_inode: |
| 1501 | iput(inode); |
| 1502 | err: |
| 1503 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | } |
| 1505 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1506 | static struct nfs4_state * |
| 1507 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1508 | { |
| 1509 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1510 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1511 | return _nfs4_opendata_to_nfs4_state(data); |
| 1512 | } |
| 1513 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1514 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1515 | { |
| 1516 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1517 | struct nfs_open_context *ctx; |
| 1518 | |
| 1519 | spin_lock(&state->inode->i_lock); |
| 1520 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1521 | if (ctx->state != state) |
| 1522 | continue; |
| 1523 | get_nfs_open_context(ctx); |
| 1524 | spin_unlock(&state->inode->i_lock); |
| 1525 | return ctx; |
| 1526 | } |
| 1527 | spin_unlock(&state->inode->i_lock); |
| 1528 | return ERR_PTR(-ENOENT); |
| 1529 | } |
| 1530 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1531 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1532 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1533 | { |
| 1534 | struct nfs4_opendata *opendata; |
| 1535 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1536 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1537 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1538 | if (opendata == NULL) |
| 1539 | return ERR_PTR(-ENOMEM); |
| 1540 | opendata->state = state; |
| 1541 | atomic_inc(&state->count); |
| 1542 | return opendata; |
| 1543 | } |
| 1544 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1545 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1546 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1547 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1548 | int ret; |
| 1549 | |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1550 | if ((opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR || |
| 1551 | opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEG_CUR_FH) && |
| 1552 | (opendata->o_arg.u.delegation_type & fmode) != fmode) |
| 1553 | /* This mode can't have been delegated, so we must have |
| 1554 | * a valid open_stateid to cover it - not need to reclaim. |
| 1555 | */ |
| 1556 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1557 | opendata->o_arg.open_flags = 0; |
| 1558 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1559 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1560 | NFS_SB(opendata->dentry->d_sb), |
| 1561 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1562 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1563 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1564 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1565 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1566 | if (ret != 0) |
| 1567 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1568 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1569 | if (IS_ERR(newstate)) |
| 1570 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1571 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1572 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1577 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1578 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1579 | int ret; |
| 1580 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1581 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1582 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1583 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1584 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1585 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1586 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1587 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1588 | smp_rmb(); |
| 1589 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1590 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1591 | if (ret != 0) |
| 1592 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1593 | if (newstate != state) |
| 1594 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1595 | } |
| 1596 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1597 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1598 | if (ret != 0) |
| 1599 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1600 | if (newstate != state) |
| 1601 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1602 | } |
| 1603 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1604 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1605 | if (ret != 0) |
| 1606 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1607 | if (newstate != state) |
| 1608 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1609 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1610 | /* |
| 1611 | * We may have performed cached opens for all three recoveries. |
| 1612 | * Check if we need to update the current stateid. |
| 1613 | */ |
| 1614 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1615 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1616 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1617 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1618 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1619 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1620 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1621 | return 0; |
| 1622 | } |
| 1623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | /* |
| 1625 | * OPEN_RECLAIM: |
| 1626 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1628 | 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] | 1629 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1630 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1631 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1632 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | int status; |
| 1634 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1635 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1636 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1637 | if (IS_ERR(opendata)) |
| 1638 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1639 | rcu_read_lock(); |
| 1640 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1641 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1642 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1643 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1644 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1645 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1646 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | return status; |
| 1648 | } |
| 1649 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1650 | 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] | 1651 | { |
| 1652 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1653 | struct nfs4_exception exception = { }; |
| 1654 | int err; |
| 1655 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1656 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1657 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1658 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1659 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1660 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1661 | break; |
| 1662 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | } while (exception.retry); |
| 1664 | return err; |
| 1665 | } |
| 1666 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1667 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1668 | { |
| 1669 | struct nfs_open_context *ctx; |
| 1670 | int ret; |
| 1671 | |
| 1672 | ctx = nfs4_state_find_open_context(state); |
| 1673 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1674 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1675 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1676 | put_nfs_open_context(ctx); |
| 1677 | return ret; |
| 1678 | } |
| 1679 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1680 | 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] | 1681 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1682 | switch (err) { |
| 1683 | default: |
| 1684 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1685 | "%d.\n", __func__, err); |
| 1686 | case 0: |
| 1687 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1688 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1689 | case -ESTALE: |
| 1690 | break; |
| 1691 | case -NFS4ERR_BADSESSION: |
| 1692 | case -NFS4ERR_BADSLOT: |
| 1693 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1694 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1695 | case -NFS4ERR_DEADSESSION: |
| 1696 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1697 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1698 | return -EAGAIN; |
| 1699 | case -NFS4ERR_STALE_CLIENTID: |
| 1700 | case -NFS4ERR_STALE_STATEID: |
| 1701 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1702 | case -NFS4ERR_EXPIRED: |
| 1703 | /* Don't recall a delegation if it was lost */ |
| 1704 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1705 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1706 | case -NFS4ERR_MOVED: |
| 1707 | nfs4_schedule_migration_recovery(server); |
| 1708 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1709 | case -NFS4ERR_LEASE_MOVED: |
| 1710 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1711 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1712 | case -NFS4ERR_DELEG_REVOKED: |
| 1713 | case -NFS4ERR_ADMIN_REVOKED: |
| 1714 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1715 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1716 | nfs_inode_find_state_and_recover(state->inode, |
| 1717 | stateid); |
| 1718 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1719 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1720 | case -NFS4ERR_DELAY: |
| 1721 | case -NFS4ERR_GRACE: |
| 1722 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1723 | ssleep(1); |
| 1724 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1725 | case -ENOMEM: |
| 1726 | case -NFS4ERR_DENIED: |
| 1727 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1728 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | return err; |
| 1731 | } |
| 1732 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1733 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1734 | { |
| 1735 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1736 | struct nfs4_opendata *opendata; |
| 1737 | int err; |
| 1738 | |
| 1739 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1740 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1741 | if (IS_ERR(opendata)) |
| 1742 | return PTR_ERR(opendata); |
| 1743 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1744 | err = nfs4_open_recover(opendata, state); |
| 1745 | nfs4_opendata_put(opendata); |
| 1746 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1747 | } |
| 1748 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1749 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1750 | { |
| 1751 | struct nfs4_opendata *data = calldata; |
| 1752 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1753 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1754 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1755 | } |
| 1756 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1757 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1758 | { |
| 1759 | struct nfs4_opendata *data = calldata; |
| 1760 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1761 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1762 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1763 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1764 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1765 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1766 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1767 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1768 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1769 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | static void nfs4_open_confirm_release(void *calldata) |
| 1773 | { |
| 1774 | struct nfs4_opendata *data = calldata; |
| 1775 | struct nfs4_state *state = NULL; |
| 1776 | |
| 1777 | /* If this request hasn't been cancelled, do nothing */ |
| 1778 | if (data->cancelled == 0) |
| 1779 | goto out_free; |
| 1780 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1781 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1782 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1783 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1784 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1785 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1786 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1787 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1791 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1792 | .rpc_call_done = nfs4_open_confirm_done, |
| 1793 | .rpc_release = nfs4_open_confirm_release, |
| 1794 | }; |
| 1795 | |
| 1796 | /* |
| 1797 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1798 | */ |
| 1799 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1800 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1801 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1802 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1803 | struct rpc_message msg = { |
| 1804 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1805 | .rpc_argp = &data->c_arg, |
| 1806 | .rpc_resp = &data->c_res, |
| 1807 | .rpc_cred = data->owner->so_cred, |
| 1808 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1809 | struct rpc_task_setup task_setup_data = { |
| 1810 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1811 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1812 | .callback_ops = &nfs4_open_confirm_ops, |
| 1813 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1814 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1815 | .flags = RPC_TASK_ASYNC, |
| 1816 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | int status; |
| 1818 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1819 | 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] | 1820 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1821 | data->rpc_done = 0; |
| 1822 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1823 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1824 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1825 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1826 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1827 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1828 | if (status != 0) { |
| 1829 | data->cancelled = 1; |
| 1830 | smp_wmb(); |
| 1831 | } else |
| 1832 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1833 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | return status; |
| 1835 | } |
| 1836 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1837 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1839 | struct nfs4_opendata *data = calldata; |
| 1840 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1841 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1842 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1843 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1844 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1845 | /* |
| 1846 | * Check if we still need to send an OPEN call, or if we can use |
| 1847 | * a delegation instead. |
| 1848 | */ |
| 1849 | if (data->state != NULL) { |
| 1850 | struct nfs_delegation *delegation; |
| 1851 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1852 | 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] | 1853 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1854 | rcu_read_lock(); |
| 1855 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1856 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1857 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1858 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1859 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1860 | rcu_read_unlock(); |
| 1861 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1862 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1863 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1864 | switch (data->o_arg.claim) { |
| 1865 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1866 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1867 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1868 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1869 | case NFS4_OPEN_CLAIM_FH: |
| 1870 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1871 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1872 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1873 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1874 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1875 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1876 | &data->o_res.seq_res, |
| 1877 | task) != 0) |
| 1878 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1879 | |
| 1880 | /* Set the create mode (note dependency on the session type) */ |
| 1881 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1882 | if (data->o_arg.open_flags & O_EXCL) { |
| 1883 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1884 | if (nfs4_has_persistent_session(clp)) |
| 1885 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1886 | else if (clp->cl_mvops->minor_version > 0) |
| 1887 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1888 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1889 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1890 | unlock_no_action: |
| 1891 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1892 | out_no_action: |
| 1893 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1894 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1895 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1896 | } |
| 1897 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1898 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1899 | { |
| 1900 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1902 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1903 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1904 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1905 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1906 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1907 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1908 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1909 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1910 | case S_IFREG: |
| 1911 | break; |
| 1912 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1913 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1914 | break; |
| 1915 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1916 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1917 | break; |
| 1918 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1919 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1920 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1921 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1922 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1923 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1924 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1925 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1926 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1927 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1928 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1929 | static void nfs4_open_release(void *calldata) |
| 1930 | { |
| 1931 | struct nfs4_opendata *data = calldata; |
| 1932 | struct nfs4_state *state = NULL; |
| 1933 | |
| 1934 | /* If this request hasn't been cancelled, do nothing */ |
| 1935 | if (data->cancelled == 0) |
| 1936 | goto out_free; |
| 1937 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1938 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1939 | goto out_free; |
| 1940 | /* In case we need an open_confirm, no cleanup! */ |
| 1941 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1942 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1943 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1944 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1945 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1946 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1947 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1951 | .rpc_call_prepare = nfs4_open_prepare, |
| 1952 | .rpc_call_done = nfs4_open_done, |
| 1953 | .rpc_release = nfs4_open_release, |
| 1954 | }; |
| 1955 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1956 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1957 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1958 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1959 | struct nfs_server *server = NFS_SERVER(dir); |
| 1960 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1961 | struct nfs_openres *o_res = &data->o_res; |
| 1962 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1963 | struct rpc_message msg = { |
| 1964 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1965 | .rpc_argp = o_arg, |
| 1966 | .rpc_resp = o_res, |
| 1967 | .rpc_cred = data->owner->so_cred, |
| 1968 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1969 | struct rpc_task_setup task_setup_data = { |
| 1970 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1971 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1972 | .callback_ops = &nfs4_open_ops, |
| 1973 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1974 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1975 | .flags = RPC_TASK_ASYNC, |
| 1976 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1977 | int status; |
| 1978 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1979 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1980 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1981 | data->rpc_done = 0; |
| 1982 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1983 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1984 | data->is_recover = 0; |
| 1985 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1986 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1987 | data->is_recover = 1; |
| 1988 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1989 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1990 | if (IS_ERR(task)) |
| 1991 | return PTR_ERR(task); |
| 1992 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1993 | if (status != 0) { |
| 1994 | data->cancelled = 1; |
| 1995 | smp_wmb(); |
| 1996 | } else |
| 1997 | status = data->rpc_status; |
| 1998 | rpc_put_task(task); |
| 1999 | |
| 2000 | return status; |
| 2001 | } |
| 2002 | |
| 2003 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2004 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2005 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2006 | struct nfs_openres *o_res = &data->o_res; |
| 2007 | int status; |
| 2008 | |
| 2009 | status = nfs4_run_open_task(data, 1); |
| 2010 | if (status != 0 || !data->rpc_done) |
| 2011 | return status; |
| 2012 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2013 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2014 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2015 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2016 | status = _nfs4_proc_open_confirm(data); |
| 2017 | if (status != 0) |
| 2018 | return status; |
| 2019 | } |
| 2020 | |
| 2021 | return status; |
| 2022 | } |
| 2023 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2024 | /* |
| 2025 | * Additional permission checks in order to distinguish between an |
| 2026 | * open for read, and an open for execute. This works around the |
| 2027 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2028 | * the same. |
| 2029 | * Note that in the non-execute case, we want to turn off permission |
| 2030 | * checking if we just created a new file (POSIX open() semantics). |
| 2031 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2032 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2033 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2034 | struct nfs4_state *state, fmode_t fmode, |
| 2035 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2036 | { |
| 2037 | struct nfs_access_entry cache; |
| 2038 | u32 mask; |
| 2039 | |
| 2040 | /* access call failed or for some reason the server doesn't |
| 2041 | * support any access modes -- defer access call until later */ |
| 2042 | if (opendata->o_res.access_supported == 0) |
| 2043 | return 0; |
| 2044 | |
| 2045 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2046 | /* |
| 2047 | * Use openflags to check for exec, because fmode won't |
| 2048 | * always have FMODE_EXEC set when file open for exec. |
| 2049 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2050 | if (openflags & __FMODE_EXEC) { |
| 2051 | /* ONLY check for exec rights */ |
| 2052 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2053 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2054 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2055 | |
| 2056 | cache.cred = cred; |
| 2057 | cache.jiffies = jiffies; |
| 2058 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2059 | nfs_access_add_cache(state->inode, &cache); |
| 2060 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2061 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2062 | return 0; |
| 2063 | |
| 2064 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2065 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2066 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2067 | } |
| 2068 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2069 | /* |
| 2070 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2071 | */ |
| 2072 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2073 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2074 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2075 | struct nfs_server *server = NFS_SERVER(dir); |
| 2076 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2077 | struct nfs_openres *o_res = &data->o_res; |
| 2078 | int status; |
| 2079 | |
| 2080 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2081 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2082 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2083 | if (status != 0) { |
| 2084 | if (status == -NFS4ERR_BADNAME && |
| 2085 | !(o_arg->open_flags & O_CREAT)) |
| 2086 | return -ENOENT; |
| 2087 | return status; |
| 2088 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2089 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2090 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2091 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2092 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2093 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2094 | if (o_arg->open_flags & O_EXCL) |
| 2095 | data->file_created = 1; |
| 2096 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2097 | data->file_created = 1; |
| 2098 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2099 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2100 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2102 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2104 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | } |
| 2106 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2107 | 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] | 2108 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2111 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2112 | { |
| 2113 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2114 | } |
| 2115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | /* |
| 2117 | * OPEN_EXPIRED: |
| 2118 | * reclaim state on the server after a network partition. |
| 2119 | * Assumes caller holds the appropriate lock |
| 2120 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2121 | 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] | 2122 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2123 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2124 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2126 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2127 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2128 | if (IS_ERR(opendata)) |
| 2129 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2130 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2131 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2132 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2133 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2134 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2137 | 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] | 2138 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2139 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2140 | struct nfs4_exception exception = { }; |
| 2141 | int err; |
| 2142 | |
| 2143 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2144 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2145 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2146 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2147 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2148 | switch (err) { |
| 2149 | default: |
| 2150 | goto out; |
| 2151 | case -NFS4ERR_GRACE: |
| 2152 | case -NFS4ERR_DELAY: |
| 2153 | nfs4_handle_exception(server, err, &exception); |
| 2154 | err = 0; |
| 2155 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2156 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2157 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2158 | return err; |
| 2159 | } |
| 2160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2162 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2164 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2166 | ctx = nfs4_state_find_open_context(state); |
| 2167 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2168 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2169 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2170 | put_nfs_open_context(ctx); |
| 2171 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2174 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2175 | { |
| 2176 | nfs_remove_bad_delegation(state->inode); |
| 2177 | write_seqlock(&state->seqlock); |
| 2178 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2179 | write_sequnlock(&state->seqlock); |
| 2180 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2181 | } |
| 2182 | |
| 2183 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2184 | { |
| 2185 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2186 | nfs_finish_clear_delegation_stateid(state); |
| 2187 | } |
| 2188 | |
| 2189 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2190 | { |
| 2191 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2192 | nfs40_clear_delegation_stateid(state); |
| 2193 | return nfs4_open_expired(sp, state); |
| 2194 | } |
| 2195 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2196 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2197 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2198 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2199 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2200 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2201 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2202 | struct rpc_cred *cred; |
| 2203 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2204 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2205 | /* Get the delegation credential for use by test/free_stateid */ |
| 2206 | rcu_read_lock(); |
| 2207 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2208 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2209 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2210 | return; |
| 2211 | } |
| 2212 | |
| 2213 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2214 | cred = get_rpccred(delegation->cred); |
| 2215 | rcu_read_unlock(); |
| 2216 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2217 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2218 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2219 | if (status != NFS_OK) { |
| 2220 | /* Free the stateid unless the server explicitly |
| 2221 | * informs us the stateid is unrecognized. */ |
| 2222 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2223 | nfs41_free_stateid(server, &stateid, cred); |
| 2224 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2225 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2226 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2227 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2232 | * |
| 2233 | * @state: NFSv4 state for an inode |
| 2234 | * |
| 2235 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2236 | * Otherwise a negative NFS4ERR value is returned. |
| 2237 | */ |
| 2238 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2239 | { |
| 2240 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2241 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2242 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2243 | int status; |
| 2244 | |
| 2245 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2246 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2247 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2248 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2249 | return -NFS4ERR_BAD_STATEID; |
| 2250 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2251 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2252 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2253 | if (status != NFS_OK) { |
| 2254 | /* Free the stateid unless the server explicitly |
| 2255 | * informs us the stateid is unrecognized. */ |
| 2256 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2257 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2258 | |
| 2259 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2260 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2261 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2262 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2263 | } |
| 2264 | return status; |
| 2265 | } |
| 2266 | |
| 2267 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2268 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2269 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2270 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2271 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2272 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2273 | if (status != NFS_OK) |
| 2274 | status = nfs4_open_expired(sp, state); |
| 2275 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2276 | } |
| 2277 | #endif |
| 2278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2280 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2281 | * fields corresponding to attributes that were used to store the verifier. |
| 2282 | * Make sure we clobber those fields in the later setattr call |
| 2283 | */ |
| 2284 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 2285 | { |
| 2286 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 2287 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2288 | sattr->ia_valid |= ATTR_ATIME; |
| 2289 | |
| 2290 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 2291 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2292 | sattr->ia_valid |= ATTR_MTIME; |
| 2293 | } |
| 2294 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2295 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2296 | fmode_t fmode, |
| 2297 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2298 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2299 | { |
| 2300 | struct nfs4_state_owner *sp = opendata->owner; |
| 2301 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2302 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2303 | struct nfs4_state *state; |
| 2304 | unsigned int seq; |
| 2305 | int ret; |
| 2306 | |
| 2307 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2308 | |
| 2309 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2310 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2311 | goto out; |
| 2312 | |
| 2313 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2314 | ret = PTR_ERR(state); |
| 2315 | if (IS_ERR(state)) |
| 2316 | goto out; |
| 2317 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2318 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 2319 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2320 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2321 | if (d_really_is_negative(dentry)) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2322 | /* FIXME: Is this d_drop() ever needed? */ |
| 2323 | d_drop(dentry); |
| 2324 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 2325 | if (dentry == NULL) { |
| 2326 | dentry = opendata->dentry; |
| 2327 | } else if (dentry != ctx->dentry) { |
| 2328 | dput(ctx->dentry); |
| 2329 | ctx->dentry = dget(dentry); |
| 2330 | } |
| 2331 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2332 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2333 | } |
| 2334 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2335 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2336 | if (ret != 0) |
| 2337 | goto out; |
| 2338 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2339 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2340 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2341 | nfs_inode_attach_open_context(ctx); |
| 2342 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2343 | nfs4_schedule_stateid_recovery(server, state); |
| 2344 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2345 | out: |
| 2346 | return ret; |
| 2347 | } |
| 2348 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2349 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2350 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2352 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2353 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2354 | int flags, |
| 2355 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2356 | struct nfs4_label *label, |
| 2357 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | { |
| 2359 | struct nfs4_state_owner *sp; |
| 2360 | struct nfs4_state *state = NULL; |
| 2361 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2362 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2363 | struct dentry *dentry = ctx->dentry; |
| 2364 | struct rpc_cred *cred = ctx->cred; |
| 2365 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2366 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2367 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2368 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2369 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | |
| 2371 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2373 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2374 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2376 | goto out_err; |
| 2377 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2378 | status = nfs4_recover_expired_lease(server); |
| 2379 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2380 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2381 | if (d_really_is_positive(dentry)) |
| 2382 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2383 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2384 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2385 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2386 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2387 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2388 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2389 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2391 | if (label) { |
| 2392 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2393 | if (IS_ERR(olabel)) { |
| 2394 | status = PTR_ERR(olabel); |
| 2395 | goto err_opendata_put; |
| 2396 | } |
| 2397 | } |
| 2398 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2399 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2400 | if (!opendata->f_attr.mdsthreshold) { |
| 2401 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2402 | if (!opendata->f_attr.mdsthreshold) |
| 2403 | goto err_free_label; |
| 2404 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2405 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2406 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2407 | if (d_really_is_positive(dentry)) |
| 2408 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2409 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2410 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2411 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2412 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2413 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2414 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2415 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2416 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2417 | nfs4_exclusive_attrset(opendata, sattr); |
| 2418 | |
| 2419 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2420 | status = nfs4_do_setattr(state->inode, cred, |
| 2421 | opendata->o_res.f_attr, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2422 | state, label, olabel); |
| 2423 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 2424 | nfs_setattr_update_inode(state->inode, sattr, |
| 2425 | opendata->o_res.f_attr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2426 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2427 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2428 | } |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2429 | if (opendata->file_created) |
| 2430 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2431 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2432 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2433 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2434 | opendata->f_attr.mdsthreshold = NULL; |
| 2435 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2436 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2437 | nfs4_label_free(olabel); |
| 2438 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2439 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2442 | err_free_label: |
| 2443 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2444 | err_opendata_put: |
| 2445 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2446 | err_put_state_owner: |
| 2447 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | return status; |
| 2450 | } |
| 2451 | |
| 2452 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2453 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2454 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2455 | int flags, |
| 2456 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2457 | struct nfs4_label *label, |
| 2458 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2460 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | struct nfs4_exception exception = { }; |
| 2462 | struct nfs4_state *res; |
| 2463 | int status; |
| 2464 | |
| 2465 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2466 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2467 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2468 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | if (status == 0) |
| 2470 | break; |
| 2471 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2472 | * book-keeping w.r.t. state-changing operations |
| 2473 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2474 | * It is actually a sign of a bug on the client or on the server. |
| 2475 | * |
| 2476 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2477 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | * have unhashed the old state_owner for us, and that we can |
| 2479 | * therefore safely retry using a new one. We should still warn |
| 2480 | * the user though... |
| 2481 | */ |
| 2482 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2483 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2484 | " returned a bad sequence-id error!\n", |
| 2485 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | exception.retry = 1; |
| 2487 | continue; |
| 2488 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2489 | /* |
| 2490 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2491 | * state before it received the OPEN_CONFIRM. |
| 2492 | * Recover by retrying the request as per the discussion |
| 2493 | * on Page 181 of RFC3530. |
| 2494 | */ |
| 2495 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2496 | exception.retry = 1; |
| 2497 | continue; |
| 2498 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2499 | if (status == -EAGAIN) { |
| 2500 | /* We must have found a delegation */ |
| 2501 | exception.retry = 1; |
| 2502 | continue; |
| 2503 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2504 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2505 | continue; |
| 2506 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | status, &exception)); |
| 2508 | } while (exception.retry); |
| 2509 | return res; |
| 2510 | } |
| 2511 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2512 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2513 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2514 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2515 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2517 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2519 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | .iap = sattr, |
| 2521 | .server = server, |
| 2522 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2523 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | }; |
| 2525 | struct nfs_setattrres res = { |
| 2526 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2527 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | .server = server, |
| 2529 | }; |
| 2530 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2532 | .rpc_argp = &arg, |
| 2533 | .rpc_resp = &res, |
| 2534 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2536 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2537 | fmode_t fmode; |
| 2538 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2539 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2541 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2542 | if (ilabel) |
| 2543 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2544 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2545 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2547 | /* Servers should only apply open mode checks for file size changes */ |
| 2548 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2549 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2550 | |
| 2551 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2552 | /* Use that stateid */ |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2553 | } else if (truncate && state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2554 | struct nfs_lockowner lockowner = { |
| 2555 | .l_owner = current->files, |
| 2556 | .l_pid = current->tgid, |
| 2557 | }; |
Trond Myklebust | 0418dae | 2014-03-04 13:48:16 -0500 | [diff] [blame] | 2558 | if (!nfs4_valid_open_stateid(state)) |
| 2559 | return -EBADF; |
| 2560 | if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2561 | &lockowner) == -EIO) |
| 2562 | return -EBADF; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2563 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2564 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2566 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2567 | if (status == 0 && state != NULL) |
| 2568 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2569 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2572 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2573 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2574 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2575 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2577 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2578 | struct nfs4_exception exception = { |
| 2579 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2580 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2581 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | int err; |
| 2583 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2584 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2585 | trace_nfs4_setattr(inode, err); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2586 | switch (err) { |
| 2587 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2588 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2589 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2590 | "applying open mode checks to " |
| 2591 | "a SETATTR that is not " |
| 2592 | "changing file size.\n", |
| 2593 | server->nfs_client->cl_hostname); |
| 2594 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2595 | if (state && !(state->state & FMODE_WRITE)) { |
| 2596 | err = -EBADF; |
| 2597 | if (sattr->ia_valid & ATTR_OPEN) |
| 2598 | err = -EACCES; |
| 2599 | goto out; |
| 2600 | } |
| 2601 | } |
| 2602 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2604 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | return err; |
| 2606 | } |
| 2607 | |
| 2608 | struct nfs4_closedata { |
| 2609 | struct inode *inode; |
| 2610 | struct nfs4_state *state; |
| 2611 | struct nfs_closeargs arg; |
| 2612 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2613 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2614 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2615 | bool roc; |
| 2616 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | }; |
| 2618 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2619 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2620 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2621 | struct nfs4_closedata *calldata = data; |
| 2622 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2623 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2624 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2625 | if (calldata->roc) |
| 2626 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2627 | nfs4_put_open_state(calldata->state); |
| 2628 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2629 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2630 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2631 | kfree(calldata); |
| 2632 | } |
| 2633 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2634 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2636 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2639 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2641 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2642 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2643 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2644 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | /* hmm. we are done with the inode, and in the process of freeing |
| 2646 | * the state_owner. we keep this around to process errors |
| 2647 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | switch (task->tk_status) { |
| 2649 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2650 | res_stateid = &calldata->res.stateid; |
| 2651 | if (calldata->arg.fmode == 0 && calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2652 | pnfs_roc_set_barrier(state->inode, |
| 2653 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2654 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2655 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2656 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2658 | case -NFS4ERR_OLD_STATEID: |
| 2659 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2661 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2662 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2663 | rpc_restart_call_prepare(task); |
| 2664 | goto out_release; |
| 2665 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2666 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2667 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2669 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2670 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2671 | goto out_release; |
| 2672 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | } |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2674 | nfs_clear_open_stateid(state, res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2675 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2676 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2677 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2678 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2681 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2683 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2684 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2685 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2686 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2687 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2688 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2689 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2690 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2691 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2692 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2693 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2694 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2695 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2696 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2697 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2698 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2699 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2700 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2701 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2702 | if (state->n_rdonly == 0) |
| 2703 | call_close |= is_rdonly; |
| 2704 | else if (is_rdonly) |
| 2705 | calldata->arg.fmode |= FMODE_READ; |
| 2706 | if (state->n_wronly == 0) |
| 2707 | call_close |= is_wronly; |
| 2708 | else if (is_wronly) |
| 2709 | calldata->arg.fmode |= FMODE_WRITE; |
| 2710 | } else if (is_rdwr) |
| 2711 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2712 | |
| 2713 | if (calldata->arg.fmode == 0) |
| 2714 | call_close |= is_rdwr; |
| 2715 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2716 | if (!nfs4_valid_open_stateid(state)) |
| 2717 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2718 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2719 | |
| 2720 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2721 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2722 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2723 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2724 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2725 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2726 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2727 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2728 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2729 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2730 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2731 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2732 | } |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2733 | calldata->arg.share_access = |
| 2734 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2735 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2736 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2737 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2738 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2739 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2740 | &calldata->arg.seq_args, |
| 2741 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2742 | task) != 0) |
| 2743 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2744 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2745 | return; |
| 2746 | out_no_action: |
| 2747 | task->tk_action = NULL; |
| 2748 | out_wait: |
| 2749 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2752 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2753 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2754 | .rpc_call_done = nfs4_close_done, |
| 2755 | .rpc_release = nfs4_free_closedata, |
| 2756 | }; |
| 2757 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2758 | static bool nfs4_roc(struct inode *inode) |
| 2759 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 2760 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2761 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2762 | return pnfs_roc(inode); |
| 2763 | } |
| 2764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | /* |
| 2766 | * It is possible for data to be read/written from a mem-mapped file |
| 2767 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2768 | * This means that we can't safely call nfsv4 close on a file until |
| 2769 | * the inode is cleared. This in turn means that we are not good |
| 2770 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2771 | * share state even when we are done with one of the three share |
| 2772 | * stateid's in the inode. |
| 2773 | * |
| 2774 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2775 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2776 | 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] | 2777 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2778 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2779 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2781 | struct nfs4_state_owner *sp = state->owner; |
| 2782 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2783 | struct rpc_message msg = { |
| 2784 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2785 | .rpc_cred = state->owner->so_cred, |
| 2786 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2787 | struct rpc_task_setup task_setup_data = { |
| 2788 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2789 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2790 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2791 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2792 | .flags = RPC_TASK_ASYNC, |
| 2793 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2794 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2796 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 2797 | &task_setup_data.rpc_client, &msg); |
| 2798 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2799 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2801 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2802 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2803 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2805 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 2807 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 2808 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 2809 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2810 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2811 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2812 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2813 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2814 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2815 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 2816 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2817 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2818 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2819 | msg.rpc_argp = &calldata->arg; |
| 2820 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2821 | task_setup_data.callback_data = calldata; |
| 2822 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2823 | if (IS_ERR(task)) |
| 2824 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2825 | status = 0; |
| 2826 | if (wait) |
| 2827 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2828 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2829 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2830 | out_free_calldata: |
| 2831 | kfree(calldata); |
| 2832 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2833 | nfs4_put_open_state(state); |
| 2834 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2835 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2838 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2839 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 2840 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2843 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 2844 | |
| 2845 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2847 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2848 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2849 | |
| 2850 | nfs4_label_release_security(label); |
| 2851 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2852 | if (IS_ERR(state)) |
| 2853 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2854 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2857 | 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] | 2858 | { |
| 2859 | if (ctx->state == NULL) |
| 2860 | return; |
| 2861 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2862 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2863 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2864 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2865 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2867 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 2868 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 2869 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2872 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2873 | struct nfs4_server_caps_arg args = { |
| 2874 | .fhandle = fhandle, |
| 2875 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | struct nfs4_server_caps_res res = {}; |
| 2877 | struct rpc_message msg = { |
| 2878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2879 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | .rpc_resp = &res, |
| 2881 | }; |
| 2882 | int status; |
| 2883 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2884 | 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] | 2885 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2886 | /* Sanity check the server answers */ |
| 2887 | switch (server->nfs_client->cl_minorversion) { |
| 2888 | case 0: |
| 2889 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 2890 | res.attr_bitmask[2] = 0; |
| 2891 | break; |
| 2892 | case 1: |
| 2893 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 2894 | break; |
| 2895 | case 2: |
| 2896 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 2897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2899 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2900 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2901 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2902 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2903 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 2904 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 2905 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 2906 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | server->caps |= NFS_CAP_ACLS; |
| 2908 | if (res.has_links != 0) |
| 2909 | server->caps |= NFS_CAP_HARDLINKS; |
| 2910 | if (res.has_symlinks != 0) |
| 2911 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2912 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2913 | server->caps |= NFS_CAP_FILEID; |
| 2914 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2915 | server->caps |= NFS_CAP_MODE; |
| 2916 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2917 | server->caps |= NFS_CAP_NLINK; |
| 2918 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2919 | server->caps |= NFS_CAP_OWNER; |
| 2920 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2921 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2922 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2923 | server->caps |= NFS_CAP_ATIME; |
| 2924 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2925 | server->caps |= NFS_CAP_CTIME; |
| 2926 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2927 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2928 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 2929 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2930 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 2931 | #endif |
| 2932 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 2933 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 2934 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2935 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2936 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2937 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2938 | 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] | 2939 | server->cache_consistency_bitmask[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2941 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | return status; |
| 2945 | } |
| 2946 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2947 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | { |
| 2949 | struct nfs4_exception exception = { }; |
| 2950 | int err; |
| 2951 | do { |
| 2952 | err = nfs4_handle_exception(server, |
| 2953 | _nfs4_server_capabilities(server, fhandle), |
| 2954 | &exception); |
| 2955 | } while (exception.retry); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
| 2959 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2960 | struct nfs_fsinfo *info) |
| 2961 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2962 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2964 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | }; |
| 2966 | struct nfs4_lookup_res res = { |
| 2967 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2968 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | .fh = fhandle, |
| 2970 | }; |
| 2971 | struct rpc_message msg = { |
| 2972 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2973 | .rpc_argp = &args, |
| 2974 | .rpc_resp = &res, |
| 2975 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2976 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2977 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 2978 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 2979 | /* |
| 2980 | * Process the label in the upcoming getfattr |
| 2981 | */ |
| 2982 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 2983 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2984 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2985 | 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] | 2986 | } |
| 2987 | |
| 2988 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2989 | struct nfs_fsinfo *info) |
| 2990 | { |
| 2991 | struct nfs4_exception exception = { }; |
| 2992 | int err; |
| 2993 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2994 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2995 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2996 | switch (err) { |
| 2997 | case 0: |
| 2998 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2999 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3000 | default: |
| 3001 | err = nfs4_handle_exception(server, err, &exception); |
| 3002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3004 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | return err; |
| 3006 | } |
| 3007 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3008 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3009 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3010 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3011 | struct rpc_auth_create_args auth_args = { |
| 3012 | .pseudoflavor = flavor, |
| 3013 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3014 | struct rpc_auth *auth; |
| 3015 | int ret; |
| 3016 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3017 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3018 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3019 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3020 | goto out; |
| 3021 | } |
| 3022 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3023 | out: |
| 3024 | return ret; |
| 3025 | } |
| 3026 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3027 | /* |
| 3028 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3029 | * |
| 3030 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3031 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3032 | * |
| 3033 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3034 | * negative errno value. |
| 3035 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3036 | 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] | 3037 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3039 | /* Per 3530bis 15.33.5 */ |
| 3040 | static const rpc_authflavor_t flav_array[] = { |
| 3041 | RPC_AUTH_GSS_KRB5P, |
| 3042 | RPC_AUTH_GSS_KRB5I, |
| 3043 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3044 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3045 | RPC_AUTH_NULL, |
| 3046 | }; |
| 3047 | int status = -EPERM; |
| 3048 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3050 | if (server->auth_info.flavor_len > 0) { |
| 3051 | /* try each flavor specified by user */ |
| 3052 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3053 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3054 | server->auth_info.flavors[i]); |
| 3055 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3056 | continue; |
| 3057 | break; |
| 3058 | } |
| 3059 | } else { |
| 3060 | /* no flavors specified by user, try default list */ |
| 3061 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3062 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3063 | flav_array[i]); |
| 3064 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3065 | continue; |
| 3066 | break; |
| 3067 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3068 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3069 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3070 | /* |
| 3071 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3072 | * to access the mount. It could also mean that we tried to mount |
| 3073 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3074 | * existing mount programs don't handle -EACCES very well so it should |
| 3075 | * be mapped to -EPERM instead. |
| 3076 | */ |
| 3077 | if (status == -EACCES) |
| 3078 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3079 | return status; |
| 3080 | } |
| 3081 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3082 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 3083 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 3084 | { |
| 3085 | int mv = server->nfs_client->cl_minorversion; |
| 3086 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 3087 | } |
| 3088 | |
| 3089 | /** |
| 3090 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3091 | * @server: initialized nfs_server handle |
| 3092 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3093 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3094 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3095 | * |
| 3096 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3097 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3098 | 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] | 3099 | struct nfs_fsinfo *info, |
| 3100 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3101 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3102 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3103 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3104 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3105 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3106 | |
| 3107 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3108 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 3109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | if (status == 0) |
| 3111 | status = nfs4_server_capabilities(server, fhandle); |
| 3112 | if (status == 0) |
| 3113 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3114 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3115 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3118 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3119 | struct nfs_fsinfo *info) |
| 3120 | { |
| 3121 | int error; |
| 3122 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3123 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3124 | |
| 3125 | error = nfs4_server_capabilities(server, mntfh); |
| 3126 | if (error < 0) { |
| 3127 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3128 | return error; |
| 3129 | } |
| 3130 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3131 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3132 | if (IS_ERR(label)) |
| 3133 | return PTR_ERR(label); |
| 3134 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3135 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3136 | if (error < 0) { |
| 3137 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3138 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3142 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3143 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3144 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3145 | err_free_label: |
| 3146 | nfs4_label_free(label); |
| 3147 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3148 | return error; |
| 3149 | } |
| 3150 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3151 | /* |
| 3152 | * Get locations and (maybe) other attributes of a referral. |
| 3153 | * Note that we'll actually follow the referral later when |
| 3154 | * we detect fsid mismatch in inode revalidation |
| 3155 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3156 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3157 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3158 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3159 | { |
| 3160 | int status = -ENOMEM; |
| 3161 | struct page *page = NULL; |
| 3162 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3163 | |
| 3164 | page = alloc_page(GFP_KERNEL); |
| 3165 | if (page == NULL) |
| 3166 | goto out; |
| 3167 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3168 | if (locations == NULL) |
| 3169 | goto out; |
| 3170 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3171 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3172 | if (status != 0) |
| 3173 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3174 | |
| 3175 | /* |
| 3176 | * If the fsid didn't change, this is a migration event, not a |
| 3177 | * referral. Cause us to drop into the exception handler, which |
| 3178 | * will kick off migration recovery. |
| 3179 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3180 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3181 | dprintk("%s: server did not return a different fsid for" |
| 3182 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3183 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3184 | goto out; |
| 3185 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3186 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3187 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3188 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3189 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3190 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3191 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3192 | out: |
| 3193 | if (page) |
| 3194 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3195 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3196 | return status; |
| 3197 | } |
| 3198 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3199 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3200 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | { |
| 3202 | struct nfs4_getattr_arg args = { |
| 3203 | .fh = fhandle, |
| 3204 | .bitmask = server->attr_bitmask, |
| 3205 | }; |
| 3206 | struct nfs4_getattr_res res = { |
| 3207 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3208 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | .server = server, |
| 3210 | }; |
| 3211 | struct rpc_message msg = { |
| 3212 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3213 | .rpc_argp = &args, |
| 3214 | .rpc_resp = &res, |
| 3215 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3216 | |
| 3217 | args.bitmask = nfs4_bitmask(server, label); |
| 3218 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3219 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3220 | 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] | 3221 | } |
| 3222 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3223 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3224 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | { |
| 3226 | struct nfs4_exception exception = { }; |
| 3227 | int err; |
| 3228 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3229 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3230 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3231 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | &exception); |
| 3233 | } while (exception.retry); |
| 3234 | return err; |
| 3235 | } |
| 3236 | |
| 3237 | /* |
| 3238 | * The file is not closed if it is opened due to the a request to change |
| 3239 | * the size of the file. The open call will not be needed once the |
| 3240 | * VFS layer lookup-intents are implemented. |
| 3241 | * |
| 3242 | * Close is called when the inode is destroyed. |
| 3243 | * If we haven't opened the file for O_WRONLY, we |
| 3244 | * need to in the size_change case to obtain a stateid. |
| 3245 | * |
| 3246 | * Got race? |
| 3247 | * Because OPEN is always done by name in nfsv4, it is |
| 3248 | * possible that we opened a different file by the same |
| 3249 | * name. We can recognize this race condition, but we |
| 3250 | * can't do anything about it besides returning an error. |
| 3251 | * |
| 3252 | * This will be fixed with VFS changes (lookup-intent). |
| 3253 | */ |
| 3254 | static int |
| 3255 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3256 | struct iattr *sattr) |
| 3257 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3258 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3259 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3260 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3261 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | int status; |
| 3263 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3264 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3265 | sattr->ia_valid & ATTR_SIZE && |
| 3266 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3267 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3268 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3269 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3271 | /* Deal with open(O_TRUNC) */ |
| 3272 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3273 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3274 | |
| 3275 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3276 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3277 | return 0; |
| 3278 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3279 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3280 | if (sattr->ia_valid & ATTR_FILE) { |
| 3281 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3282 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3283 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3284 | if (ctx) { |
| 3285 | cred = ctx->cred; |
| 3286 | state = ctx->state; |
| 3287 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3288 | } |
| 3289 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3290 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3291 | if (IS_ERR(label)) |
| 3292 | return PTR_ERR(label); |
| 3293 | |
| 3294 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3295 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3296 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3297 | nfs_setsecurity(inode, fattr, label); |
| 3298 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3299 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | return status; |
| 3301 | } |
| 3302 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3303 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3304 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3305 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3306 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3307 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3308 | int status; |
| 3309 | struct nfs4_lookup_arg args = { |
| 3310 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3311 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3312 | .name = name, |
| 3313 | }; |
| 3314 | struct nfs4_lookup_res res = { |
| 3315 | .server = server, |
| 3316 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3317 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3318 | .fh = fhandle, |
| 3319 | }; |
| 3320 | struct rpc_message msg = { |
| 3321 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3322 | .rpc_argp = &args, |
| 3323 | .rpc_resp = &res, |
| 3324 | }; |
| 3325 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3326 | args.bitmask = nfs4_bitmask(server, label); |
| 3327 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3328 | nfs_fattr_init(fattr); |
| 3329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3331 | 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] | 3332 | dprintk("NFS reply lookup: %d\n", status); |
| 3333 | return status; |
| 3334 | } |
| 3335 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3336 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3337 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3338 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3339 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3340 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3341 | fattr->nlink = 2; |
| 3342 | } |
| 3343 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3344 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 3345 | struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3346 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3347 | { |
| 3348 | struct nfs4_exception exception = { }; |
| 3349 | struct rpc_clnt *client = *clnt; |
| 3350 | int err; |
| 3351 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3352 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3353 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3354 | switch (err) { |
| 3355 | case -NFS4ERR_BADNAME: |
| 3356 | err = -ENOENT; |
| 3357 | goto out; |
| 3358 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3359 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3360 | if (err == -NFS4ERR_MOVED) |
| 3361 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3362 | goto out; |
| 3363 | case -NFS4ERR_WRONGSEC: |
| 3364 | err = -EPERM; |
| 3365 | if (client != *clnt) |
| 3366 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3367 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3368 | if (IS_ERR(client)) |
| 3369 | return PTR_ERR(client); |
| 3370 | |
| 3371 | exception.retry = 1; |
| 3372 | break; |
| 3373 | default: |
| 3374 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3375 | } |
| 3376 | } while (exception.retry); |
| 3377 | |
| 3378 | out: |
| 3379 | if (err == 0) |
| 3380 | *clnt = client; |
| 3381 | else if (client != *clnt) |
| 3382 | rpc_shutdown_client(client); |
| 3383 | |
| 3384 | return err; |
| 3385 | } |
| 3386 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3387 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3388 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3389 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3391 | int status; |
| 3392 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3393 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3394 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3395 | if (client != NFS_CLIENT(dir)) { |
| 3396 | rpc_shutdown_client(client); |
| 3397 | nfs_fixup_secinfo_attributes(fattr); |
| 3398 | } |
| 3399 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3402 | struct rpc_clnt * |
| 3403 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 3404 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3405 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3406 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3407 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3408 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3409 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3410 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3411 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3412 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3413 | } |
| 3414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3416 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3417 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | struct nfs4_accessargs args = { |
| 3419 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3420 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3422 | struct nfs4_accessres res = { |
| 3423 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3424 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | struct rpc_message msg = { |
| 3426 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3427 | .rpc_argp = &args, |
| 3428 | .rpc_resp = &res, |
| 3429 | .rpc_cred = entry->cred, |
| 3430 | }; |
| 3431 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3432 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | |
| 3434 | /* |
| 3435 | * Determine which access bits we want to ask for... |
| 3436 | */ |
| 3437 | if (mode & MAY_READ) |
| 3438 | args.access |= NFS4_ACCESS_READ; |
| 3439 | if (S_ISDIR(inode->i_mode)) { |
| 3440 | if (mode & MAY_WRITE) |
| 3441 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3442 | if (mode & MAY_EXEC) |
| 3443 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3444 | } else { |
| 3445 | if (mode & MAY_WRITE) |
| 3446 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3447 | if (mode & MAY_EXEC) |
| 3448 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3449 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3450 | |
| 3451 | res.fattr = nfs_alloc_fattr(); |
| 3452 | if (res.fattr == NULL) |
| 3453 | return -ENOMEM; |
| 3454 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3455 | 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] | 3456 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3457 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3458 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3460 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | return status; |
| 3462 | } |
| 3463 | |
| 3464 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3465 | { |
| 3466 | struct nfs4_exception exception = { }; |
| 3467 | int err; |
| 3468 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3469 | err = _nfs4_proc_access(inode, entry); |
| 3470 | trace_nfs4_access(inode, err); |
| 3471 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | &exception); |
| 3473 | } while (exception.retry); |
| 3474 | return err; |
| 3475 | } |
| 3476 | |
| 3477 | /* |
| 3478 | * TODO: For the time being, we don't try to get any attributes |
| 3479 | * along with any of the zero-copy operations READ, READDIR, |
| 3480 | * READLINK, WRITE. |
| 3481 | * |
| 3482 | * In the case of the first three, we want to put the GETATTR |
| 3483 | * after the read-type operation -- this is because it is hard |
| 3484 | * to predict the length of a GETATTR response in v4, and thus |
| 3485 | * align the READ data correctly. This means that the GETATTR |
| 3486 | * may end up partially falling into the page cache, and we should |
| 3487 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3488 | * To do this efficiently, we need to know the total length |
| 3489 | * of data received, which doesn't seem to be available outside |
| 3490 | * of the RPC layer. |
| 3491 | * |
| 3492 | * In the case of WRITE, we also want to put the GETATTR after |
| 3493 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3494 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | * |
| 3496 | * Both of these changes to the XDR layer would in fact be quite |
| 3497 | * minor, but I decided to leave them for a subsequent patch. |
| 3498 | */ |
| 3499 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3500 | unsigned int pgbase, unsigned int pglen) |
| 3501 | { |
| 3502 | struct nfs4_readlink args = { |
| 3503 | .fh = NFS_FH(inode), |
| 3504 | .pgbase = pgbase, |
| 3505 | .pglen = pglen, |
| 3506 | .pages = &page, |
| 3507 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3508 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | struct rpc_message msg = { |
| 3510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3511 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3512 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | }; |
| 3514 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3515 | 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] | 3516 | } |
| 3517 | |
| 3518 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3519 | unsigned int pgbase, unsigned int pglen) |
| 3520 | { |
| 3521 | struct nfs4_exception exception = { }; |
| 3522 | int err; |
| 3523 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3524 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3525 | trace_nfs4_readlink(inode, err); |
| 3526 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | &exception); |
| 3528 | } while (exception.retry); |
| 3529 | return err; |
| 3530 | } |
| 3531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3533 | * 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] | 3534 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | static int |
| 3536 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3537 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3539 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3540 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | struct nfs4_state *state; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3542 | int opened = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | int status = 0; |
| 3544 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3545 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3546 | if (IS_ERR(ctx)) |
| 3547 | return PTR_ERR(ctx); |
| 3548 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3549 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3550 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3551 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3552 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | if (IS_ERR(state)) { |
| 3554 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3555 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3558 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3559 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | return status; |
| 3561 | } |
| 3562 | |
| 3563 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3564 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3565 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3566 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3568 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3570 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3571 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3572 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3574 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3575 | .rpc_argp = &args, |
| 3576 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3578 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3579 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3580 | 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] | 3581 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3582 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | return status; |
| 3584 | } |
| 3585 | |
| 3586 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3587 | { |
| 3588 | struct nfs4_exception exception = { }; |
| 3589 | int err; |
| 3590 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3591 | err = _nfs4_proc_remove(dir, name); |
| 3592 | trace_nfs4_remove(dir, name, err); |
| 3593 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | &exception); |
| 3595 | } while (exception.retry); |
| 3596 | return err; |
| 3597 | } |
| 3598 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3599 | 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] | 3600 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3601 | struct nfs_server *server = NFS_SERVER(dir); |
| 3602 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3603 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3605 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3607 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3608 | |
| 3609 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3612 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3613 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3614 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3615 | &data->args.seq_args, |
| 3616 | &data->res.seq_res, |
| 3617 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3620 | 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] | 3621 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3622 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3623 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3624 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3625 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3626 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3627 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3628 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3629 | return 0; |
| 3630 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3631 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3634 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3635 | { |
| 3636 | struct nfs_server *server = NFS_SERVER(dir); |
| 3637 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3638 | struct nfs_renameres *res = msg->rpc_resp; |
| 3639 | |
| 3640 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3641 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3642 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3643 | } |
| 3644 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3645 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3646 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3647 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3648 | &data->args.seq_args, |
| 3649 | &data->res.seq_res, |
| 3650 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3654 | struct inode *new_dir) |
| 3655 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3656 | struct nfs_renamedata *data = task->tk_calldata; |
| 3657 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3658 | |
| 3659 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3660 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3661 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3662 | return 0; |
| 3663 | |
| 3664 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3665 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3666 | return 1; |
| 3667 | } |
| 3668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3670 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3671 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | struct nfs4_link_arg arg = { |
| 3673 | .fh = NFS_FH(inode), |
| 3674 | .dir_fh = NFS_FH(dir), |
| 3675 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3676 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3678 | struct nfs4_link_res res = { |
| 3679 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3680 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3681 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | struct rpc_message msg = { |
| 3683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3684 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3685 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3687 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3689 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3690 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3691 | goto out; |
| 3692 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3693 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3694 | if (IS_ERR(res.label)) { |
| 3695 | status = PTR_ERR(res.label); |
| 3696 | goto out; |
| 3697 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3698 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3699 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3700 | 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] | 3701 | if (!status) { |
| 3702 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3703 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3704 | if (!status) |
| 3705 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3706 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3707 | |
| 3708 | |
| 3709 | nfs4_label_free(res.label); |
| 3710 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3711 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3712 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | return status; |
| 3714 | } |
| 3715 | |
| 3716 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3717 | { |
| 3718 | struct nfs4_exception exception = { }; |
| 3719 | int err; |
| 3720 | do { |
| 3721 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3722 | _nfs4_proc_link(inode, dir, name), |
| 3723 | &exception); |
| 3724 | } while (exception.retry); |
| 3725 | return err; |
| 3726 | } |
| 3727 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3728 | struct nfs4_createdata { |
| 3729 | struct rpc_message msg; |
| 3730 | struct nfs4_create_arg arg; |
| 3731 | struct nfs4_create_res res; |
| 3732 | struct nfs_fh fh; |
| 3733 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3734 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3735 | }; |
| 3736 | |
| 3737 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3738 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3739 | { |
| 3740 | struct nfs4_createdata *data; |
| 3741 | |
| 3742 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3743 | if (data != NULL) { |
| 3744 | struct nfs_server *server = NFS_SERVER(dir); |
| 3745 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3746 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3747 | if (IS_ERR(data->label)) |
| 3748 | goto out_free; |
| 3749 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3750 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3751 | data->msg.rpc_argp = &data->arg; |
| 3752 | data->msg.rpc_resp = &data->res; |
| 3753 | data->arg.dir_fh = NFS_FH(dir); |
| 3754 | data->arg.server = server; |
| 3755 | data->arg.name = name; |
| 3756 | data->arg.attrs = sattr; |
| 3757 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3758 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3759 | data->res.server = server; |
| 3760 | data->res.fh = &data->fh; |
| 3761 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3762 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3763 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3764 | } |
| 3765 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3766 | out_free: |
| 3767 | kfree(data); |
| 3768 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3772 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3773 | 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] | 3774 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3775 | if (status == 0) { |
| 3776 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3777 | 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] | 3778 | } |
| 3779 | return status; |
| 3780 | } |
| 3781 | |
| 3782 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3783 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3784 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3785 | kfree(data); |
| 3786 | } |
| 3787 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3788 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3789 | struct page *page, unsigned int len, struct iattr *sattr, |
| 3790 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3792 | struct nfs4_createdata *data; |
| 3793 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3795 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3796 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3797 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3798 | status = -ENOMEM; |
| 3799 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3800 | if (data == NULL) |
| 3801 | goto out; |
| 3802 | |
| 3803 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3804 | data->arg.u.symlink.pages = &page; |
| 3805 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3806 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3808 | status = nfs4_do_create(dir, dentry, data); |
| 3809 | |
| 3810 | nfs4_free_createdata(data); |
| 3811 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | return status; |
| 3813 | } |
| 3814 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3815 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3816 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | { |
| 3818 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3819 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3821 | |
| 3822 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3825 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 3826 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 3827 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | &exception); |
| 3829 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3830 | |
| 3831 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | return err; |
| 3833 | } |
| 3834 | |
| 3835 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3836 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3838 | struct nfs4_createdata *data; |
| 3839 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3841 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3842 | if (data == NULL) |
| 3843 | goto out; |
| 3844 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3845 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3846 | status = nfs4_do_create(dir, dentry, data); |
| 3847 | |
| 3848 | nfs4_free_createdata(data); |
| 3849 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | return status; |
| 3851 | } |
| 3852 | |
| 3853 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3854 | struct iattr *sattr) |
| 3855 | { |
| 3856 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3857 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3859 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3860 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3861 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3862 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3864 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 3865 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 3866 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | &exception); |
| 3868 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3869 | nfs4_label_release_security(label); |
| 3870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | return err; |
| 3872 | } |
| 3873 | |
| 3874 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3875 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3877 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | struct nfs4_readdir_arg args = { |
| 3879 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3880 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | .pgbase = 0, |
| 3882 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3883 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3884 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 | }; |
| 3886 | struct nfs4_readdir_res res; |
| 3887 | struct rpc_message msg = { |
| 3888 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3889 | .rpc_argp = &args, |
| 3890 | .rpc_resp = &res, |
| 3891 | .rpc_cred = cred, |
| 3892 | }; |
| 3893 | int status; |
| 3894 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 3895 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 3896 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3897 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3898 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3900 | 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] | 3901 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3902 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3903 | status += args.pgbase; |
| 3904 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3905 | |
| 3906 | nfs_invalidate_atime(dir); |
| 3907 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3908 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | return status; |
| 3910 | } |
| 3911 | |
| 3912 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3913 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | { |
| 3915 | struct nfs4_exception exception = { }; |
| 3916 | int err; |
| 3917 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3918 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 3919 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3920 | trace_nfs4_readdir(d_inode(dentry), err); |
| 3921 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | &exception); |
| 3923 | } while (exception.retry); |
| 3924 | return err; |
| 3925 | } |
| 3926 | |
| 3927 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3928 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3930 | struct nfs4_createdata *data; |
| 3931 | int mode = sattr->ia_mode; |
| 3932 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3934 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3935 | if (data == NULL) |
| 3936 | goto out; |
| 3937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3939 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3941 | data->arg.ftype = NF4BLK; |
| 3942 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3943 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | } |
| 3945 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3946 | data->arg.ftype = NF4CHR; |
| 3947 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3948 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3949 | } else if (!S_ISSOCK(mode)) { |
| 3950 | status = -EINVAL; |
| 3951 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3953 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3954 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3955 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3956 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3957 | nfs4_free_createdata(data); |
| 3958 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | return status; |
| 3960 | } |
| 3961 | |
| 3962 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3963 | struct iattr *sattr, dev_t rdev) |
| 3964 | { |
| 3965 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3966 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3968 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3969 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3970 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3971 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3973 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 3974 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 3975 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | &exception); |
| 3977 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3978 | |
| 3979 | nfs4_label_release_security(label); |
| 3980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | return err; |
| 3982 | } |
| 3983 | |
| 3984 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3985 | struct nfs_fsstat *fsstat) |
| 3986 | { |
| 3987 | struct nfs4_statfs_arg args = { |
| 3988 | .fh = fhandle, |
| 3989 | .bitmask = server->attr_bitmask, |
| 3990 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3991 | struct nfs4_statfs_res res = { |
| 3992 | .fsstat = fsstat, |
| 3993 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | struct rpc_message msg = { |
| 3995 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3996 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3997 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | }; |
| 3999 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4000 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4001 | 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] | 4002 | } |
| 4003 | |
| 4004 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4005 | { |
| 4006 | struct nfs4_exception exception = { }; |
| 4007 | int err; |
| 4008 | do { |
| 4009 | err = nfs4_handle_exception(server, |
| 4010 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4011 | &exception); |
| 4012 | } while (exception.retry); |
| 4013 | return err; |
| 4014 | } |
| 4015 | |
| 4016 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4017 | struct nfs_fsinfo *fsinfo) |
| 4018 | { |
| 4019 | struct nfs4_fsinfo_arg args = { |
| 4020 | .fh = fhandle, |
| 4021 | .bitmask = server->attr_bitmask, |
| 4022 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4023 | struct nfs4_fsinfo_res res = { |
| 4024 | .fsinfo = fsinfo, |
| 4025 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | struct rpc_message msg = { |
| 4027 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4028 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4029 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | }; |
| 4031 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4032 | 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] | 4033 | } |
| 4034 | |
| 4035 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4036 | { |
| 4037 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4038 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | int err; |
| 4040 | |
| 4041 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4042 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4043 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4044 | if (err == 0) { |
| 4045 | struct nfs_client *clp = server->nfs_client; |
| 4046 | |
| 4047 | spin_lock(&clp->cl_lock); |
| 4048 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 4049 | clp->cl_last_renewal = now; |
| 4050 | spin_unlock(&clp->cl_lock); |
| 4051 | break; |
| 4052 | } |
| 4053 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | } while (exception.retry); |
| 4055 | return err; |
| 4056 | } |
| 4057 | |
| 4058 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4059 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4060 | int error; |
| 4061 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4062 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4063 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4064 | if (error == 0) { |
| 4065 | /* block layout checks this! */ |
| 4066 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4067 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4068 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4069 | |
| 4070 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4074 | struct nfs_pathconf *pathconf) |
| 4075 | { |
| 4076 | struct nfs4_pathconf_arg args = { |
| 4077 | .fh = fhandle, |
| 4078 | .bitmask = server->attr_bitmask, |
| 4079 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4080 | struct nfs4_pathconf_res res = { |
| 4081 | .pathconf = pathconf, |
| 4082 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | struct rpc_message msg = { |
| 4084 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4085 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4086 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | }; |
| 4088 | |
| 4089 | /* None of the pathconf attributes are mandatory to implement */ |
| 4090 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4091 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4092 | return 0; |
| 4093 | } |
| 4094 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4095 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4096 | 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] | 4097 | } |
| 4098 | |
| 4099 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4100 | struct nfs_pathconf *pathconf) |
| 4101 | { |
| 4102 | struct nfs4_exception exception = { }; |
| 4103 | int err; |
| 4104 | |
| 4105 | do { |
| 4106 | err = nfs4_handle_exception(server, |
| 4107 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4108 | &exception); |
| 4109 | } while (exception.retry); |
| 4110 | return err; |
| 4111 | } |
| 4112 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4113 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4114 | const struct nfs_open_context *ctx, |
| 4115 | const struct nfs_lock_context *l_ctx, |
| 4116 | fmode_t fmode) |
| 4117 | { |
| 4118 | const struct nfs_lockowner *lockowner = NULL; |
| 4119 | |
| 4120 | if (l_ctx != NULL) |
| 4121 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4122 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4123 | } |
| 4124 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4125 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4126 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4127 | const struct nfs_open_context *ctx, |
| 4128 | const struct nfs_lock_context *l_ctx, |
| 4129 | fmode_t fmode) |
| 4130 | { |
| 4131 | nfs4_stateid current_stateid; |
| 4132 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4133 | /* If the current stateid represents a lost lock, then exit */ |
| 4134 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4135 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4136 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4137 | } |
| 4138 | |
| 4139 | static bool nfs4_error_stateid_expired(int err) |
| 4140 | { |
| 4141 | switch (err) { |
| 4142 | case -NFS4ERR_DELEG_REVOKED: |
| 4143 | case -NFS4ERR_ADMIN_REVOKED: |
| 4144 | case -NFS4ERR_BAD_STATEID: |
| 4145 | case -NFS4ERR_STALE_STATEID: |
| 4146 | case -NFS4ERR_OLD_STATEID: |
| 4147 | case -NFS4ERR_OPENMODE: |
| 4148 | case -NFS4ERR_EXPIRED: |
| 4149 | return true; |
| 4150 | } |
| 4151 | return false; |
| 4152 | } |
| 4153 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4154 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4155 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4156 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4157 | } |
| 4158 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4159 | 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] | 4160 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4161 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4163 | trace_nfs4_read(hdr, task->tk_status); |
| 4164 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4165 | hdr->args.context->state, |
| 4166 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4167 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4168 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4170 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4171 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4173 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4174 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | } |
| 4176 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4177 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4178 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4179 | { |
| 4180 | |
| 4181 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4182 | nfs4_stateid_is_current(&args->stateid, |
| 4183 | args->context, |
| 4184 | args->lock_context, |
| 4185 | FMODE_READ)) |
| 4186 | return false; |
| 4187 | rpc_restart_call_prepare(task); |
| 4188 | return true; |
| 4189 | } |
| 4190 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4191 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4192 | { |
| 4193 | |
| 4194 | dprintk("--> %s\n", __func__); |
| 4195 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4196 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4197 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4198 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4199 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4200 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4201 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4204 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4205 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4207 | hdr->timestamp = jiffies; |
| 4208 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4209 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4210 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | } |
| 4212 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4213 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4214 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4215 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4216 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4217 | &hdr->args.seq_args, |
| 4218 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4219 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4220 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4221 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4222 | hdr->args.lock_context, |
| 4223 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4224 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4225 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4226 | return -EIO; |
| 4227 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4230 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4231 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4233 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4234 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4235 | trace_nfs4_write(hdr, task->tk_status); |
| 4236 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4237 | hdr->args.context->state, |
| 4238 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4239 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4240 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4242 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4243 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4244 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4245 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4246 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4249 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4250 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4251 | { |
| 4252 | |
| 4253 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4254 | nfs4_stateid_is_current(&args->stateid, |
| 4255 | args->context, |
| 4256 | args->lock_context, |
| 4257 | FMODE_WRITE)) |
| 4258 | return false; |
| 4259 | rpc_restart_call_prepare(task); |
| 4260 | return true; |
| 4261 | } |
| 4262 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4263 | 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] | 4264 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4265 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4266 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4267 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4268 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4269 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4270 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4273 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4274 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4275 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4276 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4277 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4278 | return false; |
| 4279 | /* Otherwise, request attributes if and only if we don't hold |
| 4280 | * a delegation |
| 4281 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4282 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4283 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4284 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4285 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4286 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4288 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4289 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4290 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4291 | hdr->args.bitmask = NULL; |
| 4292 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4293 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4294 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4295 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4296 | if (!hdr->pgio_done_cb) |
| 4297 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4298 | hdr->res.server = server; |
| 4299 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4301 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4302 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4305 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4306 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4307 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4308 | &data->args.seq_args, |
| 4309 | &data->res.seq_res, |
| 4310 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | } |
| 4312 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4313 | 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] | 4314 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4316 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4317 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4318 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4319 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4320 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4321 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4323 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4326 | 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] | 4327 | { |
| 4328 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4329 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4330 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4333 | 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] | 4334 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4335 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4336 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4337 | if (data->commit_done_cb == NULL) |
| 4338 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4339 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4340 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4341 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4344 | struct nfs4_renewdata { |
| 4345 | struct nfs_client *client; |
| 4346 | unsigned long timestamp; |
| 4347 | }; |
| 4348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | /* |
| 4350 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4351 | * standalone procedure for queueing an asynchronous RENEW. |
| 4352 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4353 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4354 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4355 | struct nfs4_renewdata *data = calldata; |
| 4356 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4357 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4358 | if (atomic_read(&clp->cl_count) > 1) |
| 4359 | nfs4_schedule_state_renewal(clp); |
| 4360 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4361 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4362 | } |
| 4363 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4364 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4366 | struct nfs4_renewdata *data = calldata; |
| 4367 | struct nfs_client *clp = data->client; |
| 4368 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4370 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4371 | switch (task->tk_status) { |
| 4372 | case 0: |
| 4373 | break; |
| 4374 | case -NFS4ERR_LEASE_MOVED: |
| 4375 | nfs4_schedule_lease_moved_recovery(clp); |
| 4376 | break; |
| 4377 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4378 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4379 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4380 | return; |
| 4381 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4382 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4383 | return; |
| 4384 | } |
| 4385 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4387 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4390 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4391 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4392 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4393 | }; |
| 4394 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4395 | 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] | 4396 | { |
| 4397 | struct rpc_message msg = { |
| 4398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4399 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4400 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4402 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4404 | if (renew_flags == 0) |
| 4405 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4406 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4407 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4408 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4409 | if (data == NULL) |
| 4410 | return -ENOMEM; |
| 4411 | data->client = clp; |
| 4412 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4413 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4414 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4417 | 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] | 4418 | { |
| 4419 | struct rpc_message msg = { |
| 4420 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4421 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4422 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | }; |
| 4424 | unsigned long now = jiffies; |
| 4425 | int status; |
| 4426 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4427 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | if (status < 0) |
| 4429 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4430 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | return 0; |
| 4432 | } |
| 4433 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4434 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4435 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4436 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4437 | } |
| 4438 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4439 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4440 | * 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] | 4441 | * the stack. |
| 4442 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4443 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4444 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4445 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 4446 | struct page **pages, unsigned int *pgbase) |
| 4447 | { |
| 4448 | struct page *newpage, **spages; |
| 4449 | int rc = 0; |
| 4450 | size_t len; |
| 4451 | spages = pages; |
| 4452 | |
| 4453 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4454 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4455 | newpage = alloc_page(GFP_KERNEL); |
| 4456 | |
| 4457 | if (newpage == NULL) |
| 4458 | goto unwind; |
| 4459 | memcpy(page_address(newpage), buf, len); |
| 4460 | buf += len; |
| 4461 | buflen -= len; |
| 4462 | *pages++ = newpage; |
| 4463 | rc++; |
| 4464 | } while (buflen != 0); |
| 4465 | |
| 4466 | return rc; |
| 4467 | |
| 4468 | unwind: |
| 4469 | for(; rc > 0; rc--) |
| 4470 | __free_page(spages[rc-1]); |
| 4471 | return -ENOMEM; |
| 4472 | } |
| 4473 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4474 | struct nfs4_cached_acl { |
| 4475 | int cached; |
| 4476 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4477 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4478 | }; |
| 4479 | |
| 4480 | 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] | 4481 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4482 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4483 | |
| 4484 | spin_lock(&inode->i_lock); |
| 4485 | kfree(nfsi->nfs4_acl); |
| 4486 | nfsi->nfs4_acl = acl; |
| 4487 | spin_unlock(&inode->i_lock); |
| 4488 | } |
| 4489 | |
| 4490 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4491 | { |
| 4492 | nfs4_set_cached_acl(inode, NULL); |
| 4493 | } |
| 4494 | |
| 4495 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4496 | { |
| 4497 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4498 | struct nfs4_cached_acl *acl; |
| 4499 | int ret = -ENOENT; |
| 4500 | |
| 4501 | spin_lock(&inode->i_lock); |
| 4502 | acl = nfsi->nfs4_acl; |
| 4503 | if (acl == NULL) |
| 4504 | goto out; |
| 4505 | if (buf == NULL) /* user is just asking for length */ |
| 4506 | goto out_len; |
| 4507 | if (acl->cached == 0) |
| 4508 | goto out; |
| 4509 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4510 | if (acl->len > buflen) |
| 4511 | goto out; |
| 4512 | memcpy(buf, acl->data, acl->len); |
| 4513 | out_len: |
| 4514 | ret = acl->len; |
| 4515 | out: |
| 4516 | spin_unlock(&inode->i_lock); |
| 4517 | return ret; |
| 4518 | } |
| 4519 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4520 | 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] | 4521 | { |
| 4522 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4523 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4524 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4525 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4526 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4527 | if (acl == NULL) |
| 4528 | goto out; |
| 4529 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4530 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4531 | } else { |
| 4532 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4533 | if (acl == NULL) |
| 4534 | goto out; |
| 4535 | acl->cached = 0; |
| 4536 | } |
| 4537 | acl->len = acl_len; |
| 4538 | out: |
| 4539 | nfs4_set_cached_acl(inode, acl); |
| 4540 | } |
| 4541 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4542 | /* |
| 4543 | * The getxattr API returns the required buffer length when called with a |
| 4544 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4545 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4546 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4547 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4548 | * the cache. If not so, we throw away the page, and cache the required |
| 4549 | * length. The next getxattr call will then produce another round trip to |
| 4550 | * the server, this time with the input buf of the required size. |
| 4551 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4552 | 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] | 4553 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4554 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4555 | struct nfs_getaclargs args = { |
| 4556 | .fh = NFS_FH(inode), |
| 4557 | .acl_pages = pages, |
| 4558 | .acl_len = buflen, |
| 4559 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4560 | struct nfs_getaclres res = { |
| 4561 | .acl_len = buflen, |
| 4562 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4563 | struct rpc_message msg = { |
| 4564 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4565 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4566 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4567 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4568 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4569 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4570 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4571 | /* As long as we're doing a round trip to the server anyway, |
| 4572 | * let's be prepared for a page of acl data. */ |
| 4573 | if (npages == 0) |
| 4574 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4575 | if (npages > ARRAY_SIZE(pages)) |
| 4576 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4577 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4578 | for (i = 0; i < npages; i++) { |
| 4579 | pages[i] = alloc_page(GFP_KERNEL); |
| 4580 | if (!pages[i]) |
| 4581 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4582 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4583 | |
| 4584 | /* for decoding across pages */ |
| 4585 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4586 | if (!res.acl_scratch) |
| 4587 | goto out_free; |
| 4588 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4589 | args.acl_len = npages * PAGE_SIZE; |
| 4590 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4591 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4592 | 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] | 4593 | __func__, buf, buflen, npages, args.acl_len); |
| 4594 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4595 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4596 | if (ret) |
| 4597 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4598 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4599 | /* Handle the case where the passed-in buffer is too short */ |
| 4600 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4601 | /* Did the user only issue a request for the acl length? */ |
| 4602 | if (buf == NULL) |
| 4603 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4604 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4605 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4606 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4607 | 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] | 4608 | if (buf) { |
| 4609 | if (res.acl_len > buflen) { |
| 4610 | ret = -ERANGE; |
| 4611 | goto out_free; |
| 4612 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4613 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4614 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4615 | out_ok: |
| 4616 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4617 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4618 | for (i = 0; i < npages; i++) |
| 4619 | if (pages[i]) |
| 4620 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4621 | if (res.acl_scratch) |
| 4622 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4623 | return ret; |
| 4624 | } |
| 4625 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4626 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4627 | { |
| 4628 | struct nfs4_exception exception = { }; |
| 4629 | ssize_t ret; |
| 4630 | do { |
| 4631 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4632 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4633 | if (ret >= 0) |
| 4634 | break; |
| 4635 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4636 | } while (exception.retry); |
| 4637 | return ret; |
| 4638 | } |
| 4639 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4640 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4641 | { |
| 4642 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4643 | int ret; |
| 4644 | |
| 4645 | if (!nfs4_server_supports_acls(server)) |
| 4646 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4647 | ret = nfs_revalidate_inode(server, inode); |
| 4648 | if (ret < 0) |
| 4649 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4650 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4651 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4652 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4653 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4654 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4655 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4656 | return ret; |
| 4657 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4658 | } |
| 4659 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4660 | 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] | 4661 | { |
| 4662 | struct nfs_server *server = NFS_SERVER(inode); |
| 4663 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4664 | struct nfs_setaclargs arg = { |
| 4665 | .fh = NFS_FH(inode), |
| 4666 | .acl_pages = pages, |
| 4667 | .acl_len = buflen, |
| 4668 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4669 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4670 | struct rpc_message msg = { |
| 4671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4672 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4673 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4674 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4675 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4676 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4677 | |
| 4678 | if (!nfs4_server_supports_acls(server)) |
| 4679 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4680 | if (npages > ARRAY_SIZE(pages)) |
| 4681 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4682 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4683 | if (i < 0) |
| 4684 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4685 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4686 | 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] | 4687 | |
| 4688 | /* |
| 4689 | * Free each page after tx, so the only ref left is |
| 4690 | * held by the network stack |
| 4691 | */ |
| 4692 | for (; i > 0; i--) |
| 4693 | put_page(pages[i-1]); |
| 4694 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4695 | /* |
| 4696 | * Acl update can result in inode attribute update. |
| 4697 | * so mark the attribute cache invalid. |
| 4698 | */ |
| 4699 | spin_lock(&inode->i_lock); |
| 4700 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4701 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4702 | nfs_access_zap_cache(inode); |
| 4703 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4704 | return ret; |
| 4705 | } |
| 4706 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4707 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4708 | { |
| 4709 | struct nfs4_exception exception = { }; |
| 4710 | int err; |
| 4711 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4712 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4713 | trace_nfs4_set_acl(inode, err); |
| 4714 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4715 | &exception); |
| 4716 | } while (exception.retry); |
| 4717 | return err; |
| 4718 | } |
| 4719 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4720 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4721 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4722 | size_t buflen) |
| 4723 | { |
| 4724 | struct nfs_server *server = NFS_SERVER(inode); |
| 4725 | struct nfs_fattr fattr; |
| 4726 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4727 | |
| 4728 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4729 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4730 | .fh = NFS_FH(inode), |
| 4731 | .bitmask = bitmask, |
| 4732 | }; |
| 4733 | struct nfs4_getattr_res res = { |
| 4734 | .fattr = &fattr, |
| 4735 | .label = &label, |
| 4736 | .server = server, |
| 4737 | }; |
| 4738 | struct rpc_message msg = { |
| 4739 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4740 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4741 | .rpc_resp = &res, |
| 4742 | }; |
| 4743 | int ret; |
| 4744 | |
| 4745 | nfs_fattr_init(&fattr); |
| 4746 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4747 | 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] | 4748 | if (ret) |
| 4749 | return ret; |
| 4750 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 4751 | return -ENOENT; |
| 4752 | if (buflen < label.len) |
| 4753 | return -ERANGE; |
| 4754 | return 0; |
| 4755 | } |
| 4756 | |
| 4757 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 4758 | size_t buflen) |
| 4759 | { |
| 4760 | struct nfs4_exception exception = { }; |
| 4761 | int err; |
| 4762 | |
| 4763 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4764 | return -EOPNOTSUPP; |
| 4765 | |
| 4766 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4767 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 4768 | trace_nfs4_get_security_label(inode, err); |
| 4769 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4770 | &exception); |
| 4771 | } while (exception.retry); |
| 4772 | return err; |
| 4773 | } |
| 4774 | |
| 4775 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 4776 | struct nfs4_label *ilabel, |
| 4777 | struct nfs_fattr *fattr, |
| 4778 | struct nfs4_label *olabel) |
| 4779 | { |
| 4780 | |
| 4781 | struct iattr sattr = {0}; |
| 4782 | struct nfs_server *server = NFS_SERVER(inode); |
| 4783 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4784 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4785 | .fh = NFS_FH(inode), |
| 4786 | .iap = &sattr, |
| 4787 | .server = server, |
| 4788 | .bitmask = bitmask, |
| 4789 | .label = ilabel, |
| 4790 | }; |
| 4791 | struct nfs_setattrres res = { |
| 4792 | .fattr = fattr, |
| 4793 | .label = olabel, |
| 4794 | .server = server, |
| 4795 | }; |
| 4796 | struct rpc_message msg = { |
| 4797 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4798 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4799 | .rpc_resp = &res, |
| 4800 | }; |
| 4801 | int status; |
| 4802 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4803 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4804 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 4805 | 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] | 4806 | if (status) |
| 4807 | dprintk("%s failed: %d\n", __func__, status); |
| 4808 | |
| 4809 | return status; |
| 4810 | } |
| 4811 | |
| 4812 | static int nfs4_do_set_security_label(struct inode *inode, |
| 4813 | struct nfs4_label *ilabel, |
| 4814 | struct nfs_fattr *fattr, |
| 4815 | struct nfs4_label *olabel) |
| 4816 | { |
| 4817 | struct nfs4_exception exception = { }; |
| 4818 | int err; |
| 4819 | |
| 4820 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4821 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 4822 | fattr, olabel); |
| 4823 | trace_nfs4_set_security_label(inode, err); |
| 4824 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4825 | &exception); |
| 4826 | } while (exception.retry); |
| 4827 | return err; |
| 4828 | } |
| 4829 | |
| 4830 | static int |
| 4831 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) |
| 4832 | { |
| 4833 | struct nfs4_label ilabel, *olabel = NULL; |
| 4834 | struct nfs_fattr fattr; |
| 4835 | struct rpc_cred *cred; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4836 | struct inode *inode = d_inode(dentry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4837 | int status; |
| 4838 | |
| 4839 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 4840 | return -EOPNOTSUPP; |
| 4841 | |
| 4842 | nfs_fattr_init(&fattr); |
| 4843 | |
| 4844 | ilabel.pi = 0; |
| 4845 | ilabel.lfs = 0; |
| 4846 | ilabel.label = (char *)buf; |
| 4847 | ilabel.len = buflen; |
| 4848 | |
| 4849 | cred = rpc_lookup_cred(); |
| 4850 | if (IS_ERR(cred)) |
| 4851 | return PTR_ERR(cred); |
| 4852 | |
| 4853 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 4854 | if (IS_ERR(olabel)) { |
| 4855 | status = -PTR_ERR(olabel); |
| 4856 | goto out; |
| 4857 | } |
| 4858 | |
| 4859 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 4860 | if (status == 0) |
| 4861 | nfs_setsecurity(inode, &fattr, olabel); |
| 4862 | |
| 4863 | nfs4_label_free(olabel); |
| 4864 | out: |
| 4865 | put_rpccred(cred); |
| 4866 | return status; |
| 4867 | } |
| 4868 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 4869 | |
| 4870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | static int |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4872 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, |
| 4873 | struct nfs4_state *state, long *timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4875 | struct nfs_client *clp = server->nfs_client; |
| 4876 | |
| 4877 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | return 0; |
| 4879 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4880 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4881 | case -NFS4ERR_ADMIN_REVOKED: |
| 4882 | case -NFS4ERR_BAD_STATEID: |
| 4883 | case -NFS4ERR_OPENMODE: |
| 4884 | if (state == NULL) |
| 4885 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4886 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4887 | goto recovery_failed; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4888 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4889 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4890 | if (state != NULL) { |
| 4891 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4892 | goto recovery_failed; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4893 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4895 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4896 | nfs4_schedule_lease_recovery(clp); |
| 4897 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4898 | case -NFS4ERR_MOVED: |
| 4899 | if (nfs4_schedule_migration_recovery(server) < 0) |
| 4900 | goto recovery_failed; |
| 4901 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 4902 | case -NFS4ERR_LEASE_MOVED: |
| 4903 | nfs4_schedule_lease_moved_recovery(clp); |
| 4904 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4905 | #if defined(CONFIG_NFS_V4_1) |
| 4906 | case -NFS4ERR_BADSESSION: |
| 4907 | case -NFS4ERR_BADSLOT: |
| 4908 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4909 | case -NFS4ERR_DEADSESSION: |
| 4910 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4911 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4912 | case -NFS4ERR_SEQ_MISORDERED: |
| 4913 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4914 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4915 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4a82fd7 | 2013-11-15 16:36:16 -0500 | [diff] [blame] | 4916 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4917 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4919 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4920 | rpc_delay(task, nfs4_update_delay(timeout)); |
| 4921 | goto restart_call; |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4922 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4924 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | case -NFS4ERR_OLD_STATEID: |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4926 | goto restart_call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | } |
| 4928 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4929 | return 0; |
Chuck Lever | 9f51a78 | 2013-10-17 14:13:13 -0400 | [diff] [blame] | 4930 | recovery_failed: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4931 | task->tk_status = -EIO; |
| 4932 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4933 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4934 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4935 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4936 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 4937 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 4938 | goto recovery_failed; |
Chuck Lever | f1478c1 | 2013-10-17 14:13:07 -0400 | [diff] [blame] | 4939 | restart_call: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4940 | task->tk_status = 0; |
| 4941 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4944 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4945 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4946 | { |
| 4947 | __be32 verf[2]; |
| 4948 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4949 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4950 | /* An impossible timestamp guarantees this value |
| 4951 | * will never match a generated boot time. */ |
| 4952 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4953 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4954 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4955 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4956 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 4957 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4958 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4959 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4960 | } |
| 4961 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 4962 | static int |
| 4963 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4964 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 4965 | int result; |
| 4966 | size_t len; |
| 4967 | char *str; |
| 4968 | bool retried = false; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4969 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4970 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 4971 | return 0; |
| 4972 | retry: |
| 4973 | rcu_read_lock(); |
| 4974 | len = 10 + strlen(clp->cl_ipaddr) + 1 + |
| 4975 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 4976 | 1 + |
| 4977 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 4978 | 1; |
| 4979 | rcu_read_unlock(); |
| 4980 | |
| 4981 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 4982 | return -EINVAL; |
| 4983 | |
| 4984 | /* |
| 4985 | * Since this string is allocated at mount time, and held until the |
| 4986 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 4987 | * about a memory-reclaim deadlock. |
| 4988 | */ |
| 4989 | str = kmalloc(len, GFP_KERNEL); |
| 4990 | if (!str) |
| 4991 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 4992 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4993 | rcu_read_lock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 4994 | result = scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
| 4995 | clp->cl_ipaddr, |
| 4996 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 4997 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4998 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 4999 | |
| 5000 | /* Did something change? */ |
| 5001 | if (result >= len) { |
| 5002 | kfree(str); |
| 5003 | if (retried) |
| 5004 | return -EINVAL; |
| 5005 | retried = true; |
| 5006 | goto retry; |
| 5007 | } |
| 5008 | clp->cl_owner_id = str; |
| 5009 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5010 | } |
| 5011 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5012 | static int |
| 5013 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5014 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5015 | int result; |
| 5016 | size_t len; |
| 5017 | char *str; |
| 5018 | |
| 5019 | len = 10 + 10 + 1 + 10 + 1 + |
| 5020 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5021 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5022 | |
| 5023 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5024 | return -EINVAL; |
| 5025 | |
| 5026 | /* |
| 5027 | * Since this string is allocated at mount time, and held until the |
| 5028 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5029 | * about a memory-reclaim deadlock. |
| 5030 | */ |
| 5031 | str = kmalloc(len, GFP_KERNEL); |
| 5032 | if (!str) |
| 5033 | return -ENOMEM; |
| 5034 | |
| 5035 | result = scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
| 5036 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5037 | nfs4_client_id_uniquifier, |
| 5038 | clp->cl_rpcclient->cl_nodename); |
| 5039 | if (result >= len) { |
| 5040 | kfree(str); |
| 5041 | return -EINVAL; |
| 5042 | } |
| 5043 | clp->cl_owner_id = str; |
| 5044 | return 0; |
| 5045 | } |
| 5046 | |
| 5047 | static int |
| 5048 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5049 | { |
| 5050 | int result; |
| 5051 | size_t len; |
| 5052 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5053 | |
| 5054 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5055 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5056 | |
| 5057 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5058 | return nfs4_init_uniquifier_client_string(clp); |
| 5059 | |
| 5060 | len = 10 + 10 + 1 + 10 + 1 + |
| 5061 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5062 | |
| 5063 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5064 | return -EINVAL; |
| 5065 | |
| 5066 | /* |
| 5067 | * Since this string is allocated at mount time, and held until the |
| 5068 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5069 | * about a memory-reclaim deadlock. |
| 5070 | */ |
| 5071 | str = kmalloc(len, GFP_KERNEL); |
| 5072 | if (!str) |
| 5073 | return -ENOMEM; |
| 5074 | |
| 5075 | result = scnprintf(str, len, "Linux NFSv%u.%u %s", |
| 5076 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5077 | clp->cl_rpcclient->cl_nodename); |
| 5078 | if (result >= len) { |
| 5079 | kfree(str); |
| 5080 | return -EINVAL; |
| 5081 | } |
| 5082 | clp->cl_owner_id = str; |
| 5083 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5084 | } |
| 5085 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5086 | /* |
| 5087 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5088 | * services. Advertise one based on the address family of the |
| 5089 | * clientaddr. |
| 5090 | */ |
| 5091 | static unsigned int |
| 5092 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5093 | { |
| 5094 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5095 | return scnprintf(buf, len, "tcp6"); |
| 5096 | else |
| 5097 | return scnprintf(buf, len, "tcp"); |
| 5098 | } |
| 5099 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5100 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5101 | { |
| 5102 | struct nfs4_setclientid *sc = calldata; |
| 5103 | |
| 5104 | if (task->tk_status == 0) |
| 5105 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5106 | } |
| 5107 | |
| 5108 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5109 | .rpc_call_done = nfs4_setclientid_done, |
| 5110 | }; |
| 5111 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5112 | /** |
| 5113 | * nfs4_proc_setclientid - Negotiate client ID |
| 5114 | * @clp: state data structure |
| 5115 | * @program: RPC program for NFSv4 callback service |
| 5116 | * @port: IP port number for NFS4 callback service |
| 5117 | * @cred: RPC credential to use for this call |
| 5118 | * @res: where to place the result |
| 5119 | * |
| 5120 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5121 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5122 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5123 | unsigned short port, struct rpc_cred *cred, |
| 5124 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | { |
| 5126 | nfs4_verifier sc_verifier; |
| 5127 | struct nfs4_setclientid setclientid = { |
| 5128 | .sc_verifier = &sc_verifier, |
| 5129 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5130 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | }; |
| 5132 | struct rpc_message msg = { |
| 5133 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5134 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5135 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5136 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5138 | struct rpc_task *task; |
| 5139 | struct rpc_task_setup task_setup_data = { |
| 5140 | .rpc_client = clp->cl_rpcclient, |
| 5141 | .rpc_message = &msg, |
| 5142 | .callback_ops = &nfs4_setclientid_ops, |
| 5143 | .callback_data = &setclientid, |
| 5144 | .flags = RPC_TASK_TIMEOUT, |
| 5145 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5146 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5148 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5149 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5150 | |
| 5151 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5152 | status = nfs4_init_uniform_client_string(clp); |
| 5153 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5154 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5155 | |
| 5156 | if (status) |
| 5157 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5158 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5159 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5160 | setclientid.sc_netid_len = |
| 5161 | nfs4_init_callback_netid(clp, |
| 5162 | setclientid.sc_netid, |
| 5163 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5164 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5165 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5167 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5168 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5169 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5170 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5171 | task = rpc_run_task(&task_setup_data); |
| 5172 | if (IS_ERR(task)) { |
| 5173 | status = PTR_ERR(task); |
| 5174 | goto out; |
| 5175 | } |
| 5176 | status = task->tk_status; |
| 5177 | if (setclientid.sc_cred) { |
| 5178 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5179 | put_rpccred(setclientid.sc_cred); |
| 5180 | } |
| 5181 | rpc_put_task(task); |
| 5182 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5183 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5184 | dprintk("NFS reply setclientid: %d\n", status); |
| 5185 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5188 | /** |
| 5189 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5190 | * @clp: state data structure |
| 5191 | * @res: result of a previous SETCLIENTID |
| 5192 | * @cred: RPC credential to use for this call |
| 5193 | * |
| 5194 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5195 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5196 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5197 | struct nfs4_setclientid_res *arg, |
| 5198 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | struct rpc_message msg = { |
| 5201 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5202 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5203 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | int status; |
| 5206 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5207 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5208 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5209 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5210 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5211 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5212 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | return status; |
| 5214 | } |
| 5215 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5216 | struct nfs4_delegreturndata { |
| 5217 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5218 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5219 | struct nfs_fh fh; |
| 5220 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5221 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5222 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5223 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5224 | struct inode *inode; |
| 5225 | bool roc; |
| 5226 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5227 | }; |
| 5228 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5229 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5230 | { |
| 5231 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5232 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5233 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5234 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5235 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5236 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5237 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5238 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5239 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5240 | case -NFS4ERR_ADMIN_REVOKED: |
| 5241 | case -NFS4ERR_DELEG_REVOKED: |
| 5242 | case -NFS4ERR_BAD_STATEID: |
| 5243 | case -NFS4ERR_OLD_STATEID: |
| 5244 | case -NFS4ERR_STALE_STATEID: |
| 5245 | case -NFS4ERR_EXPIRED: |
| 5246 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5247 | if (data->roc) |
| 5248 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5249 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5250 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5251 | if (nfs4_async_handle_error(task, data->res.server, |
| 5252 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5253 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5254 | return; |
| 5255 | } |
| 5256 | } |
| 5257 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | static void nfs4_delegreturn_release(void *calldata) |
| 5261 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5262 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5263 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5264 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5265 | if (inode) { |
| 5266 | if (data->roc) |
| 5267 | pnfs_roc_release(inode); |
| 5268 | nfs_iput_and_deactive(inode); |
| 5269 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5270 | kfree(calldata); |
| 5271 | } |
| 5272 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5273 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5274 | { |
| 5275 | struct nfs4_delegreturndata *d_data; |
| 5276 | |
| 5277 | d_data = (struct nfs4_delegreturndata *)data; |
| 5278 | |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5279 | if (d_data->roc && |
| 5280 | pnfs_roc_drain(d_data->inode, &d_data->roc_barrier, task)) |
| 5281 | return; |
| 5282 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5283 | nfs4_setup_sequence(d_data->res.server, |
| 5284 | &d_data->args.seq_args, |
| 5285 | &d_data->res.seq_res, |
| 5286 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5287 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5288 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5289 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5290 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5291 | .rpc_call_done = nfs4_delegreturn_done, |
| 5292 | .rpc_release = nfs4_delegreturn_release, |
| 5293 | }; |
| 5294 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5295 | 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] | 5296 | { |
| 5297 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5298 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5299 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5300 | struct rpc_message msg = { |
| 5301 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5302 | .rpc_cred = cred, |
| 5303 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5304 | struct rpc_task_setup task_setup_data = { |
| 5305 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5306 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5307 | .callback_ops = &nfs4_delegreturn_ops, |
| 5308 | .flags = RPC_TASK_ASYNC, |
| 5309 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5310 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5311 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5312 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5313 | if (data == NULL) |
| 5314 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5315 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5316 | data->args.fhandle = &data->fh; |
| 5317 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5318 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5319 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5320 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5321 | data->res.fattr = &data->fattr; |
| 5322 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5323 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5324 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5325 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5326 | data->inode = nfs_igrab_and_active(inode); |
| 5327 | if (data->inode) |
| 5328 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5329 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5330 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5331 | msg.rpc_argp = &data->args; |
| 5332 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5333 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5334 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5335 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5336 | if (!issync) |
| 5337 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5338 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5339 | if (status != 0) |
| 5340 | goto out; |
| 5341 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5342 | if (status == 0) |
| 5343 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5344 | else |
| 5345 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5346 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5347 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5348 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5351 | 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] | 5352 | { |
| 5353 | struct nfs_server *server = NFS_SERVER(inode); |
| 5354 | struct nfs4_exception exception = { }; |
| 5355 | int err; |
| 5356 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5357 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5358 | trace_nfs4_delegreturn(inode, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | switch (err) { |
| 5360 | case -NFS4ERR_STALE_STATEID: |
| 5361 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | case 0: |
| 5363 | return 0; |
| 5364 | } |
| 5365 | err = nfs4_handle_exception(server, err, &exception); |
| 5366 | } while (exception.retry); |
| 5367 | return err; |
| 5368 | } |
| 5369 | |
| 5370 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 5371 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 5372 | |
| 5373 | /* |
| 5374 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 5375 | */ |
| 5376 | static unsigned long |
| 5377 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 5378 | { |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5379 | freezable_schedule_timeout_killable_unsafe(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | timeout <<= 1; |
| 5381 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 5382 | return NFS4_LOCK_MAXTIMEOUT; |
| 5383 | return timeout; |
| 5384 | } |
| 5385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5387 | { |
| 5388 | struct inode *inode = state->inode; |
| 5389 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5390 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5391 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5392 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5393 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5395 | struct nfs_lockt_res res = { |
| 5396 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | }; |
| 5398 | struct rpc_message msg = { |
| 5399 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5400 | .rpc_argp = &arg, |
| 5401 | .rpc_resp = &res, |
| 5402 | .rpc_cred = state->owner->so_cred, |
| 5403 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | struct nfs4_lock_state *lsp; |
| 5405 | int status; |
| 5406 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5407 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5408 | status = nfs4_set_lock_state(state, request); |
| 5409 | if (status != 0) |
| 5410 | goto out; |
| 5411 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5412 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5413 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5414 | 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] | 5415 | switch (status) { |
| 5416 | case 0: |
| 5417 | request->fl_type = F_UNLCK; |
| 5418 | break; |
| 5419 | case -NFS4ERR_DENIED: |
| 5420 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5422 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5423 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5424 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5425 | return status; |
| 5426 | } |
| 5427 | |
| 5428 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5429 | { |
| 5430 | struct nfs4_exception exception = { }; |
| 5431 | int err; |
| 5432 | |
| 5433 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5434 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5435 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5436 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5437 | &exception); |
| 5438 | } while (exception.retry); |
| 5439 | return err; |
| 5440 | } |
| 5441 | |
| 5442 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 5443 | { |
| 5444 | int res = 0; |
| 5445 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 5446 | case FL_POSIX: |
| 5447 | res = posix_lock_file_wait(file, fl); |
| 5448 | break; |
| 5449 | case FL_FLOCK: |
| 5450 | res = flock_lock_file_wait(file, fl); |
| 5451 | break; |
| 5452 | default: |
| 5453 | BUG(); |
| 5454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | return res; |
| 5456 | } |
| 5457 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5458 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5459 | struct nfs_locku_args arg; |
| 5460 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5461 | struct nfs4_lock_state *lsp; |
| 5462 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5463 | struct file_lock fl; |
| 5464 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5465 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5466 | }; |
| 5467 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5468 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5469 | struct nfs_open_context *ctx, |
| 5470 | struct nfs4_lock_state *lsp, |
| 5471 | struct nfs_seqid *seqid) |
| 5472 | { |
| 5473 | struct nfs4_unlockdata *p; |
| 5474 | struct inode *inode = lsp->ls_state->inode; |
| 5475 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5476 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5477 | if (p == NULL) |
| 5478 | return NULL; |
| 5479 | p->arg.fh = NFS_FH(inode); |
| 5480 | p->arg.fl = &p->fl; |
| 5481 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5482 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5483 | p->lsp = lsp; |
| 5484 | atomic_inc(&lsp->ls_count); |
| 5485 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5486 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | db2efec | 2015-06-30 14:12:30 -0400 | [diff] [blame] | 5487 | get_file(fl->fl_file); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5488 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5489 | p->server = NFS_SERVER(inode); |
| 5490 | return p; |
| 5491 | } |
| 5492 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5493 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5494 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5495 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5496 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5497 | nfs4_put_lock_state(calldata->lsp); |
| 5498 | put_nfs_open_context(calldata->ctx); |
Jeff Layton | db2efec | 2015-06-30 14:12:30 -0400 | [diff] [blame] | 5499 | fput(calldata->fl.fl_file); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5500 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5501 | } |
| 5502 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5503 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5504 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5505 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5506 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5507 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5508 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5509 | switch (task->tk_status) { |
| 5510 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5511 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5512 | do_vfs_lock(calldata->fl.fl_file, &calldata->fl); |
| 5513 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5514 | &calldata->res.stateid)) |
| 5515 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5516 | case -NFS4ERR_BAD_STATEID: |
| 5517 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5518 | case -NFS4ERR_STALE_STATEID: |
| 5519 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5520 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5521 | &calldata->lsp->ls_stateid)) |
| 5522 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5523 | break; |
| 5524 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5525 | if (nfs4_async_handle_error(task, calldata->server, |
| 5526 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5527 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5528 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5529 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5530 | } |
| 5531 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5532 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5533 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5534 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5536 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5537 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5538 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5539 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5540 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5541 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5542 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5543 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5544 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5545 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5546 | &calldata->res.seq_res, |
| 5547 | task) != 0) |
| 5548 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5549 | return; |
| 5550 | out_no_action: |
| 5551 | task->tk_action = NULL; |
| 5552 | out_wait: |
| 5553 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5556 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5557 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5558 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5559 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5560 | }; |
| 5561 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5562 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5563 | struct nfs_open_context *ctx, |
| 5564 | struct nfs4_lock_state *lsp, |
| 5565 | struct nfs_seqid *seqid) |
| 5566 | { |
| 5567 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5568 | struct rpc_message msg = { |
| 5569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5570 | .rpc_cred = ctx->cred, |
| 5571 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5572 | struct rpc_task_setup task_setup_data = { |
| 5573 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5574 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5575 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5576 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5577 | .flags = RPC_TASK_ASYNC, |
| 5578 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5579 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5580 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5581 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5582 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5583 | /* Ensure this is an unlock - when canceling a lock, the |
| 5584 | * canceled lock is passed in, and it won't be an unlock. |
| 5585 | */ |
| 5586 | fl->fl_type = F_UNLCK; |
| 5587 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5588 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5589 | if (data == NULL) { |
| 5590 | nfs_free_seqid(seqid); |
| 5591 | return ERR_PTR(-ENOMEM); |
| 5592 | } |
| 5593 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5594 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5595 | msg.rpc_argp = &data->arg; |
| 5596 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5597 | task_setup_data.callback_data = data; |
| 5598 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5599 | } |
| 5600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5602 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5603 | struct inode *inode = state->inode; |
| 5604 | struct nfs4_state_owner *sp = state->owner; |
| 5605 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5606 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5607 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5608 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5609 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5610 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5611 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5613 | status = nfs4_set_lock_state(state, request); |
| 5614 | /* Unlock _before_ we do the RPC call */ |
| 5615 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5616 | /* Exclude nfs_delegation_claim_locks() */ |
| 5617 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5618 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5619 | down_read(&nfsi->rwsem); |
| 5620 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 5621 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5622 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5623 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5624 | } |
| 5625 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5626 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5627 | if (status != 0) |
| 5628 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5629 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5630 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5631 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5632 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5633 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5634 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5635 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5636 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5637 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5638 | 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] | 5639 | status = PTR_ERR(task); |
| 5640 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5641 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5642 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5643 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5644 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5645 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5646 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5647 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | } |
| 5649 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5650 | struct nfs4_lockdata { |
| 5651 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5652 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5653 | struct nfs4_lock_state *lsp; |
| 5654 | struct nfs_open_context *ctx; |
| 5655 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5656 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5657 | int rpc_status; |
| 5658 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5659 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5660 | }; |
| 5661 | |
| 5662 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5663 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5664 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5665 | { |
| 5666 | struct nfs4_lockdata *p; |
| 5667 | struct inode *inode = lsp->ls_state->inode; |
| 5668 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5669 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5670 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5671 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5672 | if (p == NULL) |
| 5673 | return NULL; |
| 5674 | |
| 5675 | p->arg.fh = NFS_FH(inode); |
| 5676 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5677 | 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] | 5678 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5679 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5680 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5681 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5682 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5683 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5684 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5685 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5686 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5687 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5688 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5689 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5690 | atomic_inc(&lsp->ls_count); |
| 5691 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5692 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5693 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5694 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5695 | out_free_seqid: |
| 5696 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5697 | out_free: |
| 5698 | kfree(p); |
| 5699 | return NULL; |
| 5700 | } |
| 5701 | |
| 5702 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5703 | { |
| 5704 | struct nfs4_lockdata *data = calldata; |
| 5705 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5707 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5708 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5709 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5710 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5711 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5712 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5713 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5714 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5715 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5716 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5717 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5718 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5719 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5720 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5721 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5722 | &data->lsp->ls_stateid); |
| 5723 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5724 | if (!nfs4_valid_open_stateid(state)) { |
| 5725 | data->rpc_status = -EBADF; |
| 5726 | task->tk_action = NULL; |
| 5727 | goto out_release_open_seqid; |
| 5728 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5729 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5730 | if (nfs4_setup_sequence(data->server, |
| 5731 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5732 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5733 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5734 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5735 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5736 | nfs_release_seqid(data->arg.open_seqid); |
| 5737 | out_release_lock_seqid: |
| 5738 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5739 | out_wait: |
| 5740 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5741 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5742 | } |
| 5743 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5744 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5745 | { |
| 5746 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5747 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5748 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5749 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5750 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5751 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5752 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5753 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5754 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5755 | switch (task->tk_status) { |
| 5756 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5757 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5758 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5759 | if (data->arg.new_lock) { |
| 5760 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
| 5761 | if (do_vfs_lock(data->fl.fl_file, &data->fl) < 0) { |
| 5762 | rpc_restart_call_prepare(task); |
| 5763 | break; |
| 5764 | } |
| 5765 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5766 | if (data->arg.new_lock_owner != 0) { |
| 5767 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5768 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5769 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5770 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5771 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5772 | break; |
| 5773 | case -NFS4ERR_BAD_STATEID: |
| 5774 | case -NFS4ERR_OLD_STATEID: |
| 5775 | case -NFS4ERR_STALE_STATEID: |
| 5776 | case -NFS4ERR_EXPIRED: |
| 5777 | if (data->arg.new_lock_owner != 0) { |
| 5778 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5779 | &lsp->ls_state->open_stateid)) |
| 5780 | rpc_restart_call_prepare(task); |
| 5781 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5782 | &lsp->ls_stateid)) |
| 5783 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5784 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5785 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | static void nfs4_lock_release(void *calldata) |
| 5789 | { |
| 5790 | struct nfs4_lockdata *data = calldata; |
| 5791 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5792 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5793 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5794 | if (data->cancelled != 0) { |
| 5795 | struct rpc_task *task; |
| 5796 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5797 | data->arg.lock_seqid); |
| 5798 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5799 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5800 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5801 | } else |
| 5802 | nfs_free_seqid(data->arg.lock_seqid); |
| 5803 | nfs4_put_lock_state(data->lsp); |
| 5804 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5805 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5806 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5807 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5811 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5812 | .rpc_call_done = nfs4_lock_done, |
| 5813 | .rpc_release = nfs4_lock_release, |
| 5814 | }; |
| 5815 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5816 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5817 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5818 | switch (error) { |
| 5819 | case -NFS4ERR_ADMIN_REVOKED: |
| 5820 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5821 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5822 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5823 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5824 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5825 | break; |
| 5826 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5827 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5828 | case -NFS4ERR_EXPIRED: |
| 5829 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5830 | }; |
| 5831 | } |
| 5832 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5833 | 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] | 5834 | { |
| 5835 | struct nfs4_lockdata *data; |
| 5836 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5837 | struct rpc_message msg = { |
| 5838 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5839 | .rpc_cred = state->owner->so_cred, |
| 5840 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5841 | struct rpc_task_setup task_setup_data = { |
| 5842 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5843 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5844 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5845 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5846 | .flags = RPC_TASK_ASYNC, |
| 5847 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5848 | int ret; |
| 5849 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5850 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5851 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5852 | fl->fl_u.nfs4_fl.owner, |
| 5853 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5854 | if (data == NULL) |
| 5855 | return -ENOMEM; |
| 5856 | if (IS_SETLKW(cmd)) |
| 5857 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5858 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5859 | msg.rpc_argp = &data->arg; |
| 5860 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5861 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5862 | if (recovery_type > NFS_LOCK_NEW) { |
| 5863 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5864 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5865 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5866 | } else |
| 5867 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5868 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5869 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5870 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5871 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5872 | if (ret == 0) { |
| 5873 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5874 | if (ret) |
| 5875 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5876 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5877 | } else |
| 5878 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5879 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5880 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5881 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5885 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5886 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5887 | struct nfs4_exception exception = { |
| 5888 | .inode = state->inode, |
| 5889 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5890 | int err; |
| 5891 | |
| 5892 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5893 | /* Cache the lock if possible... */ |
| 5894 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5895 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5896 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5897 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5898 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5899 | break; |
| 5900 | nfs4_handle_exception(server, err, &exception); |
| 5901 | } while (exception.retry); |
| 5902 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5906 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5907 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5908 | struct nfs4_exception exception = { |
| 5909 | .inode = state->inode, |
| 5910 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5911 | int err; |
| 5912 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5913 | err = nfs4_set_lock_state(state, request); |
| 5914 | if (err != 0) |
| 5915 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5916 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5917 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 5918 | return 0; |
| 5919 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5920 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5921 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5922 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5923 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5924 | trace_nfs4_lock_expired(request, state, F_SETLK, err); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5925 | switch (err) { |
| 5926 | default: |
| 5927 | goto out; |
| 5928 | case -NFS4ERR_GRACE: |
| 5929 | case -NFS4ERR_DELAY: |
| 5930 | nfs4_handle_exception(server, err, &exception); |
| 5931 | err = 0; |
| 5932 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5933 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5934 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5935 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | } |
| 5937 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5938 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5939 | /** |
| 5940 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5941 | * |
| 5942 | * @state: NFSv4 state for an inode |
| 5943 | * |
| 5944 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5945 | * Otherwise a negative NFS4ERR value is returned. |
| 5946 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5947 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5948 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5949 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5950 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5951 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5952 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5953 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5954 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5955 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5956 | |
| 5957 | status = nfs41_test_stateid(server, |
| 5958 | &lsp->ls_stateid, |
| 5959 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5960 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5961 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5962 | /* Free the stateid unless the server |
| 5963 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5964 | if (status != -NFS4ERR_BAD_STATEID) |
| 5965 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5966 | &lsp->ls_stateid, |
| 5967 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5968 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5969 | ret = status; |
| 5970 | } |
| 5971 | } |
| 5972 | }; |
| 5973 | |
| 5974 | return ret; |
| 5975 | } |
| 5976 | |
| 5977 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5978 | { |
| 5979 | int status = NFS_OK; |
| 5980 | |
| 5981 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5982 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5983 | if (status != NFS_OK) |
| 5984 | status = nfs4_lock_expired(state, request); |
| 5985 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5986 | } |
| 5987 | #endif |
| 5988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5990 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5991 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5992 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5993 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5995 | if ((fl_flags & FL_POSIX) && |
| 5996 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5997 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5998 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5999 | status = nfs4_set_lock_state(state, request); |
| 6000 | if (status != 0) |
| 6001 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6002 | request->fl_flags |= FL_ACCESS; |
| 6003 | status = do_vfs_lock(request->fl_file, request); |
| 6004 | if (status < 0) |
| 6005 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6006 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6007 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6008 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6009 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6010 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 6011 | status = do_vfs_lock(request->fl_file, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6012 | up_read(&nfsi->rwsem); |
| 6013 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6014 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6015 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6016 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6017 | out: |
| 6018 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | return status; |
| 6020 | } |
| 6021 | |
| 6022 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6023 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6024 | struct nfs4_exception exception = { |
| 6025 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6026 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6027 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6028 | int err; |
| 6029 | |
| 6030 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6031 | err = _nfs4_proc_setlk(state, cmd, request); |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6032 | trace_nfs4_set_lock(request, state, cmd, err); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6033 | if (err == -NFS4ERR_DENIED) |
| 6034 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6036 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | } while (exception.retry); |
| 6038 | return err; |
| 6039 | } |
| 6040 | |
| 6041 | static int |
| 6042 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6043 | { |
| 6044 | struct nfs_open_context *ctx; |
| 6045 | struct nfs4_state *state; |
| 6046 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6047 | int status; |
| 6048 | |
| 6049 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6050 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | state = ctx->state; |
| 6052 | |
| 6053 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6054 | return -EINVAL; |
| 6055 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6056 | if (IS_GETLK(cmd)) { |
| 6057 | if (state != NULL) |
| 6058 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6059 | return 0; |
| 6060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6061 | |
| 6062 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6063 | return -EINVAL; |
| 6064 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6065 | if (request->fl_type == F_UNLCK) { |
| 6066 | if (state != NULL) |
| 6067 | return nfs4_proc_unlck(state, cmd, request); |
| 6068 | return 0; |
| 6069 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6071 | if (state == NULL) |
| 6072 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6073 | /* |
| 6074 | * Don't rely on the VFS having checked the file open mode, |
| 6075 | * since it won't do this for flock() locks. |
| 6076 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6077 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6078 | case F_RDLCK: |
| 6079 | if (!(filp->f_mode & FMODE_READ)) |
| 6080 | return -EBADF; |
| 6081 | break; |
| 6082 | case F_WRLCK: |
| 6083 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6084 | return -EBADF; |
| 6085 | } |
| 6086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | do { |
| 6088 | status = nfs4_proc_setlk(state, cmd, request); |
| 6089 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6090 | break; |
| 6091 | timeout = nfs4_set_lock_task_retry(timeout); |
| 6092 | status = -ERESTARTSYS; |
| 6093 | if (signalled()) |
| 6094 | break; |
| 6095 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6096 | return status; |
| 6097 | } |
| 6098 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6099 | 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] | 6100 | { |
| 6101 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6102 | int err; |
| 6103 | |
| 6104 | err = nfs4_set_lock_state(state, fl); |
| 6105 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6106 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6107 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6108 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6109 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6110 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6111 | struct nfs_release_lockowner_data { |
| 6112 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6113 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6114 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6115 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6116 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6117 | }; |
| 6118 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6119 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6120 | { |
| 6121 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6122 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6123 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6124 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6125 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6126 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6130 | { |
| 6131 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6132 | struct nfs_server *server = data->server; |
| 6133 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6134 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6135 | |
| 6136 | switch (task->tk_status) { |
| 6137 | case 0: |
| 6138 | renew_lease(server, data->timestamp); |
| 6139 | break; |
| 6140 | case -NFS4ERR_STALE_CLIENTID: |
| 6141 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6142 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6143 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6144 | case -NFS4ERR_LEASE_MOVED: |
| 6145 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6146 | if (nfs4_async_handle_error(task, server, |
| 6147 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6148 | rpc_restart_call_prepare(task); |
| 6149 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6150 | } |
| 6151 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6152 | static void nfs4_release_lockowner_release(void *calldata) |
| 6153 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6154 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6155 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6156 | kfree(calldata); |
| 6157 | } |
| 6158 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6159 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6160 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6161 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6162 | .rpc_release = nfs4_release_lockowner_release, |
| 6163 | }; |
| 6164 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6165 | static void |
| 6166 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6167 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6168 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6169 | struct rpc_message msg = { |
| 6170 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6171 | }; |
| 6172 | |
| 6173 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6174 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6175 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6176 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6177 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6178 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6179 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6180 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6181 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6182 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6183 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6184 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6185 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6186 | msg.rpc_resp = &data->res; |
| 6187 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6188 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6189 | } |
| 6190 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6191 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6192 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6193 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 6194 | const void *buf, size_t buflen, |
| 6195 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6196 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6197 | if (strcmp(key, "") != 0) |
| 6198 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6199 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6200 | return nfs4_proc_set_acl(d_inode(dentry), buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6203 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 6204 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6205 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6206 | if (strcmp(key, "") != 0) |
| 6207 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6208 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6209 | return nfs4_proc_get_acl(d_inode(dentry), buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6210 | } |
| 6211 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6212 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 6213 | size_t list_len, const char *name, |
| 6214 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6215 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6216 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6217 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6218 | if (!nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry)))) |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 6219 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6220 | |
| 6221 | if (list && len <= list_len) |
| 6222 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6223 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6224 | } |
| 6225 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6226 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 6227 | static inline int nfs4_server_supports_labels(struct nfs_server *server) |
| 6228 | { |
| 6229 | return server->caps & NFS_CAP_SECURITY_LABEL; |
| 6230 | } |
| 6231 | |
| 6232 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, |
| 6233 | const void *buf, size_t buflen, |
| 6234 | int flags, int type) |
| 6235 | { |
| 6236 | if (security_ismaclabel(key)) |
| 6237 | return nfs4_set_security_label(dentry, buf, buflen); |
| 6238 | |
| 6239 | return -EOPNOTSUPP; |
| 6240 | } |
| 6241 | |
| 6242 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, |
| 6243 | void *buf, size_t buflen, int type) |
| 6244 | { |
| 6245 | if (security_ismaclabel(key)) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6246 | return nfs4_get_security_label(d_inode(dentry), buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6247 | return -EOPNOTSUPP; |
| 6248 | } |
| 6249 | |
| 6250 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, |
| 6251 | size_t list_len, const char *name, |
| 6252 | size_t name_len, int type) |
| 6253 | { |
| 6254 | size_t len = 0; |
| 6255 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6256 | if (nfs_server_capable(d_inode(dentry), NFS_CAP_SECURITY_LABEL)) { |
| 6257 | len = security_inode_listsecurity(d_inode(dentry), NULL, 0); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6258 | if (list && len <= list_len) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6259 | security_inode_listsecurity(d_inode(dentry), list, len); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6260 | } |
| 6261 | return len; |
| 6262 | } |
| 6263 | |
| 6264 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6265 | .prefix = XATTR_SECURITY_PREFIX, |
| 6266 | .list = nfs4_xattr_list_nfs4_label, |
| 6267 | .get = nfs4_xattr_get_nfs4_label, |
| 6268 | .set = nfs4_xattr_set_nfs4_label, |
| 6269 | }; |
| 6270 | #endif |
| 6271 | |
| 6272 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6273 | /* |
| 6274 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6275 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6276 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6277 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6278 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6279 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6280 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6281 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6282 | return; |
| 6283 | |
| 6284 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6285 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6286 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6287 | fattr->nlink = 2; |
| 6288 | } |
| 6289 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6290 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6291 | const struct qstr *name, |
| 6292 | struct nfs4_fs_locations *fs_locations, |
| 6293 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6294 | { |
| 6295 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6296 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6297 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6298 | }; |
| 6299 | struct nfs4_fs_locations_arg args = { |
| 6300 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6301 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6302 | .page = page, |
| 6303 | .bitmask = bitmask, |
| 6304 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6305 | struct nfs4_fs_locations_res res = { |
| 6306 | .fs_locations = fs_locations, |
| 6307 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6308 | struct rpc_message msg = { |
| 6309 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6310 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6311 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6312 | }; |
| 6313 | int status; |
| 6314 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6315 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6316 | |
| 6317 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6318 | * is not supported */ |
| 6319 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6320 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6321 | else |
| 6322 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6323 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6324 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6325 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6326 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6327 | 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] | 6328 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6329 | return status; |
| 6330 | } |
| 6331 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6332 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6333 | const struct qstr *name, |
| 6334 | struct nfs4_fs_locations *fs_locations, |
| 6335 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6336 | { |
| 6337 | struct nfs4_exception exception = { }; |
| 6338 | int err; |
| 6339 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6340 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6341 | fs_locations, page); |
| 6342 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6343 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6344 | &exception); |
| 6345 | } while (exception.retry); |
| 6346 | return err; |
| 6347 | } |
| 6348 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6349 | /* |
| 6350 | * This operation also signals the server that this client is |
| 6351 | * performing migration recovery. The server can stop returning |
| 6352 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6353 | * appended to this compound to identify the client ID which is |
| 6354 | * performing recovery. |
| 6355 | */ |
| 6356 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6357 | struct nfs4_fs_locations *locations, |
| 6358 | struct page *page, struct rpc_cred *cred) |
| 6359 | { |
| 6360 | struct nfs_server *server = NFS_SERVER(inode); |
| 6361 | struct rpc_clnt *clnt = server->client; |
| 6362 | u32 bitmask[2] = { |
| 6363 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6364 | }; |
| 6365 | struct nfs4_fs_locations_arg args = { |
| 6366 | .clientid = server->nfs_client->cl_clientid, |
| 6367 | .fh = NFS_FH(inode), |
| 6368 | .page = page, |
| 6369 | .bitmask = bitmask, |
| 6370 | .migration = 1, /* skip LOOKUP */ |
| 6371 | .renew = 1, /* append RENEW */ |
| 6372 | }; |
| 6373 | struct nfs4_fs_locations_res res = { |
| 6374 | .fs_locations = locations, |
| 6375 | .migration = 1, |
| 6376 | .renew = 1, |
| 6377 | }; |
| 6378 | struct rpc_message msg = { |
| 6379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6380 | .rpc_argp = &args, |
| 6381 | .rpc_resp = &res, |
| 6382 | .rpc_cred = cred, |
| 6383 | }; |
| 6384 | unsigned long now = jiffies; |
| 6385 | int status; |
| 6386 | |
| 6387 | nfs_fattr_init(&locations->fattr); |
| 6388 | locations->server = server; |
| 6389 | locations->nlocations = 0; |
| 6390 | |
| 6391 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6392 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6393 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6394 | &args.seq_args, &res.seq_res); |
| 6395 | if (status) |
| 6396 | return status; |
| 6397 | |
| 6398 | renew_lease(server, now); |
| 6399 | return 0; |
| 6400 | } |
| 6401 | |
| 6402 | #ifdef CONFIG_NFS_V4_1 |
| 6403 | |
| 6404 | /* |
| 6405 | * This operation also signals the server that this client is |
| 6406 | * performing migration recovery. The server can stop asserting |
| 6407 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6408 | * performing this operation is identified in the SEQUENCE |
| 6409 | * operation in this compound. |
| 6410 | * |
| 6411 | * When the client supports GETATTR(fs_locations_info), it can |
| 6412 | * be plumbed in here. |
| 6413 | */ |
| 6414 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6415 | struct nfs4_fs_locations *locations, |
| 6416 | struct page *page, struct rpc_cred *cred) |
| 6417 | { |
| 6418 | struct nfs_server *server = NFS_SERVER(inode); |
| 6419 | struct rpc_clnt *clnt = server->client; |
| 6420 | u32 bitmask[2] = { |
| 6421 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6422 | }; |
| 6423 | struct nfs4_fs_locations_arg args = { |
| 6424 | .fh = NFS_FH(inode), |
| 6425 | .page = page, |
| 6426 | .bitmask = bitmask, |
| 6427 | .migration = 1, /* skip LOOKUP */ |
| 6428 | }; |
| 6429 | struct nfs4_fs_locations_res res = { |
| 6430 | .fs_locations = locations, |
| 6431 | .migration = 1, |
| 6432 | }; |
| 6433 | struct rpc_message msg = { |
| 6434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6435 | .rpc_argp = &args, |
| 6436 | .rpc_resp = &res, |
| 6437 | .rpc_cred = cred, |
| 6438 | }; |
| 6439 | int status; |
| 6440 | |
| 6441 | nfs_fattr_init(&locations->fattr); |
| 6442 | locations->server = server; |
| 6443 | locations->nlocations = 0; |
| 6444 | |
| 6445 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6446 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6447 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6448 | &args.seq_args, &res.seq_res); |
| 6449 | if (status == NFS4_OK && |
| 6450 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6451 | status = -NFS4ERR_LEASE_MOVED; |
| 6452 | return status; |
| 6453 | } |
| 6454 | |
| 6455 | #endif /* CONFIG_NFS_V4_1 */ |
| 6456 | |
| 6457 | /** |
| 6458 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6459 | * @inode: inode on FSID that is migrating |
| 6460 | * @locations: result of query |
| 6461 | * @page: buffer |
| 6462 | * @cred: credential to use for this operation |
| 6463 | * |
| 6464 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6465 | * operation failed, or a negative errno if a local error occurred. |
| 6466 | * |
| 6467 | * On success, "locations" is filled in, but if the server has |
| 6468 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6469 | * asserted. |
| 6470 | * |
| 6471 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6472 | * from this client that require migration recovery. |
| 6473 | */ |
| 6474 | int nfs4_proc_get_locations(struct inode *inode, |
| 6475 | struct nfs4_fs_locations *locations, |
| 6476 | struct page *page, struct rpc_cred *cred) |
| 6477 | { |
| 6478 | struct nfs_server *server = NFS_SERVER(inode); |
| 6479 | struct nfs_client *clp = server->nfs_client; |
| 6480 | const struct nfs4_mig_recovery_ops *ops = |
| 6481 | clp->cl_mvops->mig_recovery_ops; |
| 6482 | struct nfs4_exception exception = { }; |
| 6483 | int status; |
| 6484 | |
| 6485 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6486 | (unsigned long long)server->fsid.major, |
| 6487 | (unsigned long long)server->fsid.minor, |
| 6488 | clp->cl_hostname); |
| 6489 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6490 | |
| 6491 | do { |
| 6492 | status = ops->get_locations(inode, locations, page, cred); |
| 6493 | if (status != -NFS4ERR_DELAY) |
| 6494 | break; |
| 6495 | nfs4_handle_exception(server, status, &exception); |
| 6496 | } while (exception.retry); |
| 6497 | return status; |
| 6498 | } |
| 6499 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6500 | /* |
| 6501 | * This operation also signals the server that this client is |
| 6502 | * performing "lease moved" recovery. The server can stop |
| 6503 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6504 | * is appended to this compound to identify the client ID which is |
| 6505 | * performing recovery. |
| 6506 | */ |
| 6507 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6508 | { |
| 6509 | struct nfs_server *server = NFS_SERVER(inode); |
| 6510 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6511 | struct rpc_clnt *clnt = server->client; |
| 6512 | struct nfs4_fsid_present_arg args = { |
| 6513 | .fh = NFS_FH(inode), |
| 6514 | .clientid = clp->cl_clientid, |
| 6515 | .renew = 1, /* append RENEW */ |
| 6516 | }; |
| 6517 | struct nfs4_fsid_present_res res = { |
| 6518 | .renew = 1, |
| 6519 | }; |
| 6520 | struct rpc_message msg = { |
| 6521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6522 | .rpc_argp = &args, |
| 6523 | .rpc_resp = &res, |
| 6524 | .rpc_cred = cred, |
| 6525 | }; |
| 6526 | unsigned long now = jiffies; |
| 6527 | int status; |
| 6528 | |
| 6529 | res.fh = nfs_alloc_fhandle(); |
| 6530 | if (res.fh == NULL) |
| 6531 | return -ENOMEM; |
| 6532 | |
| 6533 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6534 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6535 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6536 | &args.seq_args, &res.seq_res); |
| 6537 | nfs_free_fhandle(res.fh); |
| 6538 | if (status) |
| 6539 | return status; |
| 6540 | |
| 6541 | do_renew_lease(clp, now); |
| 6542 | return 0; |
| 6543 | } |
| 6544 | |
| 6545 | #ifdef CONFIG_NFS_V4_1 |
| 6546 | |
| 6547 | /* |
| 6548 | * This operation also signals the server that this client is |
| 6549 | * performing "lease moved" recovery. The server can stop asserting |
| 6550 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6551 | * this operation is identified in the SEQUENCE operation in this |
| 6552 | * compound. |
| 6553 | */ |
| 6554 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6555 | { |
| 6556 | struct nfs_server *server = NFS_SERVER(inode); |
| 6557 | struct rpc_clnt *clnt = server->client; |
| 6558 | struct nfs4_fsid_present_arg args = { |
| 6559 | .fh = NFS_FH(inode), |
| 6560 | }; |
| 6561 | struct nfs4_fsid_present_res res = { |
| 6562 | }; |
| 6563 | struct rpc_message msg = { |
| 6564 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6565 | .rpc_argp = &args, |
| 6566 | .rpc_resp = &res, |
| 6567 | .rpc_cred = cred, |
| 6568 | }; |
| 6569 | int status; |
| 6570 | |
| 6571 | res.fh = nfs_alloc_fhandle(); |
| 6572 | if (res.fh == NULL) |
| 6573 | return -ENOMEM; |
| 6574 | |
| 6575 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6576 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6577 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6578 | &args.seq_args, &res.seq_res); |
| 6579 | nfs_free_fhandle(res.fh); |
| 6580 | if (status == NFS4_OK && |
| 6581 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6582 | status = -NFS4ERR_LEASE_MOVED; |
| 6583 | return status; |
| 6584 | } |
| 6585 | |
| 6586 | #endif /* CONFIG_NFS_V4_1 */ |
| 6587 | |
| 6588 | /** |
| 6589 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6590 | * @inode: inode on FSID to check |
| 6591 | * @cred: credential to use for this operation |
| 6592 | * |
| 6593 | * Server indicates whether the FSID is present, moved, or not |
| 6594 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6595 | * condition for this client ID. |
| 6596 | * |
| 6597 | * Returns NFS4_OK if the FSID is present on this server, |
| 6598 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6599 | * NFS4ERR code if some error occurred on the server, or a |
| 6600 | * negative errno if a local failure occurred. |
| 6601 | */ |
| 6602 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6603 | { |
| 6604 | struct nfs_server *server = NFS_SERVER(inode); |
| 6605 | struct nfs_client *clp = server->nfs_client; |
| 6606 | const struct nfs4_mig_recovery_ops *ops = |
| 6607 | clp->cl_mvops->mig_recovery_ops; |
| 6608 | struct nfs4_exception exception = { }; |
| 6609 | int status; |
| 6610 | |
| 6611 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6612 | (unsigned long long)server->fsid.major, |
| 6613 | (unsigned long long)server->fsid.minor, |
| 6614 | clp->cl_hostname); |
| 6615 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6616 | |
| 6617 | do { |
| 6618 | status = ops->fsid_present(inode, cred); |
| 6619 | if (status != -NFS4ERR_DELAY) |
| 6620 | break; |
| 6621 | nfs4_handle_exception(server, status, &exception); |
| 6622 | } while (exception.retry); |
| 6623 | return status; |
| 6624 | } |
| 6625 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6626 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6627 | * If 'use_integrity' is true and the state managment nfs_client |
| 6628 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6629 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6630 | * Considerations sections. Otherwise, just use the user cred with the |
| 6631 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6632 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6633 | 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] | 6634 | { |
| 6635 | int status; |
| 6636 | struct nfs4_secinfo_arg args = { |
| 6637 | .dir_fh = NFS_FH(dir), |
| 6638 | .name = name, |
| 6639 | }; |
| 6640 | struct nfs4_secinfo_res res = { |
| 6641 | .flavors = flavors, |
| 6642 | }; |
| 6643 | struct rpc_message msg = { |
| 6644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6645 | .rpc_argp = &args, |
| 6646 | .rpc_resp = &res, |
| 6647 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6648 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6649 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6650 | |
| 6651 | if (use_integrity) { |
| 6652 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6653 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6654 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6655 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6656 | |
| 6657 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6658 | |
| 6659 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6660 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6661 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6662 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6663 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6664 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6665 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6666 | if (cred) |
| 6667 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6668 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6669 | return status; |
| 6670 | } |
| 6671 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6672 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6673 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6674 | { |
| 6675 | struct nfs4_exception exception = { }; |
| 6676 | int err; |
| 6677 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6678 | err = -NFS4ERR_WRONGSEC; |
| 6679 | |
| 6680 | /* try to use integrity protection with machine cred */ |
| 6681 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6682 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6683 | |
| 6684 | /* |
| 6685 | * if unable to use integrity protection, or SECINFO with |
| 6686 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6687 | * disallowed by spec, but exists in deployed servers) use |
| 6688 | * the current filesystem's rpc_client and the user cred. |
| 6689 | */ |
| 6690 | if (err == -NFS4ERR_WRONGSEC) |
| 6691 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6692 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6693 | trace_nfs4_secinfo(dir, name, err); |
| 6694 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6695 | &exception); |
| 6696 | } while (exception.retry); |
| 6697 | return err; |
| 6698 | } |
| 6699 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6700 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6701 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6702 | * Check the exchange flags returned by the server for invalid flags, having |
| 6703 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6704 | * DS flags set. |
| 6705 | */ |
| 6706 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6707 | { |
| 6708 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6709 | goto out_inval; |
| 6710 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6711 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6712 | goto out_inval; |
| 6713 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6714 | goto out_inval; |
| 6715 | return NFS_OK; |
| 6716 | out_inval: |
| 6717 | return -NFS4ERR_INVAL; |
| 6718 | } |
| 6719 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6720 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6721 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6722 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6723 | { |
| 6724 | if (a->server_scope_sz == b->server_scope_sz && |
| 6725 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6726 | return true; |
| 6727 | |
| 6728 | return false; |
| 6729 | } |
| 6730 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6731 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6732 | * nfs4_proc_bind_conn_to_session() |
| 6733 | * |
| 6734 | * The 4.1 client currently uses the same TCP connection for the |
| 6735 | * fore and backchannel. |
| 6736 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6737 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6738 | { |
| 6739 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6740 | struct nfs41_bind_conn_to_session_args args = { |
| 6741 | .client = clp, |
| 6742 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6743 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6744 | struct nfs41_bind_conn_to_session_res res; |
| 6745 | struct rpc_message msg = { |
| 6746 | .rpc_proc = |
| 6747 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6748 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6749 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6750 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6751 | }; |
| 6752 | |
| 6753 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6754 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6755 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 6756 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 6757 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6758 | |
| 6759 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6760 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6761 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6762 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6763 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 6764 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 6765 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6766 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6767 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6768 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6769 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 6770 | __func__); |
| 6771 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6772 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6773 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6774 | 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] | 6775 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 6776 | __func__); |
| 6777 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6778 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6779 | } |
| 6780 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6781 | out: |
| 6782 | dprintk("<-- %s status= %d\n", __func__, status); |
| 6783 | return status; |
| 6784 | } |
| 6785 | |
| 6786 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6787 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 6788 | * 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] | 6789 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6790 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 6791 | .how = SP4_MACH_CRED, |
| 6792 | .enforce.u.words = { |
| 6793 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6794 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6795 | 1 << (OP_CREATE_SESSION - 32) | |
| 6796 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6797 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6798 | }, |
| 6799 | .allow.u.words = { |
| 6800 | [0] = 1 << (OP_CLOSE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6801 | 1 << (OP_LOCKU) | |
| 6802 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6803 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6804 | 1 << (OP_SECINFO_NO_NAME - 32) | |
| 6805 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6806 | 1 << (OP_FREE_STATEID - 32) | |
| 6807 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6808 | } |
| 6809 | }; |
| 6810 | |
| 6811 | /* |
| 6812 | * Select the state protection mode for client `clp' given the server results |
| 6813 | * from exchange_id in `sp'. |
| 6814 | * |
| 6815 | * Returns 0 on success, negative errno otherwise. |
| 6816 | */ |
| 6817 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 6818 | struct nfs41_state_protection *sp) |
| 6819 | { |
| 6820 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 6821 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 6822 | 1 << (OP_EXCHANGE_ID - 32) | |
| 6823 | 1 << (OP_CREATE_SESSION - 32) | |
| 6824 | 1 << (OP_DESTROY_SESSION - 32) | |
| 6825 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 6826 | }; |
| 6827 | unsigned int i; |
| 6828 | |
| 6829 | if (sp->how == SP4_MACH_CRED) { |
| 6830 | /* Print state protect result */ |
| 6831 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 6832 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 6833 | if (test_bit(i, sp->enforce.u.longs)) |
| 6834 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 6835 | if (test_bit(i, sp->allow.u.longs)) |
| 6836 | dfprintk(MOUNT, " allow op %d\n", i); |
| 6837 | } |
| 6838 | |
| 6839 | /* make sure nothing is on enforce list that isn't supported */ |
| 6840 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 6841 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 6842 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6843 | return -EINVAL; |
| 6844 | } |
| 6845 | } |
| 6846 | |
| 6847 | /* |
| 6848 | * Minimal mode - state operations are allowed to use machine |
| 6849 | * credential. Note this already happens by default, so the |
| 6850 | * client doesn't have to do anything more than the negotiation. |
| 6851 | * |
| 6852 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 6853 | * we're already using the machine cred for exchange_id |
| 6854 | * and will never use a different cred. |
| 6855 | */ |
| 6856 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 6857 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 6858 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 6859 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 6860 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 6861 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 6862 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 6863 | } else { |
| 6864 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 6865 | return -EINVAL; |
| 6866 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6867 | |
| 6868 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
| 6869 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 6870 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 6871 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 6872 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6873 | |
| 6874 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 6875 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 6876 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 6877 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 6878 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6879 | |
| 6880 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 6881 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 6882 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 6883 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 6884 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6885 | |
| 6886 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 6887 | dfprintk(MOUNT, " write mode enabled\n"); |
| 6888 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 6889 | } |
| 6890 | |
| 6891 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 6892 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 6893 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 6894 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | return 0; |
| 6898 | } |
| 6899 | |
| 6900 | /* |
| 6901 | * _nfs4_proc_exchange_id() |
| 6902 | * |
| 6903 | * Wrapper for EXCHANGE_ID operation. |
| 6904 | */ |
| 6905 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 6906 | u32 sp4_how) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6907 | { |
| 6908 | nfs4_verifier verifier; |
| 6909 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6910 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6911 | .client = clp, |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6912 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6913 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
Chuck Lever | cd3fade | 2013-10-17 14:14:04 -0400 | [diff] [blame] | 6914 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 6915 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 6916 | #else |
| 6917 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 6918 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 6919 | #endif |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6920 | }; |
| 6921 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6922 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6923 | }; |
| 6924 | int status; |
| 6925 | struct rpc_message msg = { |
| 6926 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 6927 | .rpc_argp = &args, |
| 6928 | .rpc_resp = &res, |
| 6929 | .rpc_cred = cred, |
| 6930 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6931 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6932 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 6933 | |
| 6934 | status = nfs4_init_uniform_client_string(clp); |
| 6935 | if (status) |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6936 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6937 | |
| 6938 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6939 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 6940 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6941 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6942 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6943 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6944 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6945 | status = -ENOMEM; |
| 6946 | goto out; |
| 6947 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6948 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6949 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6950 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6951 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6952 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6953 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6954 | } |
| 6955 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6956 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6957 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6958 | status = -ENOMEM; |
| 6959 | goto out_server_scope; |
| 6960 | } |
| 6961 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6962 | switch (sp4_how) { |
| 6963 | case SP4_NONE: |
| 6964 | args.state_protect.how = SP4_NONE; |
| 6965 | break; |
| 6966 | |
| 6967 | case SP4_MACH_CRED: |
| 6968 | args.state_protect = nfs4_sp4_mach_cred_request; |
| 6969 | break; |
| 6970 | |
| 6971 | default: |
| 6972 | /* unsupported! */ |
| 6973 | WARN_ON_ONCE(1); |
| 6974 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 6975 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6976 | } |
| 6977 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6978 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6979 | trace_nfs4_exchange_id(clp, status); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6980 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6981 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6982 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6983 | if (status == 0) |
| 6984 | status = nfs4_sp4_select_mode(clp, &res.state_protect); |
| 6985 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6986 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6987 | clp->cl_clientid = res.clientid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 6988 | clp->cl_exchange_flags = res.flags; |
| 6989 | /* Client ID is not confirmed */ |
| 6990 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 6991 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 6992 | &clp->cl_session->session_state); |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6993 | clp->cl_seqid = res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 6994 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6995 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6996 | kfree(clp->cl_serverowner); |
| 6997 | clp->cl_serverowner = res.server_owner; |
| 6998 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6999 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7000 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7001 | kfree(clp->cl_implid); |
| 7002 | clp->cl_implid = res.impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7003 | res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7004 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7005 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7006 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7007 | res.server_scope)) { |
| 7008 | dprintk("%s: server_scope mismatch detected\n", |
| 7009 | __func__); |
| 7010 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7011 | kfree(clp->cl_serverscope); |
| 7012 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7013 | } |
| 7014 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7015 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7016 | clp->cl_serverscope = res.server_scope; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7017 | res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7018 | } |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7019 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7020 | |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7021 | out_impl_id: |
| 7022 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7023 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7024 | kfree(res.server_scope); |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7025 | out_server_owner: |
| 7026 | kfree(res.server_owner); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7027 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7028 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7029 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7030 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7031 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7032 | clp->cl_implid->date.seconds, |
| 7033 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7034 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7035 | return status; |
| 7036 | } |
| 7037 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7038 | /* |
| 7039 | * nfs4_proc_exchange_id() |
| 7040 | * |
| 7041 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7042 | * |
| 7043 | * Since the clientid has expired, all compounds using sessions |
| 7044 | * associated with the stale clientid will be returning |
| 7045 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7046 | * be in some phase of session reset. |
| 7047 | * |
| 7048 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7049 | */ |
| 7050 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7051 | { |
| 7052 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7053 | int status; |
| 7054 | |
| 7055 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7056 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7057 | authflavor == RPC_AUTH_GSS_KRB5P) { |
| 7058 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
| 7059 | if (!status) |
| 7060 | return 0; |
| 7061 | } |
| 7062 | |
| 7063 | /* try SP4_NONE */ |
| 7064 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
| 7065 | } |
| 7066 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7067 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7068 | struct rpc_cred *cred) |
| 7069 | { |
| 7070 | struct rpc_message msg = { |
| 7071 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7072 | .rpc_argp = clp, |
| 7073 | .rpc_cred = cred, |
| 7074 | }; |
| 7075 | int status; |
| 7076 | |
| 7077 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7078 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7079 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7080 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7081 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7082 | return status; |
| 7083 | } |
| 7084 | |
| 7085 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7086 | struct rpc_cred *cred) |
| 7087 | { |
| 7088 | unsigned int loop; |
| 7089 | int ret; |
| 7090 | |
| 7091 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7092 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7093 | switch (ret) { |
| 7094 | case -NFS4ERR_DELAY: |
| 7095 | case -NFS4ERR_CLIENTID_BUSY: |
| 7096 | ssleep(1); |
| 7097 | break; |
| 7098 | default: |
| 7099 | return ret; |
| 7100 | } |
| 7101 | } |
| 7102 | return 0; |
| 7103 | } |
| 7104 | |
| 7105 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7106 | { |
| 7107 | struct rpc_cred *cred; |
| 7108 | int ret = 0; |
| 7109 | |
| 7110 | if (clp->cl_mvops->minor_version < 1) |
| 7111 | goto out; |
| 7112 | if (clp->cl_exchange_flags == 0) |
| 7113 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7114 | if (clp->cl_preserve_clid) |
| 7115 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7116 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7117 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7118 | if (cred) |
| 7119 | put_rpccred(cred); |
| 7120 | switch (ret) { |
| 7121 | case 0: |
| 7122 | case -NFS4ERR_STALE_CLIENTID: |
| 7123 | clp->cl_exchange_flags = 0; |
| 7124 | } |
| 7125 | out: |
| 7126 | return ret; |
| 7127 | } |
| 7128 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7129 | struct nfs4_get_lease_time_data { |
| 7130 | struct nfs4_get_lease_time_args *args; |
| 7131 | struct nfs4_get_lease_time_res *res; |
| 7132 | struct nfs_client *clp; |
| 7133 | }; |
| 7134 | |
| 7135 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7136 | void *calldata) |
| 7137 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7138 | struct nfs4_get_lease_time_data *data = |
| 7139 | (struct nfs4_get_lease_time_data *)calldata; |
| 7140 | |
| 7141 | dprintk("--> %s\n", __func__); |
| 7142 | /* just setup sequence, do not trigger session recovery |
| 7143 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7144 | nfs41_setup_sequence(data->clp->cl_session, |
| 7145 | &data->args->la_seq_args, |
| 7146 | &data->res->lr_seq_res, |
| 7147 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7148 | dprintk("<-- %s\n", __func__); |
| 7149 | } |
| 7150 | |
| 7151 | /* |
| 7152 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7153 | * from sequence operation or clientid errors. |
| 7154 | */ |
| 7155 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7156 | { |
| 7157 | struct nfs4_get_lease_time_data *data = |
| 7158 | (struct nfs4_get_lease_time_data *)calldata; |
| 7159 | |
| 7160 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7161 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7162 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7163 | switch (task->tk_status) { |
| 7164 | case -NFS4ERR_DELAY: |
| 7165 | case -NFS4ERR_GRACE: |
| 7166 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7167 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7168 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7169 | /* fall through */ |
| 7170 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7171 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7172 | return; |
| 7173 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7174 | dprintk("<-- %s\n", __func__); |
| 7175 | } |
| 7176 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7177 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7178 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7179 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7180 | }; |
| 7181 | |
| 7182 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7183 | { |
| 7184 | struct rpc_task *task; |
| 7185 | struct nfs4_get_lease_time_args args; |
| 7186 | struct nfs4_get_lease_time_res res = { |
| 7187 | .lr_fsinfo = fsinfo, |
| 7188 | }; |
| 7189 | struct nfs4_get_lease_time_data data = { |
| 7190 | .args = &args, |
| 7191 | .res = &res, |
| 7192 | .clp = clp, |
| 7193 | }; |
| 7194 | struct rpc_message msg = { |
| 7195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7196 | .rpc_argp = &args, |
| 7197 | .rpc_resp = &res, |
| 7198 | }; |
| 7199 | struct rpc_task_setup task_setup = { |
| 7200 | .rpc_client = clp->cl_rpcclient, |
| 7201 | .rpc_message = &msg, |
| 7202 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7203 | .callback_data = &data, |
| 7204 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7205 | }; |
| 7206 | int status; |
| 7207 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7208 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7209 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7210 | dprintk("--> %s\n", __func__); |
| 7211 | task = rpc_run_task(&task_setup); |
| 7212 | |
| 7213 | if (IS_ERR(task)) |
| 7214 | status = PTR_ERR(task); |
| 7215 | else { |
| 7216 | status = task->tk_status; |
| 7217 | rpc_put_task(task); |
| 7218 | } |
| 7219 | dprintk("<-- %s return %d\n", __func__, status); |
| 7220 | |
| 7221 | return status; |
| 7222 | } |
| 7223 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7224 | /* |
| 7225 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7226 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7227 | * use them. |
| 7228 | * |
| 7229 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7230 | * always set csa_cachethis to FALSE because the current implementation |
| 7231 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7232 | */ |
| 7233 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 7234 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7235 | unsigned int max_rqst_sz, max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7236 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7237 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7238 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7239 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7240 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7241 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7242 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7243 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7244 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7245 | |
| 7246 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7247 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7248 | __func__, |
| 7249 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7250 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7251 | |
| 7252 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7253 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 7254 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 7255 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7256 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 7257 | args->bc_attrs.max_reqs = 1; |
| 7258 | |
| 7259 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7260 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7261 | __func__, |
| 7262 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7263 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7264 | args->bc_attrs.max_reqs); |
| 7265 | } |
| 7266 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7267 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7268 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7269 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7270 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7271 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7272 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7273 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7274 | return -EINVAL; |
| 7275 | /* |
| 7276 | * Our requested max_ops is the minimum we need; we're not |
| 7277 | * prepared to break up compounds into smaller pieces than that. |
| 7278 | * So, no point even trying to continue if the server won't |
| 7279 | * cooperate: |
| 7280 | */ |
| 7281 | if (rcvd->max_ops < sent->max_ops) |
| 7282 | return -EINVAL; |
| 7283 | if (rcvd->max_reqs == 0) |
| 7284 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7285 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7286 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7287 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7288 | } |
| 7289 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7290 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7291 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7292 | { |
| 7293 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7294 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7295 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7296 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7297 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7298 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7299 | return -EINVAL; |
| 7300 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7301 | return -EINVAL; |
| 7302 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7303 | return -EINVAL; |
| 7304 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7305 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7306 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7307 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7308 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7309 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7310 | return 0; |
| 7311 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7312 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7313 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7314 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7315 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7316 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7317 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7318 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7319 | if (ret) |
| 7320 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7321 | return nfs4_verify_back_channel_attrs(args, res); |
| 7322 | } |
| 7323 | |
| 7324 | static void nfs4_update_session(struct nfs4_session *session, |
| 7325 | struct nfs41_create_session_res *res) |
| 7326 | { |
| 7327 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7328 | /* Mark client id and session as being confirmed */ |
| 7329 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7330 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7331 | session->flags = res->flags; |
| 7332 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7333 | if (res->flags & SESSION4_BACK_CHAN) |
| 7334 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7335 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7336 | } |
| 7337 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7338 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7339 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7340 | { |
| 7341 | struct nfs4_session *session = clp->cl_session; |
| 7342 | struct nfs41_create_session_args args = { |
| 7343 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7344 | .clientid = clp->cl_clientid, |
| 7345 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7346 | .cb_program = NFS4_CALLBACK, |
| 7347 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7348 | struct nfs41_create_session_res res; |
| 7349 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7350 | struct rpc_message msg = { |
| 7351 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7352 | .rpc_argp = &args, |
| 7353 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7354 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7355 | }; |
| 7356 | int status; |
| 7357 | |
| 7358 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7359 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7360 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7361 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7362 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7363 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7364 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7365 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7366 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7367 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7368 | if (clp->cl_seqid == res.seqid) |
| 7369 | clp->cl_seqid++; |
| 7370 | if (status) |
| 7371 | goto out; |
| 7372 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7373 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7374 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7375 | return status; |
| 7376 | } |
| 7377 | |
| 7378 | /* |
| 7379 | * Issues a CREATE_SESSION operation to the server. |
| 7380 | * It is the responsibility of the caller to verify the session is |
| 7381 | * expired before calling this routine. |
| 7382 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7383 | 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] | 7384 | { |
| 7385 | int status; |
| 7386 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7387 | struct nfs4_session *session = clp->cl_session; |
| 7388 | |
| 7389 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7390 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7391 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7392 | if (status) |
| 7393 | goto out; |
| 7394 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7395 | /* Init or reset the session slot tables */ |
| 7396 | status = nfs4_setup_session_slot_tables(session); |
| 7397 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7398 | if (status) |
| 7399 | goto out; |
| 7400 | |
| 7401 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7402 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7403 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7404 | out: |
| 7405 | dprintk("<-- %s\n", __func__); |
| 7406 | return status; |
| 7407 | } |
| 7408 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7409 | /* |
| 7410 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7411 | * The caller must serialize access to this routine. |
| 7412 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7413 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7414 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7415 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7416 | struct rpc_message msg = { |
| 7417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7418 | .rpc_argp = session, |
| 7419 | .rpc_cred = cred, |
| 7420 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7421 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7422 | |
| 7423 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7424 | |
| 7425 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7426 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7427 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7428 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7429 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7430 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7431 | |
| 7432 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7433 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7434 | "Session has been destroyed regardless...\n", status); |
| 7435 | |
| 7436 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7437 | return status; |
| 7438 | } |
| 7439 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7440 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7441 | * Renew the cl_session lease. |
| 7442 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7443 | struct nfs4_sequence_data { |
| 7444 | struct nfs_client *clp; |
| 7445 | struct nfs4_sequence_args args; |
| 7446 | struct nfs4_sequence_res res; |
| 7447 | }; |
| 7448 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7449 | static void nfs41_sequence_release(void *data) |
| 7450 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7451 | struct nfs4_sequence_data *calldata = data; |
| 7452 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7453 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7454 | if (atomic_read(&clp->cl_count) > 1) |
| 7455 | nfs4_schedule_state_renewal(clp); |
| 7456 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7457 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7458 | } |
| 7459 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7460 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7461 | { |
| 7462 | switch(task->tk_status) { |
| 7463 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7464 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7465 | return -EAGAIN; |
| 7466 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7467 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7468 | } |
| 7469 | return 0; |
| 7470 | } |
| 7471 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7472 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7473 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7474 | struct nfs4_sequence_data *calldata = data; |
| 7475 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7476 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7477 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7478 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7479 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7480 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7481 | if (task->tk_status < 0) { |
| 7482 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7483 | if (atomic_read(&clp->cl_count) == 1) |
| 7484 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7485 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7486 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7487 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7488 | return; |
| 7489 | } |
| 7490 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7491 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7492 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7493 | dprintk("<-- %s\n", __func__); |
| 7494 | } |
| 7495 | |
| 7496 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7497 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7498 | struct nfs4_sequence_data *calldata = data; |
| 7499 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7500 | struct nfs4_sequence_args *args; |
| 7501 | struct nfs4_sequence_res *res; |
| 7502 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7503 | args = task->tk_msg.rpc_argp; |
| 7504 | res = task->tk_msg.rpc_resp; |
| 7505 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7506 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7510 | .rpc_call_done = nfs41_sequence_call_done, |
| 7511 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7512 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7513 | }; |
| 7514 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7515 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7516 | struct rpc_cred *cred, |
| 7517 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7518 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7519 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7520 | struct rpc_message msg = { |
| 7521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7522 | .rpc_cred = cred, |
| 7523 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7524 | struct rpc_task_setup task_setup_data = { |
| 7525 | .rpc_client = clp->cl_rpcclient, |
| 7526 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7527 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7528 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7529 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7530 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7531 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7532 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7533 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7534 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7535 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7536 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7537 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7538 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7539 | if (is_privileged) |
| 7540 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7541 | msg.rpc_argp = &calldata->args; |
| 7542 | msg.rpc_resp = &calldata->res; |
| 7543 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7544 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7545 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7546 | return rpc_run_task(&task_setup_data); |
| 7547 | } |
| 7548 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7549 | 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] | 7550 | { |
| 7551 | struct rpc_task *task; |
| 7552 | int ret = 0; |
| 7553 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7554 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7555 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7556 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7557 | if (IS_ERR(task)) |
| 7558 | ret = PTR_ERR(task); |
| 7559 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7560 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7561 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7562 | return ret; |
| 7563 | } |
| 7564 | |
| 7565 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7566 | { |
| 7567 | struct rpc_task *task; |
| 7568 | int ret; |
| 7569 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7570 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7571 | if (IS_ERR(task)) { |
| 7572 | ret = PTR_ERR(task); |
| 7573 | goto out; |
| 7574 | } |
| 7575 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7576 | if (!ret) { |
| 7577 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 7578 | |
| 7579 | if (task->tk_status == 0) |
| 7580 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7581 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 7582 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7583 | rpc_put_task(task); |
| 7584 | out: |
| 7585 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7586 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7587 | } |
| 7588 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7589 | struct nfs4_reclaim_complete_data { |
| 7590 | struct nfs_client *clp; |
| 7591 | struct nfs41_reclaim_complete_args arg; |
| 7592 | struct nfs41_reclaim_complete_res res; |
| 7593 | }; |
| 7594 | |
| 7595 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 7596 | { |
| 7597 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7598 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7599 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 7600 | &calldata->arg.seq_args, |
| 7601 | &calldata->res.seq_res, |
| 7602 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7603 | } |
| 7604 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7605 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7606 | { |
| 7607 | switch(task->tk_status) { |
| 7608 | case 0: |
| 7609 | case -NFS4ERR_COMPLETE_ALREADY: |
| 7610 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 7611 | break; |
| 7612 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7613 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7614 | /* fall through */ |
| 7615 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7616 | return -EAGAIN; |
| 7617 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7618 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7619 | } |
| 7620 | return 0; |
| 7621 | } |
| 7622 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7623 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 7624 | { |
| 7625 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7626 | struct nfs_client *clp = calldata->clp; |
| 7627 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 7628 | |
| 7629 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7630 | if (!nfs41_sequence_done(task, res)) |
| 7631 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7632 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7633 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7634 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 7635 | rpc_restart_call_prepare(task); |
| 7636 | return; |
| 7637 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7638 | dprintk("<-- %s\n", __func__); |
| 7639 | } |
| 7640 | |
| 7641 | static void nfs4_free_reclaim_complete_data(void *data) |
| 7642 | { |
| 7643 | struct nfs4_reclaim_complete_data *calldata = data; |
| 7644 | |
| 7645 | kfree(calldata); |
| 7646 | } |
| 7647 | |
| 7648 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 7649 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 7650 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 7651 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 7652 | }; |
| 7653 | |
| 7654 | /* |
| 7655 | * Issue a global reclaim complete. |
| 7656 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7657 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 7658 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7659 | { |
| 7660 | struct nfs4_reclaim_complete_data *calldata; |
| 7661 | struct rpc_task *task; |
| 7662 | struct rpc_message msg = { |
| 7663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 7664 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7665 | }; |
| 7666 | struct rpc_task_setup task_setup_data = { |
| 7667 | .rpc_client = clp->cl_rpcclient, |
| 7668 | .rpc_message = &msg, |
| 7669 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 7670 | .flags = RPC_TASK_ASYNC, |
| 7671 | }; |
| 7672 | int status = -ENOMEM; |
| 7673 | |
| 7674 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7675 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7676 | if (calldata == NULL) |
| 7677 | goto out; |
| 7678 | calldata->clp = clp; |
| 7679 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7680 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7681 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7682 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7683 | msg.rpc_argp = &calldata->arg; |
| 7684 | msg.rpc_resp = &calldata->res; |
| 7685 | task_setup_data.callback_data = calldata; |
| 7686 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7687 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7688 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7689 | goto out; |
| 7690 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7691 | status = nfs4_wait_for_completion_rpc_task(task); |
| 7692 | if (status == 0) |
| 7693 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7694 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7695 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7696 | out: |
| 7697 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7698 | return status; |
| 7699 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7700 | |
| 7701 | static void |
| 7702 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 7703 | { |
| 7704 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7705 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7706 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7707 | |
| 7708 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7709 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 7710 | * right now covering the LAYOUTGET we are about to send. |
| 7711 | * However, that is not so catastrophic, and there seems |
| 7712 | * to be no way to prevent it completely. |
| 7713 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7714 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7715 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7716 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7717 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7718 | NFS_I(lgp->args.inode)->layout, |
Peng Tao | ce6ab4f | 2014-09-06 00:53:24 +0800 | [diff] [blame] | 7719 | &lgp->args.range, |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7720 | lgp->args.ctx->state)) { |
| 7721 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7722 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7723 | } |
| 7724 | |
| 7725 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 7726 | { |
| 7727 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7728 | struct inode *inode = lgp->args.inode; |
| 7729 | struct nfs_server *server = NFS_SERVER(inode); |
| 7730 | struct pnfs_layout_hdr *lo; |
| 7731 | struct nfs4_state *state = NULL; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7732 | unsigned long timeo, now, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7733 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7734 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7735 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7736 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7737 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7738 | |
| 7739 | switch (task->tk_status) { |
| 7740 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7741 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7742 | /* |
| 7743 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
| 7744 | * (or clients) writing to the same RAID stripe |
| 7745 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7746 | case -NFS4ERR_LAYOUTTRYLATER: |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7747 | /* |
| 7748 | * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall |
| 7749 | * existing layout before getting a new one). |
| 7750 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7751 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7752 | timeo = rpc_get_timeout(task->tk_client); |
| 7753 | giveup = lgp->args.timestamp + timeo; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 7754 | now = jiffies; |
| 7755 | if (time_after(giveup, now)) { |
| 7756 | unsigned long delay; |
| 7757 | |
| 7758 | /* Delay for: |
| 7759 | * - Not less then NFS4_POLL_RETRY_MIN. |
| 7760 | * - One last time a jiffie before we give up |
| 7761 | * - exponential backoff (time_now minus start_attempt) |
| 7762 | */ |
| 7763 | delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN, |
| 7764 | min((giveup - now - 1), |
| 7765 | now - lgp->args.timestamp)); |
| 7766 | |
| 7767 | dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n", |
| 7768 | __func__, delay); |
| 7769 | rpc_delay(task, delay); |
| 7770 | task->tk_status = 0; |
| 7771 | rpc_restart_call_prepare(task); |
| 7772 | goto out; /* Do not call nfs4_async_handle_error() */ |
| 7773 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7774 | break; |
| 7775 | case -NFS4ERR_EXPIRED: |
| 7776 | case -NFS4ERR_BAD_STATEID: |
| 7777 | spin_lock(&inode->i_lock); |
| 7778 | lo = NFS_I(inode)->layout; |
| 7779 | if (!lo || list_empty(&lo->plh_segs)) { |
| 7780 | spin_unlock(&inode->i_lock); |
| 7781 | /* If the open stateid was bad, then recover it. */ |
| 7782 | state = lgp->args.ctx->state; |
| 7783 | } else { |
| 7784 | LIST_HEAD(head); |
| 7785 | |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7786 | /* |
| 7787 | * Mark the bad layout state as invalid, then retry |
| 7788 | * with the current stateid. |
| 7789 | */ |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7790 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 7791 | spin_unlock(&inode->i_lock); |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7792 | pnfs_free_lseg_list(&head); |
Christoph Hellwig | defb846 | 2014-08-21 11:09:21 -0500 | [diff] [blame] | 7793 | |
| 7794 | task->tk_status = 0; |
| 7795 | rpc_restart_call_prepare(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7796 | } |
| 7797 | } |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7798 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7799 | rpc_restart_call_prepare(task); |
| 7800 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7801 | dprintk("<-- %s\n", __func__); |
| 7802 | } |
| 7803 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7804 | static size_t max_response_pages(struct nfs_server *server) |
| 7805 | { |
| 7806 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 7807 | return nfs_page_array_len(0, max_resp_sz); |
| 7808 | } |
| 7809 | |
| 7810 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 7811 | { |
| 7812 | int i; |
| 7813 | |
| 7814 | if (!pages) |
| 7815 | return; |
| 7816 | |
| 7817 | for (i = 0; i < size; i++) { |
| 7818 | if (!pages[i]) |
| 7819 | break; |
| 7820 | __free_page(pages[i]); |
| 7821 | } |
| 7822 | kfree(pages); |
| 7823 | } |
| 7824 | |
| 7825 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 7826 | { |
| 7827 | struct page **pages; |
| 7828 | int i; |
| 7829 | |
| 7830 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 7831 | if (!pages) { |
| 7832 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 7833 | return NULL; |
| 7834 | } |
| 7835 | |
| 7836 | for (i = 0; i < size; i++) { |
| 7837 | pages[i] = alloc_page(gfp_flags); |
| 7838 | if (!pages[i]) { |
| 7839 | dprintk("%s: failed to allocate page\n", __func__); |
| 7840 | nfs4_free_pages(pages, size); |
| 7841 | return NULL; |
| 7842 | } |
| 7843 | } |
| 7844 | |
| 7845 | return pages; |
| 7846 | } |
| 7847 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7848 | static void nfs4_layoutget_release(void *calldata) |
| 7849 | { |
| 7850 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7851 | struct inode *inode = lgp->args.inode; |
| 7852 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7853 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7854 | |
| 7855 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7856 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7857 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7858 | put_nfs_open_context(lgp->args.ctx); |
| 7859 | kfree(calldata); |
| 7860 | dprintk("<-- %s\n", __func__); |
| 7861 | } |
| 7862 | |
| 7863 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 7864 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 7865 | .rpc_call_done = nfs4_layoutget_done, |
| 7866 | .rpc_release = nfs4_layoutget_release, |
| 7867 | }; |
| 7868 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7869 | struct pnfs_layout_segment * |
| 7870 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7871 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7872 | struct inode *inode = lgp->args.inode; |
| 7873 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7874 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7875 | struct rpc_task *task; |
| 7876 | struct rpc_message msg = { |
| 7877 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 7878 | .rpc_argp = &lgp->args, |
| 7879 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7880 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7881 | }; |
| 7882 | struct rpc_task_setup task_setup_data = { |
| 7883 | .rpc_client = server->client, |
| 7884 | .rpc_message = &msg, |
| 7885 | .callback_ops = &nfs4_layoutget_call_ops, |
| 7886 | .callback_data = lgp, |
| 7887 | .flags = RPC_TASK_ASYNC, |
| 7888 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7889 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7890 | int status = 0; |
| 7891 | |
| 7892 | dprintk("--> %s\n", __func__); |
| 7893 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 7894 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 7895 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 7896 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7897 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 7898 | if (!lgp->args.layout.pages) { |
| 7899 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7900 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7901 | } |
| 7902 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7903 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7904 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7905 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7906 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7907 | 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] | 7908 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7909 | task = rpc_run_task(&task_setup_data); |
| 7910 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7911 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7912 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7913 | if (status == 0) |
| 7914 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7915 | trace_nfs4_layoutget(lgp->args.ctx, |
| 7916 | &lgp->args.range, |
| 7917 | &lgp->res.range, |
| 7918 | status); |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7919 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 7920 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7921 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7922 | rpc_put_task(task); |
| 7923 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7924 | if (status) |
| 7925 | return ERR_PTR(status); |
| 7926 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7927 | } |
| 7928 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7929 | static void |
| 7930 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 7931 | { |
| 7932 | struct nfs4_layoutreturn *lrp = calldata; |
| 7933 | |
| 7934 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7935 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 7936 | &lrp->args.seq_args, |
| 7937 | &lrp->res.seq_res, |
| 7938 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7939 | } |
| 7940 | |
| 7941 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 7942 | { |
| 7943 | struct nfs4_layoutreturn *lrp = calldata; |
| 7944 | struct nfs_server *server; |
| 7945 | |
| 7946 | dprintk("--> %s\n", __func__); |
| 7947 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7948 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7949 | return; |
| 7950 | |
| 7951 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7952 | switch (task->tk_status) { |
| 7953 | default: |
| 7954 | task->tk_status = 0; |
| 7955 | case 0: |
| 7956 | break; |
| 7957 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7958 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 7959 | break; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7960 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7961 | return; |
| 7962 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7963 | dprintk("<-- %s\n", __func__); |
| 7964 | } |
| 7965 | |
| 7966 | static void nfs4_layoutreturn_release(void *calldata) |
| 7967 | { |
| 7968 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7969 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7970 | |
| 7971 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7972 | spin_lock(&lo->plh_inode->i_lock); |
| 7973 | if (lrp->res.lrs_present) |
| 7974 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 7975 | pnfs_clear_layoutreturn_waitbit(lo); |
Peng Tao | 193e3aa | 2014-11-17 09:30:41 +0800 | [diff] [blame] | 7976 | clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags); |
| 7977 | rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7978 | lo->plh_block_lgets--; |
| 7979 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7980 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 7981 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7982 | kfree(calldata); |
| 7983 | dprintk("<-- %s\n", __func__); |
| 7984 | } |
| 7985 | |
| 7986 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 7987 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 7988 | .rpc_call_done = nfs4_layoutreturn_done, |
| 7989 | .rpc_release = nfs4_layoutreturn_release, |
| 7990 | }; |
| 7991 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 7992 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7993 | { |
| 7994 | struct rpc_task *task; |
| 7995 | struct rpc_message msg = { |
| 7996 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 7997 | .rpc_argp = &lrp->args, |
| 7998 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7999 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8000 | }; |
| 8001 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8002 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8003 | .rpc_message = &msg, |
| 8004 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8005 | .callback_data = lrp, |
| 8006 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8007 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8008 | |
| 8009 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8010 | if (!sync) { |
| 8011 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8012 | if (!lrp->inode) { |
| 8013 | nfs4_layoutreturn_release(lrp); |
| 8014 | return -EAGAIN; |
| 8015 | } |
| 8016 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8017 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8018 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8019 | task = rpc_run_task(&task_setup_data); |
| 8020 | if (IS_ERR(task)) |
| 8021 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8022 | if (sync) |
| 8023 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8024 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8025 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8026 | rpc_put_task(task); |
| 8027 | return status; |
| 8028 | } |
| 8029 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8030 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8031 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8032 | struct pnfs_device *pdev, |
| 8033 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8034 | { |
| 8035 | struct nfs4_getdeviceinfo_args args = { |
| 8036 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8037 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8038 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8039 | }; |
| 8040 | struct nfs4_getdeviceinfo_res res = { |
| 8041 | .pdev = pdev, |
| 8042 | }; |
| 8043 | struct rpc_message msg = { |
| 8044 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8045 | .rpc_argp = &args, |
| 8046 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8047 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8048 | }; |
| 8049 | int status; |
| 8050 | |
| 8051 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8052 | 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] | 8053 | if (res.notification & ~args.notify_types) |
| 8054 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8055 | if (res.notification != args.notify_types) |
| 8056 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8057 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8058 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8059 | |
| 8060 | return status; |
| 8061 | } |
| 8062 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8063 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8064 | struct pnfs_device *pdev, |
| 8065 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8066 | { |
| 8067 | struct nfs4_exception exception = { }; |
| 8068 | int err; |
| 8069 | |
| 8070 | do { |
| 8071 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8072 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8073 | &exception); |
| 8074 | } while (exception.retry); |
| 8075 | return err; |
| 8076 | } |
| 8077 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8078 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8079 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8080 | { |
| 8081 | struct nfs4_layoutcommit_data *data = calldata; |
| 8082 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8083 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8084 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8085 | nfs41_setup_sequence(session, |
| 8086 | &data->args.seq_args, |
| 8087 | &data->res.seq_res, |
| 8088 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8089 | } |
| 8090 | |
| 8091 | static void |
| 8092 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8093 | { |
| 8094 | struct nfs4_layoutcommit_data *data = calldata; |
| 8095 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8096 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8097 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8098 | return; |
| 8099 | |
| 8100 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8101 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8102 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8103 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8104 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8105 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8106 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8107 | break; |
| 8108 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8109 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8110 | rpc_restart_call_prepare(task); |
| 8111 | return; |
| 8112 | } |
| 8113 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8114 | } |
| 8115 | |
| 8116 | static void nfs4_layoutcommit_release(void *calldata) |
| 8117 | { |
| 8118 | struct nfs4_layoutcommit_data *data = calldata; |
| 8119 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8120 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8121 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8122 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8123 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8124 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8125 | kfree(data); |
| 8126 | } |
| 8127 | |
| 8128 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8129 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8130 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8131 | .rpc_release = nfs4_layoutcommit_release, |
| 8132 | }; |
| 8133 | |
| 8134 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8135 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8136 | { |
| 8137 | struct rpc_message msg = { |
| 8138 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8139 | .rpc_argp = &data->args, |
| 8140 | .rpc_resp = &data->res, |
| 8141 | .rpc_cred = data->cred, |
| 8142 | }; |
| 8143 | struct rpc_task_setup task_setup_data = { |
| 8144 | .task = &data->task, |
| 8145 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8146 | .rpc_message = &msg, |
| 8147 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8148 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8149 | }; |
| 8150 | struct rpc_task *task; |
| 8151 | int status = 0; |
| 8152 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8153 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8154 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8155 | data->args.lastbytewritten, |
| 8156 | data->args.inode->i_ino); |
| 8157 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8158 | if (!sync) { |
| 8159 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8160 | if (data->inode == NULL) { |
| 8161 | nfs4_layoutcommit_release(data); |
| 8162 | return -EAGAIN; |
| 8163 | } |
| 8164 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8165 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8166 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8167 | task = rpc_run_task(&task_setup_data); |
| 8168 | if (IS_ERR(task)) |
| 8169 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8170 | if (sync) |
| 8171 | status = task->tk_status; |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8172 | trace_nfs4_layoutcommit(data->args.inode, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8173 | dprintk("%s: status %d\n", __func__, status); |
| 8174 | rpc_put_task(task); |
| 8175 | return status; |
| 8176 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8177 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8178 | /** |
| 8179 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8180 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8181 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8182 | static int |
| 8183 | _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] | 8184 | struct nfs_fsinfo *info, |
| 8185 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8186 | { |
| 8187 | struct nfs41_secinfo_no_name_args args = { |
| 8188 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8189 | }; |
| 8190 | struct nfs4_secinfo_res res = { |
| 8191 | .flavors = flavors, |
| 8192 | }; |
| 8193 | struct rpc_message msg = { |
| 8194 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8195 | .rpc_argp = &args, |
| 8196 | .rpc_resp = &res, |
| 8197 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8198 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8199 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8200 | int status; |
| 8201 | |
| 8202 | if (use_integrity) { |
| 8203 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8204 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8205 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8206 | } |
| 8207 | |
| 8208 | dprintk("--> %s\n", __func__); |
| 8209 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8210 | &res.seq_res, 0); |
| 8211 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8212 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8213 | if (cred) |
| 8214 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8215 | |
| 8216 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8217 | } |
| 8218 | |
| 8219 | static int |
| 8220 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8221 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8222 | { |
| 8223 | struct nfs4_exception exception = { }; |
| 8224 | int err; |
| 8225 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8226 | /* first try using integrity protection */ |
| 8227 | err = -NFS4ERR_WRONGSEC; |
| 8228 | |
| 8229 | /* try to use integrity protection with machine cred */ |
| 8230 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8231 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8232 | flavors, true); |
| 8233 | |
| 8234 | /* |
| 8235 | * if unable to use integrity protection, or SECINFO with |
| 8236 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8237 | * disallowed by spec, but exists in deployed servers) use |
| 8238 | * the current filesystem's rpc_client and the user cred. |
| 8239 | */ |
| 8240 | if (err == -NFS4ERR_WRONGSEC) |
| 8241 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8242 | flavors, false); |
| 8243 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8244 | switch (err) { |
| 8245 | case 0: |
| 8246 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8247 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8248 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8249 | default: |
| 8250 | err = nfs4_handle_exception(server, err, &exception); |
| 8251 | } |
| 8252 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8253 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8254 | return err; |
| 8255 | } |
| 8256 | |
| 8257 | static int |
| 8258 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8259 | struct nfs_fsinfo *info) |
| 8260 | { |
| 8261 | int err; |
| 8262 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8263 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8264 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8265 | struct nfs4_secinfo4 *secinfo; |
| 8266 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8267 | |
| 8268 | page = alloc_page(GFP_KERNEL); |
| 8269 | if (!page) { |
| 8270 | err = -ENOMEM; |
| 8271 | goto out; |
| 8272 | } |
| 8273 | |
| 8274 | flavors = page_address(page); |
| 8275 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8276 | |
| 8277 | /* |
| 8278 | * Fall back on "guess and check" method if |
| 8279 | * the server doesn't support SECINFO_NO_NAME |
| 8280 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8281 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8282 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8283 | goto out_freepage; |
| 8284 | } |
| 8285 | if (err) |
| 8286 | goto out_freepage; |
| 8287 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8288 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8289 | secinfo = &flavors->flavors[i]; |
| 8290 | |
| 8291 | switch (secinfo->flavor) { |
| 8292 | case RPC_AUTH_NULL: |
| 8293 | case RPC_AUTH_UNIX: |
| 8294 | case RPC_AUTH_GSS: |
| 8295 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8296 | &secinfo->flavor_info); |
| 8297 | break; |
| 8298 | default: |
| 8299 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8300 | break; |
| 8301 | } |
| 8302 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8303 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8304 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8305 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8306 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8307 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8308 | info, flavor); |
| 8309 | if (!err) |
| 8310 | break; |
| 8311 | } |
| 8312 | } |
| 8313 | |
| 8314 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8315 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8316 | |
| 8317 | out_freepage: |
| 8318 | put_page(page); |
| 8319 | if (err == -EACCES) |
| 8320 | return -EPERM; |
| 8321 | out: |
| 8322 | return err; |
| 8323 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8324 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8325 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8326 | nfs4_stateid *stateid, |
| 8327 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8328 | { |
| 8329 | int status; |
| 8330 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8331 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8332 | }; |
| 8333 | struct nfs41_test_stateid_res res; |
| 8334 | struct rpc_message msg = { |
| 8335 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8336 | .rpc_argp = &args, |
| 8337 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8338 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8339 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8340 | struct rpc_clnt *rpc_client = server->client; |
| 8341 | |
| 8342 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8343 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8344 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8345 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8346 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8347 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8348 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8349 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8350 | if (status != NFS_OK) { |
| 8351 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8352 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8353 | } |
| 8354 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8355 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8356 | } |
| 8357 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8358 | /** |
| 8359 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8360 | * |
| 8361 | * @server: server / transport on which to perform the operation |
| 8362 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8363 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8364 | * |
| 8365 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8366 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8367 | * failed or the state ID is not currently valid. |
| 8368 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8369 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8370 | nfs4_stateid *stateid, |
| 8371 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8372 | { |
| 8373 | struct nfs4_exception exception = { }; |
| 8374 | int err; |
| 8375 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8376 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8377 | if (err != -NFS4ERR_DELAY) |
| 8378 | break; |
| 8379 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8380 | } while (exception.retry); |
| 8381 | return err; |
| 8382 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8383 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8384 | struct nfs_free_stateid_data { |
| 8385 | struct nfs_server *server; |
| 8386 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8387 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8388 | }; |
| 8389 | |
| 8390 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8391 | { |
| 8392 | struct nfs_free_stateid_data *data = calldata; |
| 8393 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8394 | &data->args.seq_args, |
| 8395 | &data->res.seq_res, |
| 8396 | task); |
| 8397 | } |
| 8398 | |
| 8399 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8400 | { |
| 8401 | struct nfs_free_stateid_data *data = calldata; |
| 8402 | |
| 8403 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8404 | |
| 8405 | switch (task->tk_status) { |
| 8406 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8407 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8408 | rpc_restart_call_prepare(task); |
| 8409 | } |
| 8410 | } |
| 8411 | |
| 8412 | static void nfs41_free_stateid_release(void *calldata) |
| 8413 | { |
| 8414 | kfree(calldata); |
| 8415 | } |
| 8416 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8417 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8418 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8419 | .rpc_call_done = nfs41_free_stateid_done, |
| 8420 | .rpc_release = nfs41_free_stateid_release, |
| 8421 | }; |
| 8422 | |
| 8423 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8424 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8425 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8426 | bool privileged) |
| 8427 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8428 | struct rpc_message msg = { |
| 8429 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8430 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8431 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8432 | struct rpc_task_setup task_setup = { |
| 8433 | .rpc_client = server->client, |
| 8434 | .rpc_message = &msg, |
| 8435 | .callback_ops = &nfs41_free_stateid_ops, |
| 8436 | .flags = RPC_TASK_ASYNC, |
| 8437 | }; |
| 8438 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8439 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8440 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8441 | &task_setup.rpc_client, &msg); |
| 8442 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8443 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8444 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8445 | if (!data) |
| 8446 | return ERR_PTR(-ENOMEM); |
| 8447 | data->server = server; |
| 8448 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8449 | |
| 8450 | task_setup.callback_data = data; |
| 8451 | |
| 8452 | msg.rpc_argp = &data->args; |
| 8453 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8454 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8455 | if (privileged) |
| 8456 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8457 | |
| 8458 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8459 | } |
| 8460 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8461 | /** |
| 8462 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8463 | * |
| 8464 | * @server: server / transport on which to perform the operation |
| 8465 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8466 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8467 | * |
| 8468 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8469 | * negative NFS4ERR value is returned. |
| 8470 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8471 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8472 | nfs4_stateid *stateid, |
| 8473 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8474 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8475 | struct rpc_task *task; |
| 8476 | int ret; |
| 8477 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8478 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8479 | if (IS_ERR(task)) |
| 8480 | return PTR_ERR(task); |
| 8481 | ret = rpc_wait_for_completion_task(task); |
| 8482 | if (!ret) |
| 8483 | ret = task->tk_status; |
| 8484 | rpc_put_task(task); |
| 8485 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8486 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8487 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8488 | static void |
| 8489 | 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] | 8490 | { |
| 8491 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8492 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8493 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8494 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8495 | nfs4_free_lock_state(server, lsp); |
| 8496 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8497 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8498 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8499 | } |
| 8500 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8501 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8502 | const nfs4_stateid *s2) |
| 8503 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8504 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8505 | return false; |
| 8506 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8507 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8508 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8509 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8510 | return true; |
| 8511 | |
| 8512 | return false; |
| 8513 | } |
| 8514 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8515 | #endif /* CONFIG_NFS_V4_1 */ |
| 8516 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8517 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8518 | const nfs4_stateid *s2) |
| 8519 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8520 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8521 | } |
| 8522 | |
| 8523 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8524 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8525 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8526 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8527 | .recover_open = nfs4_open_reclaim, |
| 8528 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8529 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8530 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8531 | }; |
| 8532 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8533 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8534 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8535 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8536 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8537 | .recover_open = nfs4_open_reclaim, |
| 8538 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8539 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8540 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8541 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8542 | }; |
| 8543 | #endif /* CONFIG_NFS_V4_1 */ |
| 8544 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8545 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8546 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8547 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8548 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8549 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8550 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8551 | }; |
| 8552 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8553 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8554 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8555 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8556 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8557 | .recover_open = nfs41_open_expired, |
| 8558 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8559 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8560 | }; |
| 8561 | #endif /* CONFIG_NFS_V4_1 */ |
| 8562 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8563 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8564 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8565 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8566 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8567 | }; |
| 8568 | |
| 8569 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8570 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8571 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 8572 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 8573 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 8574 | }; |
| 8575 | #endif |
| 8576 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8577 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8578 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8579 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8580 | }; |
| 8581 | |
| 8582 | #if defined(CONFIG_NFS_V4_1) |
| 8583 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 8584 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 8585 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8586 | }; |
| 8587 | #endif /* CONFIG_NFS_V4_1 */ |
| 8588 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8589 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 8590 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8591 | .init_caps = NFS_CAP_READDIRPLUS |
| 8592 | | NFS_CAP_ATOMIC_OPEN |
| 8593 | | NFS_CAP_CHANGE_ATTR |
| 8594 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8595 | .init_client = nfs40_init_client, |
| 8596 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8597 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8598 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8599 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8600 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8601 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8602 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8603 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 8604 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8605 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8606 | }; |
| 8607 | |
| 8608 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8609 | static struct nfs_seqid * |
| 8610 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 8611 | { |
| 8612 | return NULL; |
| 8613 | } |
| 8614 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8615 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8616 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 8617 | .init_caps = NFS_CAP_READDIRPLUS |
| 8618 | | NFS_CAP_ATOMIC_OPEN |
| 8619 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 8620 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 8621 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8622 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8623 | .init_client = nfs41_init_client, |
| 8624 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8625 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8626 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8627 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8628 | .alloc_seqid = nfs_alloc_no_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8629 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 8630 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8631 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8632 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 8633 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8634 | }; |
| 8635 | #endif |
| 8636 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8637 | #if defined(CONFIG_NFS_V4_2) |
| 8638 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 8639 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8640 | .init_caps = NFS_CAP_READDIRPLUS |
| 8641 | | NFS_CAP_ATOMIC_OPEN |
| 8642 | | NFS_CAP_CHANGE_ATTR |
| 8643 | | NFS_CAP_POSIX_LOCK |
| 8644 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 8645 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 8646 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 8647 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 8648 | | NFS_CAP_SEEK |
| 8649 | | NFS_CAP_LAYOUTSTATS, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 8650 | .init_client = nfs41_init_client, |
| 8651 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8652 | .match_stateid = nfs41_match_stateid, |
| 8653 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 8654 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 8655 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 8656 | .alloc_seqid = nfs_alloc_no_seqid, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8657 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8658 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8659 | .state_renewal_ops = &nfs41_state_renewal_ops, |
| 8660 | }; |
| 8661 | #endif |
| 8662 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8663 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 8664 | [0] = &nfs_v4_0_minor_ops, |
| 8665 | #if defined(CONFIG_NFS_V4_1) |
| 8666 | [1] = &nfs_v4_1_minor_ops, |
| 8667 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 8668 | #if defined(CONFIG_NFS_V4_2) |
| 8669 | [2] = &nfs_v4_2_minor_ops, |
| 8670 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8671 | }; |
| 8672 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8673 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 8674 | .create = nfs_create, |
| 8675 | .lookup = nfs_lookup, |
| 8676 | .atomic_open = nfs_atomic_open, |
| 8677 | .link = nfs_link, |
| 8678 | .unlink = nfs_unlink, |
| 8679 | .symlink = nfs_symlink, |
| 8680 | .mkdir = nfs_mkdir, |
| 8681 | .rmdir = nfs_rmdir, |
| 8682 | .mknod = nfs_mknod, |
| 8683 | .rename = nfs_rename, |
| 8684 | .permission = nfs_permission, |
| 8685 | .getattr = nfs_getattr, |
| 8686 | .setattr = nfs_setattr, |
| 8687 | .getxattr = generic_getxattr, |
| 8688 | .setxattr = generic_setxattr, |
| 8689 | .listxattr = generic_listxattr, |
| 8690 | .removexattr = generic_removexattr, |
| 8691 | }; |
| 8692 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 8693 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8694 | .permission = nfs_permission, |
| 8695 | .getattr = nfs_getattr, |
| 8696 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8697 | .getxattr = generic_getxattr, |
| 8698 | .setxattr = generic_setxattr, |
| 8699 | .listxattr = generic_listxattr, |
| 8700 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8701 | }; |
| 8702 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 8703 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8704 | .version = 4, /* protocol version */ |
| 8705 | .dentry_ops = &nfs4_dentry_operations, |
| 8706 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 8707 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 8708 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8709 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 8710 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 8711 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8712 | .getattr = nfs4_proc_getattr, |
| 8713 | .setattr = nfs4_proc_setattr, |
| 8714 | .lookup = nfs4_proc_lookup, |
| 8715 | .access = nfs4_proc_access, |
| 8716 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8717 | .create = nfs4_proc_create, |
| 8718 | .remove = nfs4_proc_remove, |
| 8719 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8720 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8721 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8722 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8723 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8724 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8725 | .link = nfs4_proc_link, |
| 8726 | .symlink = nfs4_proc_symlink, |
| 8727 | .mkdir = nfs4_proc_mkdir, |
| 8728 | .rmdir = nfs4_proc_remove, |
| 8729 | .readdir = nfs4_proc_readdir, |
| 8730 | .mknod = nfs4_proc_mknod, |
| 8731 | .statfs = nfs4_proc_statfs, |
| 8732 | .fsinfo = nfs4_proc_fsinfo, |
| 8733 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8734 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8735 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 8736 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8737 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8738 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8739 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8740 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8741 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8742 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8743 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8744 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8745 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8746 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8747 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8748 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8749 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8750 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8751 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8752 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8753 | .create_server = nfs4_create_server, |
| 8754 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8755 | }; |
| 8756 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8757 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 8758 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 8759 | .list = nfs4_xattr_list_nfs4_acl, |
| 8760 | .get = nfs4_xattr_get_nfs4_acl, |
| 8761 | .set = nfs4_xattr_set_nfs4_acl, |
| 8762 | }; |
| 8763 | |
| 8764 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 8765 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8766 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 8767 | &nfs4_xattr_nfs4_label_handler, |
| 8768 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8769 | NULL |
| 8770 | }; |
| 8771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8772 | /* |
| 8773 | * Local variables: |
| 8774 | * c-basic-offset: 8 |
| 8775 | * End: |
| 8776 | */ |