| 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> | 
|  | 41 | #include <linux/string.h> | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> | 
|  | 43 | #include <linux/printk.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> | 
|  | 46 | #include <linux/nfs.h> | 
|  | 47 | #include <linux/nfs4.h> | 
|  | 48 | #include <linux/nfs_fs.h> | 
|  | 49 | #include <linux/nfs_page.h> | 
| Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> | 
| Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.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" | 
| Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" | 
| David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" | 
|  | 70 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY		NFSDBG_PROC | 
|  | 72 |  | 
| Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN	(HZ/10) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX	(15*HZ) | 
|  | 75 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 76 | struct nfs4_opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 77 | static int _nfs4_proc_open(struct nfs4_opendata *data); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 78 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 80 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); | 
| Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 81 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 82 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); | 
|  | 83 | 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] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
|  | 85 | struct nfs_fattr *fattr, struct iattr *sattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 86 | struct nfs4_state *state, struct nfs4_label *ilabel, | 
|  | 87 | struct nfs4_label *olabel); | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, | 
|  | 90 | struct rpc_cred *); | 
|  | 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, | 
|  | 92 | struct rpc_cred *); | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 93 | #endif | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 94 |  | 
|  | 95 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 96 | static inline struct nfs4_label * | 
|  | 97 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, | 
|  | 98 | struct iattr *sattr, struct nfs4_label *label) | 
|  | 99 | { | 
|  | 100 | int err; | 
|  | 101 |  | 
|  | 102 | if (label == NULL) | 
|  | 103 | return NULL; | 
|  | 104 |  | 
|  | 105 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) | 
|  | 106 | return NULL; | 
|  | 107 |  | 
|  | 108 | if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2) | 
|  | 109 | return NULL; | 
|  | 110 |  | 
|  | 111 | err = security_dentry_init_security(dentry, sattr->ia_mode, | 
|  | 112 | &dentry->d_name, (void **)&label->label, &label->len); | 
|  | 113 | if (err == 0) | 
|  | 114 | return label; | 
|  | 115 |  | 
|  | 116 | return NULL; | 
|  | 117 | } | 
|  | 118 | static inline void | 
|  | 119 | nfs4_label_release_security(struct nfs4_label *label) | 
|  | 120 | { | 
|  | 121 | if (label) | 
|  | 122 | security_release_secctx(label->label, label->len); | 
|  | 123 | } | 
|  | 124 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) | 
|  | 125 | { | 
|  | 126 | if (label) | 
|  | 127 | return server->attr_bitmask; | 
|  | 128 |  | 
|  | 129 | return server->attr_bitmask_nl; | 
|  | 130 | } | 
|  | 131 | #else | 
|  | 132 | static inline struct nfs4_label * | 
|  | 133 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, | 
|  | 134 | struct iattr *sattr, struct nfs4_label *l) | 
|  | 135 | { return NULL; } | 
|  | 136 | static inline void | 
|  | 137 | nfs4_label_release_security(struct nfs4_label *label) | 
|  | 138 | { return; } | 
|  | 139 | static inline u32 * | 
|  | 140 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) | 
|  | 141 | { return server->attr_bitmask; } | 
|  | 142 | #endif | 
|  | 143 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Prevent leaks of NFSv4 errors into userland */ | 
| WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 145 | static int nfs4_map_errors(int err) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 147 | if (err >= -1000) | 
|  | 148 | return err; | 
|  | 149 | switch (err) { | 
|  | 150 | case -NFS4ERR_RESOURCE: | 
| Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 151 | case -NFS4ERR_LAYOUTTRYLATER: | 
|  | 152 | case -NFS4ERR_RECALLCONFLICT: | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 153 | return -EREMOTEIO; | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 154 | case -NFS4ERR_WRONGSEC: | 
| Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 155 | case -NFS4ERR_WRONG_CRED: | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 156 | return -EPERM; | 
| Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 157 | case -NFS4ERR_BADOWNER: | 
|  | 158 | case -NFS4ERR_BADNAME: | 
|  | 159 | return -EINVAL; | 
| Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 160 | case -NFS4ERR_SHARE_DENIED: | 
|  | 161 | return -EACCES; | 
| Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 162 | case -NFS4ERR_MINOR_VERS_MISMATCH: | 
|  | 163 | return -EPROTONOSUPPORT; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 164 | case -NFS4ERR_ACCESS: | 
|  | 165 | return -EACCES; | 
| Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 166 | case -NFS4ERR_FILE_OPEN: | 
|  | 167 | return -EBUSY; | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 168 | default: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | dprintk("%s could not handle NFSv4 error %d\n", | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 170 | __func__, -err); | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 171 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 173 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } | 
|  | 175 |  | 
|  | 176 | /* | 
|  | 177 | * This is our standard bitmap for GETATTR requests. | 
|  | 178 | */ | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 179 | const u32 nfs4_fattr_bitmap[3] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | FATTR4_WORD0_TYPE | 
|  | 181 | | FATTR4_WORD0_CHANGE | 
|  | 182 | | FATTR4_WORD0_SIZE | 
|  | 183 | | FATTR4_WORD0_FSID | 
|  | 184 | | FATTR4_WORD0_FILEID, | 
|  | 185 | FATTR4_WORD1_MODE | 
|  | 186 | | FATTR4_WORD1_NUMLINKS | 
|  | 187 | | FATTR4_WORD1_OWNER | 
|  | 188 | | FATTR4_WORD1_OWNER_GROUP | 
|  | 189 | | FATTR4_WORD1_RAWDEV | 
|  | 190 | | FATTR4_WORD1_SPACE_USED | 
|  | 191 | | FATTR4_WORD1_TIME_ACCESS | 
|  | 192 | | FATTR4_WORD1_TIME_METADATA | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 193 | | FATTR4_WORD1_TIME_MODIFY, | 
|  | 194 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 195 | FATTR4_WORD2_SECURITY_LABEL | 
|  | 196 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | }; | 
|  | 198 |  | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 199 | static const u32 nfs4_pnfs_open_bitmap[3] = { | 
|  | 200 | FATTR4_WORD0_TYPE | 
|  | 201 | | FATTR4_WORD0_CHANGE | 
|  | 202 | | FATTR4_WORD0_SIZE | 
|  | 203 | | FATTR4_WORD0_FSID | 
|  | 204 | | FATTR4_WORD0_FILEID, | 
|  | 205 | FATTR4_WORD1_MODE | 
|  | 206 | | FATTR4_WORD1_NUMLINKS | 
|  | 207 | | FATTR4_WORD1_OWNER | 
|  | 208 | | FATTR4_WORD1_OWNER_GROUP | 
|  | 209 | | FATTR4_WORD1_RAWDEV | 
|  | 210 | | FATTR4_WORD1_SPACE_USED | 
|  | 211 | | FATTR4_WORD1_TIME_ACCESS | 
|  | 212 | | FATTR4_WORD1_TIME_METADATA | 
|  | 213 | | FATTR4_WORD1_TIME_MODIFY, | 
|  | 214 | FATTR4_WORD2_MDSTHRESHOLD | 
|  | 215 | }; | 
|  | 216 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 217 | static const u32 nfs4_open_noattr_bitmap[3] = { | 
|  | 218 | FATTR4_WORD0_TYPE | 
|  | 219 | | FATTR4_WORD0_CHANGE | 
|  | 220 | | FATTR4_WORD0_FILEID, | 
|  | 221 | }; | 
|  | 222 |  | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 223 | const u32 nfs4_statfs_bitmap[3] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | FATTR4_WORD0_FILES_AVAIL | 
|  | 225 | | FATTR4_WORD0_FILES_FREE | 
|  | 226 | | FATTR4_WORD0_FILES_TOTAL, | 
|  | 227 | FATTR4_WORD1_SPACE_AVAIL | 
|  | 228 | | FATTR4_WORD1_SPACE_FREE | 
|  | 229 | | FATTR4_WORD1_SPACE_TOTAL | 
|  | 230 | }; | 
|  | 231 |  | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 232 | const u32 nfs4_pathconf_bitmap[3] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | FATTR4_WORD0_MAXLINK | 
|  | 234 | | FATTR4_WORD0_MAXNAME, | 
|  | 235 | 0 | 
|  | 236 | }; | 
|  | 237 |  | 
| Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 238 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | | FATTR4_WORD0_MAXREAD | 
|  | 240 | | FATTR4_WORD0_MAXWRITE | 
|  | 241 | | FATTR4_WORD0_LEASE_TIME, | 
| Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 242 | FATTR4_WORD1_TIME_DELTA | 
| Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 243 | | FATTR4_WORD1_FS_LAYOUT_TYPES, | 
|  | 244 | FATTR4_WORD2_LAYOUT_BLKSIZE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | }; | 
|  | 246 |  | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 247 | const u32 nfs4_fs_locations_bitmap[3] = { | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 248 | FATTR4_WORD0_TYPE | 
|  | 249 | | FATTR4_WORD0_CHANGE | 
|  | 250 | | FATTR4_WORD0_SIZE | 
|  | 251 | | FATTR4_WORD0_FSID | 
|  | 252 | | FATTR4_WORD0_FILEID | 
|  | 253 | | FATTR4_WORD0_FS_LOCATIONS, | 
|  | 254 | FATTR4_WORD1_MODE | 
|  | 255 | | FATTR4_WORD1_NUMLINKS | 
|  | 256 | | FATTR4_WORD1_OWNER | 
|  | 257 | | FATTR4_WORD1_OWNER_GROUP | 
|  | 258 | | FATTR4_WORD1_RAWDEV | 
|  | 259 | | FATTR4_WORD1_SPACE_USED | 
|  | 260 | | FATTR4_WORD1_TIME_ACCESS | 
|  | 261 | | FATTR4_WORD1_TIME_METADATA | 
|  | 262 | | FATTR4_WORD1_TIME_MODIFY | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 263 | | FATTR4_WORD1_MOUNTED_ON_FILEID, | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 264 | }; | 
|  | 265 |  | 
| Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 266 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | struct nfs4_readdir_arg *readdir) | 
|  | 268 | { | 
| Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 269 | __be32 *start, *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | if (cookie > 2) { | 
| Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 272 | readdir->cookie = cookie; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); | 
|  | 274 | return; | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | readdir->cookie = 0; | 
|  | 278 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); | 
|  | 279 | if (cookie == 2) | 
|  | 280 | return; | 
|  | 281 |  | 
|  | 282 | /* | 
|  | 283 | * NFSv4 servers do not return entries for '.' and '..' | 
|  | 284 | * Therefore, we fake these entries here.  We let '.' | 
|  | 285 | * have cookie 0 and '..' have cookie 1.  Note that | 
|  | 286 | * when talking to the server, we always send cookie 0 | 
|  | 287 | * instead of 1 or 2. | 
|  | 288 | */ | 
| Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 289 | start = p = kmap_atomic(*readdir->pages); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 |  | 
|  | 291 | if (cookie == 0) { | 
|  | 292 | *p++ = xdr_one;                                  /* next */ | 
|  | 293 | *p++ = xdr_zero;                   /* cookie, first word */ | 
|  | 294 | *p++ = xdr_one;                   /* cookie, second word */ | 
|  | 295 | *p++ = xdr_one;                             /* entry len */ | 
|  | 296 | memcpy(p, ".\0\0\0", 4);                        /* entry */ | 
|  | 297 | p++; | 
|  | 298 | *p++ = xdr_one;                         /* bitmap length */ | 
|  | 299 | *p++ = htonl(FATTR4_WORD0_FILEID);             /* bitmap */ | 
|  | 300 | *p++ = htonl(8);              /* attribute buffer length */ | 
| Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 301 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } | 
|  | 303 |  | 
|  | 304 | *p++ = xdr_one;                                  /* next */ | 
|  | 305 | *p++ = xdr_zero;                   /* cookie, first word */ | 
|  | 306 | *p++ = xdr_two;                   /* cookie, second word */ | 
|  | 307 | *p++ = xdr_two;                             /* entry len */ | 
|  | 308 | memcpy(p, "..\0\0", 4);                         /* entry */ | 
|  | 309 | p++; | 
|  | 310 | *p++ = xdr_one;                         /* bitmap length */ | 
|  | 311 | *p++ = htonl(FATTR4_WORD0_FILEID);             /* bitmap */ | 
|  | 312 | *p++ = htonl(8);              /* attribute buffer length */ | 
| Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 313 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 |  | 
|  | 315 | readdir->pgbase = (char *)p - (char *)start; | 
|  | 316 | readdir->count -= readdir->pgbase; | 
| Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 317 | kunmap_atomic(start); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } | 
|  | 319 |  | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 320 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) | 
|  | 321 | { | 
|  | 322 | int res = 0; | 
|  | 323 |  | 
|  | 324 | might_sleep(); | 
|  | 325 |  | 
|  | 326 | if (*timeout <= 0) | 
|  | 327 | *timeout = NFS4_POLL_RETRY_MIN; | 
|  | 328 | if (*timeout > NFS4_POLL_RETRY_MAX) | 
|  | 329 | *timeout = NFS4_POLL_RETRY_MAX; | 
| Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 330 | freezable_schedule_timeout_killable_unsafe(*timeout); | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 331 | if (fatal_signal_pending(current)) | 
|  | 332 | res = -ERESTARTSYS; | 
|  | 333 | *timeout <<= 1; | 
|  | 334 | return res; | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | /* This is the error handling routine for processes that are allowed | 
|  | 338 | * to sleep. | 
|  | 339 | */ | 
| Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 340 | static 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] | 341 | { | 
|  | 342 | struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 343 | struct nfs4_state *state = exception->state; | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 344 | struct inode *inode = exception->inode; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | int ret = errorcode; | 
|  | 346 |  | 
|  | 347 | exception->retry = 0; | 
|  | 348 | switch(errorcode) { | 
|  | 349 | case 0: | 
|  | 350 | return 0; | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 351 | case -NFS4ERR_OPENMODE: | 
| Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 352 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 353 | nfs4_inode_return_delegation(inode); | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 354 | exception->retry = 1; | 
|  | 355 | return 0; | 
|  | 356 | } | 
|  | 357 | if (state == NULL) | 
|  | 358 | break; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 359 | ret = nfs4_schedule_stateid_recovery(server, state); | 
|  | 360 | if (ret < 0) | 
|  | 361 | break; | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 362 | goto wait_on_recovery; | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 363 | case -NFS4ERR_DELEG_REVOKED: | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 364 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 365 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 366 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { | 
|  | 367 | nfs_remove_bad_delegation(inode); | 
|  | 368 | exception->retry = 1; | 
|  | 369 | break; | 
|  | 370 | } | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 371 | if (state == NULL) | 
|  | 372 | break; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 373 | ret = nfs4_schedule_stateid_recovery(server, state); | 
|  | 374 | if (ret < 0) | 
|  | 375 | break; | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 376 | goto wait_on_recovery; | 
| Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 377 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 378 | if (state != NULL) { | 
|  | 379 | ret = nfs4_schedule_stateid_recovery(server, state); | 
|  | 380 | if (ret < 0) | 
|  | 381 | break; | 
|  | 382 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 384 | case -NFS4ERR_STALE_CLIENTID: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 385 | nfs4_schedule_lease_recovery(clp); | 
|  | 386 | goto wait_on_recovery; | 
| Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 387 | #if defined(CONFIG_NFS_V4_1) | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 388 | case -NFS4ERR_BADSESSION: | 
|  | 389 | case -NFS4ERR_BADSLOT: | 
|  | 390 | case -NFS4ERR_BAD_HIGH_SLOT: | 
|  | 391 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 392 | case -NFS4ERR_DEADSESSION: | 
|  | 393 | case -NFS4ERR_SEQ_FALSE_RETRY: | 
|  | 394 | case -NFS4ERR_SEQ_MISORDERED: | 
|  | 395 | dprintk("%s ERROR: %d Reset session\n", __func__, | 
|  | 396 | errorcode); | 
| Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 397 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); | 
| Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 398 | goto wait_on_recovery; | 
| Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 399 | #endif /* defined(CONFIG_NFS_V4_1) */ | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 400 | case -NFS4ERR_FILE_OPEN: | 
| NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 401 | if (exception->timeout > HZ) { | 
|  | 402 | /* We have retried a decent amount, time to | 
|  | 403 | * fail | 
|  | 404 | */ | 
|  | 405 | ret = -EBUSY; | 
|  | 406 | break; | 
|  | 407 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 408 | case -NFS4ERR_GRACE: | 
|  | 409 | case -NFS4ERR_DELAY: | 
|  | 410 | ret = nfs4_delay(server->client, &exception->timeout); | 
|  | 411 | if (ret != 0) | 
|  | 412 | break; | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 413 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 414 | case -NFS4ERR_OLD_STATEID: | 
|  | 415 | exception->retry = 1; | 
| Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 416 | break; | 
|  | 417 | case -NFS4ERR_BADOWNER: | 
|  | 418 | /* The following works around a Linux server bug! */ | 
|  | 419 | case -NFS4ERR_BADNAME: | 
|  | 420 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { | 
|  | 421 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; | 
|  | 422 | exception->retry = 1; | 
|  | 423 | printk(KERN_WARNING "NFS: v4 server %s " | 
|  | 424 | "does not accept raw " | 
|  | 425 | "uid/gids. " | 
|  | 426 | "Reenabling the idmapper.\n", | 
|  | 427 | server->nfs_client->cl_hostname); | 
|  | 428 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | } | 
|  | 430 | /* We failed to handle the error */ | 
|  | 431 | return nfs4_map_errors(ret); | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 432 | wait_on_recovery: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 433 | ret = nfs4_wait_clnt_recover(clp); | 
|  | 434 | if (ret == 0) | 
|  | 435 | exception->retry = 1; | 
|  | 436 | return ret; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | } | 
|  | 438 |  | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 439 | /* | 
|  | 440 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected | 
|  | 441 | * or 'false' otherwise. | 
|  | 442 | */ | 
|  | 443 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) | 
|  | 444 | { | 
|  | 445 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; | 
|  | 446 |  | 
|  | 447 | if (flavor == RPC_AUTH_GSS_KRB5I || | 
|  | 448 | flavor == RPC_AUTH_GSS_KRB5P) | 
|  | 449 | return true; | 
|  | 450 |  | 
|  | 451 | return false; | 
|  | 452 | } | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 453 |  | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 454 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | spin_lock(&clp->cl_lock); | 
|  | 457 | if (time_before(clp->cl_last_renewal,timestamp)) | 
|  | 458 | clp->cl_last_renewal = timestamp; | 
|  | 459 | spin_unlock(&clp->cl_lock); | 
|  | 460 | } | 
|  | 461 |  | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 462 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) | 
|  | 463 | { | 
|  | 464 | do_renew_lease(server->nfs_client, timestamp); | 
|  | 465 | } | 
|  | 466 |  | 
| Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 467 | struct nfs4_call_sync_data { | 
|  | 468 | const struct nfs_server *seq_server; | 
|  | 469 | struct nfs4_sequence_args *seq_args; | 
|  | 470 | struct nfs4_sequence_res *seq_res; | 
|  | 471 | }; | 
|  | 472 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 473 | static void nfs4_init_sequence(struct nfs4_sequence_args *args, | 
|  | 474 | struct nfs4_sequence_res *res, int cache_reply) | 
|  | 475 | { | 
|  | 476 | args->sa_slot = NULL; | 
|  | 477 | args->sa_cache_this = cache_reply; | 
|  | 478 | args->sa_privileged = 0; | 
|  | 479 |  | 
|  | 480 | res->sr_slot = NULL; | 
|  | 481 | } | 
|  | 482 |  | 
|  | 483 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) | 
|  | 484 | { | 
|  | 485 | args->sa_privileged = 1; | 
|  | 486 | } | 
|  | 487 |  | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 488 | static int nfs40_setup_sequence(const struct nfs_server *server, | 
|  | 489 | struct nfs4_sequence_args *args, | 
|  | 490 | struct nfs4_sequence_res *res, | 
|  | 491 | struct rpc_task *task) | 
|  | 492 | { | 
|  | 493 | struct nfs4_slot_table *tbl = server->nfs_client->cl_slot_tbl; | 
|  | 494 | struct nfs4_slot *slot; | 
|  | 495 |  | 
|  | 496 | /* slot already allocated? */ | 
|  | 497 | if (res->sr_slot != NULL) | 
|  | 498 | goto out_start; | 
|  | 499 |  | 
|  | 500 | spin_lock(&tbl->slot_tbl_lock); | 
|  | 501 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) | 
|  | 502 | goto out_sleep; | 
|  | 503 |  | 
|  | 504 | slot = nfs4_alloc_slot(tbl); | 
|  | 505 | if (IS_ERR(slot)) { | 
|  | 506 | if (slot == ERR_PTR(-ENOMEM)) | 
|  | 507 | task->tk_timeout = HZ >> 2; | 
|  | 508 | goto out_sleep; | 
|  | 509 | } | 
|  | 510 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 511 |  | 
|  | 512 | args->sa_slot = slot; | 
|  | 513 | res->sr_slot = slot; | 
|  | 514 |  | 
|  | 515 | out_start: | 
|  | 516 | rpc_call_start(task); | 
|  | 517 | return 0; | 
|  | 518 |  | 
|  | 519 | out_sleep: | 
|  | 520 | if (args->sa_privileged) | 
|  | 521 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, | 
|  | 522 | NULL, RPC_PRIORITY_PRIVILEGED); | 
|  | 523 | else | 
|  | 524 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); | 
|  | 525 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 526 | return -EAGAIN; | 
|  | 527 | } | 
|  | 528 |  | 
|  | 529 | static int nfs40_sequence_done(struct rpc_task *task, | 
|  | 530 | struct nfs4_sequence_res *res) | 
|  | 531 | { | 
|  | 532 | struct nfs4_slot *slot = res->sr_slot; | 
|  | 533 | struct nfs4_slot_table *tbl; | 
|  | 534 |  | 
|  | 535 | if (!RPC_WAS_SENT(task)) | 
|  | 536 | goto out; | 
|  | 537 |  | 
|  | 538 | tbl = slot->table; | 
|  | 539 | spin_lock(&tbl->slot_tbl_lock); | 
|  | 540 | if (!nfs41_wake_and_assign_slot(tbl, slot)) | 
|  | 541 | nfs4_free_slot(tbl, slot); | 
|  | 542 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 543 |  | 
|  | 544 | res->sr_slot = NULL; | 
|  | 545 | out: | 
|  | 546 | return 1; | 
|  | 547 | } | 
|  | 548 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 549 | #if defined(CONFIG_NFS_V4_1) | 
|  | 550 |  | 
| Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 551 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 552 | { | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 553 | struct nfs4_session *session; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 554 | struct nfs4_slot_table *tbl; | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 555 | bool send_new_highest_used_slotid = false; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 556 |  | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 557 | if (!res->sr_slot) { | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 558 | /* just wake up the next guy waiting since | 
|  | 559 | * we may have not consumed a slot after all */ | 
| Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 560 | dprintk("%s: No slot\n", __func__); | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 561 | return; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 562 | } | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 563 | tbl = res->sr_slot->table; | 
|  | 564 | session = tbl->session; | 
| Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 565 |  | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 566 | spin_lock(&tbl->slot_tbl_lock); | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 567 | /* Be nice to the server: try to ensure that the last transmitted | 
|  | 568 | * value for highest_user_slotid <= target_highest_slotid | 
|  | 569 | */ | 
|  | 570 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) | 
|  | 571 | send_new_highest_used_slotid = true; | 
|  | 572 |  | 
| Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 573 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { | 
|  | 574 | send_new_highest_used_slotid = false; | 
|  | 575 | goto out_unlock; | 
|  | 576 | } | 
| Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 577 | nfs4_free_slot(tbl, res->sr_slot); | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 578 |  | 
|  | 579 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) | 
|  | 580 | send_new_highest_used_slotid = false; | 
| Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 581 | out_unlock: | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 582 | spin_unlock(&tbl->slot_tbl_lock); | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 583 | res->sr_slot = NULL; | 
| Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 584 | if (send_new_highest_used_slotid) | 
|  | 585 | nfs41_server_notify_highest_slotid_update(session->clp); | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 586 | } | 
|  | 587 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 588 | static 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] | 589 | { | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 590 | struct nfs4_session *session; | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 591 | struct nfs4_slot *slot; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 592 | struct nfs_client *clp; | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 593 | bool interrupted = false; | 
| Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 594 | int ret = 1; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 595 |  | 
| Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 596 | /* don't increment the sequence number if the task wasn't sent */ | 
|  | 597 | if (!RPC_WAS_SENT(task)) | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 598 | goto out; | 
|  | 599 |  | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 600 | slot = res->sr_slot; | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 601 | session = slot->table->session; | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 602 |  | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 603 | if (slot->interrupted) { | 
|  | 604 | slot->interrupted = 0; | 
|  | 605 | interrupted = true; | 
|  | 606 | } | 
|  | 607 |  | 
| Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 608 | trace_nfs4_sequence_done(session, res); | 
| Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 609 | /* Check the SEQUENCE operation status */ | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 610 | switch (res->sr_status) { | 
|  | 611 | case 0: | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 612 | /* Update the slot's sequence and clientid lease timer */ | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 613 | ++slot->seq_nr; | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 614 | clp = session->clp; | 
| Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 615 | do_renew_lease(clp, res->sr_timestamp); | 
| Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 616 | /* Check sequence flags */ | 
| Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 617 | if (res->sr_status_flags != 0) | 
|  | 618 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 619 | nfs41_update_target_slotid(slot->table, slot, res); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 620 | break; | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 621 | case 1: | 
|  | 622 | /* | 
|  | 623 | * sr_status remains 1 if an RPC level error occurred. | 
|  | 624 | * The server may or may not have processed the sequence | 
|  | 625 | * operation.. | 
|  | 626 | * Mark the slot as having hosted an interrupted RPC call. | 
|  | 627 | */ | 
|  | 628 | slot->interrupted = 1; | 
|  | 629 | goto out; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 630 | case -NFS4ERR_DELAY: | 
|  | 631 | /* The server detected a resend of the RPC call and | 
|  | 632 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 | 
|  | 633 | * of RFC5661. | 
|  | 634 | */ | 
| Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 635 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 636 | __func__, | 
| Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 637 | slot->slot_nr, | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 638 | slot->seq_nr); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 639 | goto out_retry; | 
| Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 640 | case -NFS4ERR_BADSLOT: | 
|  | 641 | /* | 
|  | 642 | * The slot id we used was probably retired. Try again | 
|  | 643 | * using a different slot id. | 
|  | 644 | */ | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 645 | goto retry_nowait; | 
|  | 646 | case -NFS4ERR_SEQ_MISORDERED: | 
|  | 647 | /* | 
| Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 648 | * Was the last operation on this sequence interrupted? | 
|  | 649 | * If so, retry after bumping the sequence number. | 
|  | 650 | */ | 
|  | 651 | if (interrupted) { | 
|  | 652 | ++slot->seq_nr; | 
|  | 653 | goto retry_nowait; | 
|  | 654 | } | 
|  | 655 | /* | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 656 | * Could this slot have been previously retired? | 
|  | 657 | * If so, then the server may be expecting seq_nr = 1! | 
|  | 658 | */ | 
| Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 659 | if (slot->seq_nr != 1) { | 
|  | 660 | slot->seq_nr = 1; | 
|  | 661 | goto retry_nowait; | 
|  | 662 | } | 
|  | 663 | break; | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 664 | case -NFS4ERR_SEQ_FALSE_RETRY: | 
|  | 665 | ++slot->seq_nr; | 
|  | 666 | goto retry_nowait; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 667 | default: | 
|  | 668 | /* Just update the slot sequence no. */ | 
| Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 669 | ++slot->seq_nr; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 670 | } | 
|  | 671 | out: | 
|  | 672 | /* The session may be reset by one of the error handlers. */ | 
|  | 673 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); | 
| Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 674 | nfs41_sequence_free_slot(res); | 
| Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 675 | return ret; | 
| Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 676 | retry_nowait: | 
|  | 677 | if (rpc_restart_call_prepare(task)) { | 
|  | 678 | task->tk_status = 0; | 
|  | 679 | ret = 0; | 
|  | 680 | } | 
|  | 681 | goto out; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 682 | out_retry: | 
| Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 683 | if (!rpc_restart_call(task)) | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 684 | goto out; | 
|  | 685 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
|  | 686 | return 0; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 687 | } | 
|  | 688 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 689 | static int nfs4_sequence_done(struct rpc_task *task, | 
|  | 690 | struct nfs4_sequence_res *res) | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 691 | { | 
| Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 692 | if (res->sr_slot == NULL) | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 693 | return 1; | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 694 | if (!res->sr_slot->table->session) | 
|  | 695 | return nfs40_sequence_done(task, res); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 696 | return nfs41_sequence_done(task, res); | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 697 | } | 
|  | 698 |  | 
| Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 699 | int nfs41_setup_sequence(struct nfs4_session *session, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 700 | struct nfs4_sequence_args *args, | 
|  | 701 | struct nfs4_sequence_res *res, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 702 | struct rpc_task *task) | 
|  | 703 | { | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 704 | struct nfs4_slot *slot; | 
|  | 705 | struct nfs4_slot_table *tbl; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 706 |  | 
|  | 707 | dprintk("--> %s\n", __func__); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 708 | /* slot already allocated? */ | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 709 | if (res->sr_slot != NULL) | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 710 | goto out_success; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 711 |  | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 712 | tbl = &session->fc_slot_table; | 
|  | 713 |  | 
| Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 714 | task->tk_timeout = 0; | 
|  | 715 |  | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 716 | spin_lock(&tbl->slot_tbl_lock); | 
| Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 717 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 718 | !args->sa_privileged) { | 
| Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 719 | /* The state manager will wait until the slot table is empty */ | 
| Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 720 | dprintk("%s session is draining\n", __func__); | 
| Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 721 | goto out_sleep; | 
| Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 722 | } | 
|  | 723 |  | 
| Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 724 | slot = nfs4_alloc_slot(tbl); | 
| Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 725 | if (IS_ERR(slot)) { | 
|  | 726 | /* If out of memory, try again in 1/4 second */ | 
|  | 727 | if (slot == ERR_PTR(-ENOMEM)) | 
|  | 728 | task->tk_timeout = HZ >> 2; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 729 | dprintk("<-- %s: no free slots\n", __func__); | 
| Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 730 | goto out_sleep; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 731 | } | 
|  | 732 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 733 |  | 
| Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 734 | args->sa_slot = slot; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 735 |  | 
| Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 736 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, | 
| Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 737 | slot->slot_nr, slot->seq_nr); | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 738 |  | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 739 | res->sr_slot = slot; | 
| Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 740 | res->sr_timestamp = jiffies; | 
| Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 741 | res->sr_status_flags = 0; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 742 | /* | 
|  | 743 | * sr_status is only set in decode_sequence, and so will remain | 
|  | 744 | * set to 1 if an rpc level failure occurs. | 
|  | 745 | */ | 
|  | 746 | res->sr_status = 1; | 
| Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 747 | trace_nfs4_setup_sequence(session, args); | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 748 | out_success: | 
|  | 749 | rpc_call_start(task); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 750 | return 0; | 
| Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 751 | out_sleep: | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 752 | /* Privileged tasks are queued with top priority */ | 
|  | 753 | if (args->sa_privileged) | 
| Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 754 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, | 
|  | 755 | NULL, RPC_PRIORITY_PRIVILEGED); | 
|  | 756 | else | 
|  | 757 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); | 
| Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 758 | spin_unlock(&tbl->slot_tbl_lock); | 
|  | 759 | return -EAGAIN; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 760 | } | 
| Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 761 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 762 |  | 
| Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 763 | static int nfs4_setup_sequence(const struct nfs_server *server, | 
|  | 764 | struct nfs4_sequence_args *args, | 
|  | 765 | struct nfs4_sequence_res *res, | 
|  | 766 | struct rpc_task *task) | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 767 | { | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 768 | struct nfs4_session *session = nfs4_get_session(server); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 769 | int ret = 0; | 
|  | 770 |  | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 771 | if (!session) | 
|  | 772 | return nfs40_setup_sequence(server, args, res, task); | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 773 |  | 
| Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 774 | dprintk("--> %s clp %p session %p sr_slot %u\n", | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 775 | __func__, session->clp, session, res->sr_slot ? | 
| Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 776 | res->sr_slot->slot_nr : NFS4_NO_SLOT); | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 777 |  | 
| Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 778 | ret = nfs41_setup_sequence(session, args, res, task); | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 779 |  | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 780 | dprintk("<-- %s status=%d\n", __func__, ret); | 
|  | 781 | return ret; | 
|  | 782 | } | 
|  | 783 |  | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 784 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) | 
|  | 785 | { | 
| Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 786 | struct nfs4_call_sync_data *data = calldata; | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 787 | struct nfs4_session *session = nfs4_get_session(data->seq_server); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 788 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 789 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); | 
|  | 790 |  | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 791 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 792 | } | 
|  | 793 |  | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 794 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) | 
|  | 795 | { | 
| Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 796 | struct nfs4_call_sync_data *data = calldata; | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 797 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | nfs41_sequence_done(task, data->seq_res); | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 799 | } | 
|  | 800 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 801 | static const struct rpc_call_ops nfs41_call_sync_ops = { | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 802 | .rpc_call_prepare = nfs41_call_sync_prepare, | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 803 | .rpc_call_done = nfs41_call_sync_done, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 804 | }; | 
|  | 805 |  | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 806 | #else	/* !CONFIG_NFS_V4_1 */ | 
|  | 807 |  | 
| Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 808 | static int nfs4_setup_sequence(const struct nfs_server *server, | 
|  | 809 | struct nfs4_sequence_args *args, | 
|  | 810 | struct nfs4_sequence_res *res, | 
|  | 811 | struct rpc_task *task) | 
|  | 812 | { | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 813 | return nfs40_setup_sequence(server, args, res, task); | 
| Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 814 | } | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 815 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 816 | static int nfs4_sequence_done(struct rpc_task *task, | 
|  | 817 | struct nfs4_sequence_res *res) | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 818 | { | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 819 | return nfs40_sequence_done(task, res); | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 820 | } | 
| Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 821 |  | 
|  | 822 | #endif	/* !CONFIG_NFS_V4_1 */ | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 823 |  | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 824 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) | 
|  | 825 | { | 
|  | 826 | struct nfs4_call_sync_data *data = calldata; | 
|  | 827 | nfs4_setup_sequence(data->seq_server, | 
|  | 828 | data->seq_args, data->seq_res, task); | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) | 
|  | 832 | { | 
|  | 833 | struct nfs4_call_sync_data *data = calldata; | 
|  | 834 | nfs4_sequence_done(task, data->seq_res); | 
|  | 835 | } | 
|  | 836 |  | 
|  | 837 | static const struct rpc_call_ops nfs40_call_sync_ops = { | 
|  | 838 | .rpc_call_prepare = nfs40_call_sync_prepare, | 
|  | 839 | .rpc_call_done = nfs40_call_sync_done, | 
|  | 840 | }; | 
|  | 841 |  | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 842 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 843 | struct nfs_server *server, | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 844 | struct rpc_message *msg, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 845 | struct nfs4_sequence_args *args, | 
|  | 846 | struct nfs4_sequence_res *res) | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 847 | { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 848 | int ret; | 
|  | 849 | struct rpc_task *task; | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 850 | struct nfs_client *clp = server->nfs_client; | 
|  | 851 | struct nfs4_call_sync_data data = { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | .seq_server = server, | 
|  | 853 | .seq_args = args, | 
|  | 854 | .seq_res = res, | 
|  | 855 | }; | 
|  | 856 | struct rpc_task_setup task_setup = { | 
|  | 857 | .rpc_client = clnt, | 
|  | 858 | .rpc_message = msg, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 859 | .callback_ops = clp->cl_mvops->call_sync_ops, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 860 | .callback_data = &data | 
|  | 861 | }; | 
|  | 862 |  | 
|  | 863 | task = rpc_run_task(&task_setup); | 
|  | 864 | if (IS_ERR(task)) | 
|  | 865 | ret = PTR_ERR(task); | 
|  | 866 | else { | 
|  | 867 | ret = task->tk_status; | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 868 | rpc_put_task(task); | 
|  | 869 | } | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 870 | return ret; | 
|  | 871 | } | 
|  | 872 |  | 
| Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 873 | static | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 874 | int nfs4_call_sync(struct rpc_clnt *clnt, | 
|  | 875 | struct nfs_server *server, | 
| Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 876 | struct rpc_message *msg, | 
|  | 877 | struct nfs4_sequence_args *args, | 
|  | 878 | struct nfs4_sequence_res *res, | 
|  | 879 | int cache_reply) | 
|  | 880 | { | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 881 | nfs4_init_sequence(args, res, cache_reply); | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 882 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); | 
| Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 883 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 |  | 
|  | 885 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) | 
|  | 886 | { | 
|  | 887 | struct nfs_inode *nfsi = NFS_I(dir); | 
|  | 888 |  | 
|  | 889 | spin_lock(&dir->i_lock); | 
| Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 890 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; | 
| Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 891 | if (!cinfo->atomic || cinfo->before != dir->i_version) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | nfs_force_lookup_revalidate(dir); | 
| Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 893 | dir->i_version = cinfo->after; | 
| David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 894 | nfs_fscache_invalidate(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | spin_unlock(&dir->i_lock); | 
|  | 896 | } | 
|  | 897 |  | 
|  | 898 | struct nfs4_opendata { | 
|  | 899 | struct kref kref; | 
|  | 900 | struct nfs_openargs o_arg; | 
|  | 901 | struct nfs_openres o_res; | 
|  | 902 | struct nfs_open_confirmargs c_arg; | 
|  | 903 | struct nfs_open_confirmres c_res; | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 904 | struct nfs4_string owner_name; | 
|  | 905 | struct nfs4_string group_name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | struct nfs_fattr f_attr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 907 | struct nfs4_label *f_label; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | struct dentry *dir; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 909 | struct dentry *dentry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | struct nfs4_state_owner *owner; | 
|  | 911 | struct nfs4_state *state; | 
|  | 912 | struct iattr attrs; | 
|  | 913 | unsigned long timestamp; | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 914 | unsigned int rpc_done : 1; | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 915 | unsigned int file_created : 1; | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 916 | unsigned int is_recover : 1; | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 917 | int rpc_status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | int cancelled; | 
|  | 919 | }; | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 920 |  | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 921 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, | 
|  | 922 | int err, struct nfs4_exception *exception) | 
|  | 923 | { | 
|  | 924 | if (err != -EINVAL) | 
|  | 925 | return false; | 
|  | 926 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) | 
|  | 927 | return false; | 
|  | 928 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; | 
|  | 929 | exception->retry = 1; | 
|  | 930 | return true; | 
|  | 931 | } | 
|  | 932 |  | 
|  | 933 | static enum open_claim_type4 | 
|  | 934 | nfs4_map_atomic_open_claim(struct nfs_server *server, | 
|  | 935 | enum open_claim_type4 claim) | 
|  | 936 | { | 
|  | 937 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) | 
|  | 938 | return claim; | 
|  | 939 | switch (claim) { | 
|  | 940 | default: | 
|  | 941 | return claim; | 
|  | 942 | case NFS4_OPEN_CLAIM_FH: | 
|  | 943 | return NFS4_OPEN_CLAIM_NULL; | 
|  | 944 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
|  | 945 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; | 
|  | 946 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | 
|  | 947 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; | 
|  | 948 | } | 
|  | 949 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 |  | 
|  | 951 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 952 | { | 
|  | 953 | p->o_res.f_attr = &p->f_attr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 954 | p->o_res.f_label = p->f_label; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 955 | p->o_res.seqid = p->o_arg.seqid; | 
|  | 956 | p->c_res.seqid = p->c_arg.seqid; | 
|  | 957 | p->o_res.server = p->o_arg.server; | 
| Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 958 | p->o_res.access_request = p->o_arg.access; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 959 | nfs_fattr_init(&p->f_attr); | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 960 | 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] | 961 | } | 
|  | 962 |  | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 963 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 964 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 965 | const struct iattr *attrs, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 966 | struct nfs4_label *label, | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 967 | enum open_claim_type4 claim, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 968 | gfp_t gfp_mask) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 969 | { | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 970 | struct dentry *parent = dget_parent(dentry); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 971 | struct inode *dir = parent->d_inode; | 
|  | 972 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 973 | struct nfs4_opendata *p; | 
|  | 974 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 975 | p = kzalloc(sizeof(*p), gfp_mask); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 976 | if (p == NULL) | 
|  | 977 | goto err; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 978 |  | 
|  | 979 | p->f_label = nfs4_label_alloc(server, gfp_mask); | 
|  | 980 | if (IS_ERR(p->f_label)) | 
|  | 981 | goto err_free_p; | 
|  | 982 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 983 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 984 | if (p->o_arg.seqid == NULL) | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 985 | goto err_free_label; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 986 | nfs_sb_active(dentry->d_sb); | 
|  | 987 | p->dentry = dget(dentry); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 988 | p->dir = parent; | 
|  | 989 | p->owner = sp; | 
|  | 990 | atomic_inc(&sp->so_count); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 991 | p->o_arg.open_flags = flags; | 
|  | 992 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); | 
| Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 993 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS | 
|  | 994 | * will return permission denied for all bits until close */ | 
|  | 995 | if (!(flags & O_EXCL)) { | 
|  | 996 | /* ask server to check for all possible rights as results | 
|  | 997 | * are cached */ | 
|  | 998 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | | 
|  | 999 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; | 
| Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1000 | } | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1001 | p->o_arg.clientid = server->nfs_client->cl_clientid; | 
| Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1002 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); | 
|  | 1003 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1004 | p->o_arg.name = &dentry->d_name; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1005 | p->o_arg.server = server; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1006 | p->o_arg.bitmask = nfs4_bitmask(server, label); | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1007 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1008 | p->o_arg.label = label; | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1009 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); | 
|  | 1010 | switch (p->o_arg.claim) { | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1011 | case NFS4_OPEN_CLAIM_NULL: | 
|  | 1012 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: | 
|  | 1013 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: | 
|  | 1014 | p->o_arg.fh = NFS_FH(dir); | 
|  | 1015 | break; | 
|  | 1016 | case NFS4_OPEN_CLAIM_PREVIOUS: | 
|  | 1017 | case NFS4_OPEN_CLAIM_FH: | 
|  | 1018 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
|  | 1019 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | 
|  | 1020 | p->o_arg.fh = NFS_FH(dentry->d_inode); | 
|  | 1021 | } | 
| Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1022 | if (attrs != NULL && attrs->ia_valid != 0) { | 
| Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1023 | __u32 verf[2]; | 
| Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1024 |  | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1025 | p->o_arg.u.attrs = &p->attrs; | 
|  | 1026 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1027 |  | 
|  | 1028 | verf[0] = jiffies; | 
|  | 1029 | verf[1] = current->pid; | 
|  | 1030 | memcpy(p->o_arg.u.verifier.data, verf, | 
|  | 1031 | sizeof(p->o_arg.u.verifier.data)); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1032 | } | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1033 | p->c_arg.fh = &p->o_res.fh; | 
|  | 1034 | p->c_arg.stateid = &p->o_res.stateid; | 
|  | 1035 | p->c_arg.seqid = p->o_arg.seqid; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1036 | nfs4_init_opendata_res(p); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1037 | kref_init(&p->kref); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1038 | return p; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1039 |  | 
|  | 1040 | err_free_label: | 
|  | 1041 | nfs4_label_free(p->f_label); | 
|  | 1042 | err_free_p: | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1043 | kfree(p); | 
|  | 1044 | err: | 
|  | 1045 | dput(parent); | 
|  | 1046 | return NULL; | 
|  | 1047 | } | 
|  | 1048 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1049 | static void nfs4_opendata_free(struct kref *kref) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1050 | { | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1051 | struct nfs4_opendata *p = container_of(kref, | 
|  | 1052 | struct nfs4_opendata, kref); | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1053 | struct super_block *sb = p->dentry->d_sb; | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1054 |  | 
|  | 1055 | nfs_free_seqid(p->o_arg.seqid); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1056 | if (p->state != NULL) | 
|  | 1057 | nfs4_put_open_state(p->state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1058 | nfs4_put_state_owner(p->owner); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1059 |  | 
|  | 1060 | nfs4_label_free(p->f_label); | 
|  | 1061 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1062 | dput(p->dir); | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1063 | dput(p->dentry); | 
|  | 1064 | nfs_sb_deactive(sb); | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1065 | nfs_fattr_free_names(&p->f_attr); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1066 | kfree(p); | 
|  | 1067 | } | 
|  | 1068 |  | 
|  | 1069 | static void nfs4_opendata_put(struct nfs4_opendata *p) | 
|  | 1070 | { | 
|  | 1071 | if (p != NULL) | 
|  | 1072 | kref_put(&p->kref, nfs4_opendata_free); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1073 | } | 
|  | 1074 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1075 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) | 
|  | 1076 | { | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1077 | int ret; | 
|  | 1078 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1079 | ret = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1080 | return ret; | 
|  | 1081 | } | 
|  | 1082 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1083 | 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] | 1084 | { | 
|  | 1085 | int ret = 0; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1086 |  | 
| Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1087 | if (open_mode & (O_EXCL|O_TRUNC)) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1088 | goto out; | 
|  | 1089 | switch (mode & (FMODE_READ|FMODE_WRITE)) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | case FMODE_READ: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1091 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 | 
|  | 1092 | && state->n_rdonly != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1093 | break; | 
|  | 1094 | case FMODE_WRITE: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1095 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 | 
|  | 1096 | && state->n_wronly != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1097 | break; | 
|  | 1098 | case FMODE_READ|FMODE_WRITE: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1099 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 | 
|  | 1100 | && state->n_rdwr != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1101 | } | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1102 | out: | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1103 | return ret; | 
|  | 1104 | } | 
|  | 1105 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1106 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1107 | { | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1108 | if (delegation == NULL) | 
|  | 1109 | return 0; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | if ((delegation->type & fmode) != fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1111 | return 0; | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1112 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1113 | return 0; | 
| Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1114 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) | 
|  | 1115 | return 0; | 
| Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1116 | nfs_mark_delegation_referenced(delegation); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1117 | return 1; | 
|  | 1118 | } | 
|  | 1119 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1120 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1121 | { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1122 | switch (fmode) { | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1123 | case FMODE_WRITE: | 
|  | 1124 | state->n_wronly++; | 
|  | 1125 | break; | 
|  | 1126 | case FMODE_READ: | 
|  | 1127 | state->n_rdonly++; | 
|  | 1128 | break; | 
|  | 1129 | case FMODE_READ|FMODE_WRITE: | 
|  | 1130 | state->n_rdwr++; | 
|  | 1131 | } | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1132 | nfs4_state_set_mode_locked(state, state->state | fmode); | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1133 | } | 
|  | 1134 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1135 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1136 | { | 
|  | 1137 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1138 | nfs4_stateid_copy(&state->stateid, stateid); | 
|  | 1139 | nfs4_stateid_copy(&state->open_stateid, stateid); | 
| Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 1140 | set_bit(NFS_OPEN_STATE, &state->flags); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | switch (fmode) { | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1142 | case FMODE_READ: | 
|  | 1143 | set_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 1144 | break; | 
|  | 1145 | case FMODE_WRITE: | 
|  | 1146 | set_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 1147 | break; | 
|  | 1148 | case FMODE_READ|FMODE_WRITE: | 
|  | 1149 | set_bit(NFS_O_RDWR_STATE, &state->flags); | 
|  | 1150 | } | 
|  | 1151 | } | 
|  | 1152 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1153 | static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1154 | { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1155 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1156 | nfs_set_open_stateid_locked(state, stateid, fmode); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1157 | write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1158 | } | 
|  | 1159 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1160 | 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] | 1161 | { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1162 | /* | 
|  | 1163 | * Protect the call to nfs4_state_set_mode_locked and | 
|  | 1164 | * serialise the stateid update | 
|  | 1165 | */ | 
|  | 1166 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1167 | if (deleg_stateid != NULL) { | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1168 | nfs4_stateid_copy(&state->stateid, deleg_stateid); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1169 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 1170 | } | 
|  | 1171 | if (open_stateid != NULL) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1172 | nfs_set_open_stateid_locked(state, open_stateid, fmode); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1173 | write_sequnlock(&state->seqlock); | 
|  | 1174 | spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1175 | update_open_stateflags(state, fmode); | 
| Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1176 | spin_unlock(&state->owner->so_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | } | 
|  | 1178 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1179 | 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] | 1180 | { | 
|  | 1181 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
|  | 1182 | struct nfs_delegation *deleg_cur; | 
|  | 1183 | int ret = 0; | 
|  | 1184 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1185 | fmode &= (FMODE_READ|FMODE_WRITE); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1186 |  | 
|  | 1187 | rcu_read_lock(); | 
|  | 1188 | deleg_cur = rcu_dereference(nfsi->delegation); | 
|  | 1189 | if (deleg_cur == NULL) | 
|  | 1190 | goto no_delegation; | 
|  | 1191 |  | 
|  | 1192 | spin_lock(&deleg_cur->lock); | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1193 | if (rcu_dereference(nfsi->delegation) != deleg_cur || | 
| Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1194 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1195 | (deleg_cur->type & fmode) != fmode) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1196 | goto no_delegation_unlock; | 
|  | 1197 |  | 
|  | 1198 | if (delegation == NULL) | 
|  | 1199 | delegation = &deleg_cur->stateid; | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1200 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1201 | goto no_delegation_unlock; | 
|  | 1202 |  | 
| Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1203 | nfs_mark_delegation_referenced(deleg_cur); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1204 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1205 | ret = 1; | 
|  | 1206 | no_delegation_unlock: | 
|  | 1207 | spin_unlock(&deleg_cur->lock); | 
|  | 1208 | no_delegation: | 
|  | 1209 | rcu_read_unlock(); | 
|  | 1210 |  | 
|  | 1211 | if (!ret && open_stateid != NULL) { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1212 | __update_open_stateid(state, open_stateid, NULL, fmode); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1213 | ret = 1; | 
|  | 1214 | } | 
|  | 1215 |  | 
|  | 1216 | return ret; | 
|  | 1217 | } | 
|  | 1218 |  | 
|  | 1219 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1220 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1221 | { | 
|  | 1222 | struct nfs_delegation *delegation; | 
|  | 1223 |  | 
|  | 1224 | rcu_read_lock(); | 
|  | 1225 | delegation = rcu_dereference(NFS_I(inode)->delegation); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1226 | if (delegation == NULL || (delegation->type & fmode) == fmode) { | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1227 | rcu_read_unlock(); | 
|  | 1228 | return; | 
|  | 1229 | } | 
|  | 1230 | rcu_read_unlock(); | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1231 | nfs4_inode_return_delegation(inode); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1232 | } | 
|  | 1233 |  | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1234 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1235 | { | 
|  | 1236 | struct nfs4_state *state = opendata->state; | 
|  | 1237 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
|  | 1238 | struct nfs_delegation *delegation; | 
| Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1239 | int open_mode = opendata->o_arg.open_flags; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1240 | fmode_t fmode = opendata->o_arg.fmode; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1241 | nfs4_stateid stateid; | 
|  | 1242 | int ret = -EAGAIN; | 
|  | 1243 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1244 | for (;;) { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1245 | if (can_open_cached(state, fmode, open_mode)) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1246 | spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1247 | if (can_open_cached(state, fmode, open_mode)) { | 
|  | 1248 | update_open_stateflags(state, fmode); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1249 | spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1250 | goto out_return_state; | 
|  | 1251 | } | 
|  | 1252 | spin_unlock(&state->owner->so_lock); | 
|  | 1253 | } | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1254 | rcu_read_lock(); | 
|  | 1255 | delegation = rcu_dereference(nfsi->delegation); | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1256 | if (!can_open_delegated(delegation, fmode)) { | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1257 | rcu_read_unlock(); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1258 | break; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1259 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1260 | /* Save the delegation */ | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1261 | nfs4_stateid_copy(&stateid, &delegation->stateid); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1262 | rcu_read_unlock(); | 
| Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1263 | nfs_release_seqid(opendata->o_arg.seqid); | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1264 | if (!opendata->is_recover) { | 
|  | 1265 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); | 
|  | 1266 | if (ret != 0) | 
|  | 1267 | goto out; | 
|  | 1268 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1269 | ret = -EAGAIN; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1270 |  | 
|  | 1271 | /* Try to update the stateid using the delegation */ | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1272 | if (update_open_stateid(state, NULL, &stateid, fmode)) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1273 | goto out_return_state; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1274 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1275 | out: | 
|  | 1276 | return ERR_PTR(ret); | 
|  | 1277 | out_return_state: | 
|  | 1278 | atomic_inc(&state->count); | 
|  | 1279 | return state; | 
|  | 1280 | } | 
|  | 1281 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1282 | static void | 
|  | 1283 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) | 
|  | 1284 | { | 
|  | 1285 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; | 
|  | 1286 | struct nfs_delegation *delegation; | 
|  | 1287 | int delegation_flags = 0; | 
|  | 1288 |  | 
|  | 1289 | rcu_read_lock(); | 
|  | 1290 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
|  | 1291 | if (delegation) | 
|  | 1292 | delegation_flags = delegation->flags; | 
|  | 1293 | rcu_read_unlock(); | 
|  | 1294 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { | 
|  | 1295 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " | 
|  | 1296 | "returning a delegation for " | 
|  | 1297 | "OPEN(CLAIM_DELEGATE_CUR)\n", | 
|  | 1298 | clp->cl_hostname); | 
|  | 1299 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) | 
|  | 1300 | nfs_inode_set_delegation(state->inode, | 
|  | 1301 | data->owner->so_cred, | 
|  | 1302 | &data->o_res); | 
|  | 1303 | else | 
|  | 1304 | nfs_inode_reclaim_delegation(state->inode, | 
|  | 1305 | data->owner->so_cred, | 
|  | 1306 | &data->o_res); | 
|  | 1307 | } | 
|  | 1308 |  | 
|  | 1309 | /* | 
|  | 1310 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes | 
|  | 1311 | * and update the nfs4_state. | 
|  | 1312 | */ | 
|  | 1313 | static struct nfs4_state * | 
|  | 1314 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) | 
|  | 1315 | { | 
|  | 1316 | struct inode *inode = data->state->inode; | 
|  | 1317 | struct nfs4_state *state = data->state; | 
|  | 1318 | int ret; | 
|  | 1319 |  | 
|  | 1320 | if (!data->rpc_done) { | 
|  | 1321 | ret = data->rpc_status; | 
|  | 1322 | goto err; | 
|  | 1323 | } | 
|  | 1324 |  | 
|  | 1325 | ret = -ESTALE; | 
|  | 1326 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || | 
|  | 1327 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || | 
|  | 1328 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) | 
|  | 1329 | goto err; | 
|  | 1330 |  | 
|  | 1331 | ret = -ENOMEM; | 
|  | 1332 | state = nfs4_get_open_state(inode, data->owner); | 
|  | 1333 | if (state == NULL) | 
|  | 1334 | goto err; | 
|  | 1335 |  | 
|  | 1336 | ret = nfs_refresh_inode(inode, &data->f_attr); | 
|  | 1337 | if (ret) | 
|  | 1338 | goto err; | 
|  | 1339 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1340 | nfs_setsecurity(inode, &data->f_attr, data->f_label); | 
|  | 1341 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1342 | if (data->o_res.delegation_type != 0) | 
|  | 1343 | nfs4_opendata_check_deleg(data, state); | 
|  | 1344 | update_open_stateid(state, &data->o_res.stateid, NULL, | 
|  | 1345 | data->o_arg.fmode); | 
|  | 1346 |  | 
|  | 1347 | return state; | 
|  | 1348 | err: | 
|  | 1349 | return ERR_PTR(ret); | 
|  | 1350 |  | 
|  | 1351 | } | 
|  | 1352 |  | 
|  | 1353 | static struct nfs4_state * | 
|  | 1354 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1355 | { | 
|  | 1356 | struct inode *inode; | 
|  | 1357 | struct nfs4_state *state = NULL; | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1358 | int ret; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1359 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1360 | if (!data->rpc_done) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1361 | state = nfs4_try_open_cached(data); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1362 | goto out; | 
|  | 1363 | } | 
|  | 1364 |  | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1365 | ret = -EAGAIN; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1366 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1367 | goto err; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1368 | 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] | 1369 | ret = PTR_ERR(inode); | 
| Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1370 | if (IS_ERR(inode)) | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1371 | goto err; | 
|  | 1372 | ret = -ENOMEM; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1373 | state = nfs4_get_open_state(inode, data->owner); | 
|  | 1374 | if (state == NULL) | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1375 | goto err_put_inode; | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1376 | if (data->o_res.delegation_type != 0) | 
|  | 1377 | nfs4_opendata_check_deleg(data, state); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1378 | update_open_stateid(state, &data->o_res.stateid, NULL, | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1379 | data->o_arg.fmode); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1380 | iput(inode); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1381 | out: | 
| Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1382 | nfs_release_seqid(data->o_arg.seqid); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1383 | return state; | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1384 | err_put_inode: | 
|  | 1385 | iput(inode); | 
|  | 1386 | err: | 
|  | 1387 | return ERR_PTR(ret); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1388 | } | 
|  | 1389 |  | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1390 | static struct nfs4_state * | 
|  | 1391 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) | 
|  | 1392 | { | 
|  | 1393 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) | 
|  | 1394 | return _nfs4_opendata_reclaim_to_nfs4_state(data); | 
|  | 1395 | return _nfs4_opendata_to_nfs4_state(data); | 
|  | 1396 | } | 
|  | 1397 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1398 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) | 
|  | 1399 | { | 
|  | 1400 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
|  | 1401 | struct nfs_open_context *ctx; | 
|  | 1402 |  | 
|  | 1403 | spin_lock(&state->inode->i_lock); | 
|  | 1404 | list_for_each_entry(ctx, &nfsi->open_files, list) { | 
|  | 1405 | if (ctx->state != state) | 
|  | 1406 | continue; | 
|  | 1407 | get_nfs_open_context(ctx); | 
|  | 1408 | spin_unlock(&state->inode->i_lock); | 
|  | 1409 | return ctx; | 
|  | 1410 | } | 
|  | 1411 | spin_unlock(&state->inode->i_lock); | 
|  | 1412 | return ERR_PTR(-ENOENT); | 
|  | 1413 | } | 
|  | 1414 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1415 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, | 
|  | 1416 | struct nfs4_state *state, enum open_claim_type4 claim) | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1417 | { | 
|  | 1418 | struct nfs4_opendata *opendata; | 
|  | 1419 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1420 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1421 | NULL, NULL, claim, GFP_NOFS); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1422 | if (opendata == NULL) | 
|  | 1423 | return ERR_PTR(-ENOMEM); | 
|  | 1424 | opendata->state = state; | 
|  | 1425 | atomic_inc(&state->count); | 
|  | 1426 | return opendata; | 
|  | 1427 | } | 
|  | 1428 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1429 | 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] | 1430 | { | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1431 | struct nfs4_state *newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1432 | int ret; | 
|  | 1433 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1434 | opendata->o_arg.open_flags = 0; | 
|  | 1435 | opendata->o_arg.fmode = fmode; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1436 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); | 
|  | 1437 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); | 
|  | 1438 | nfs4_init_opendata_res(opendata); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1439 | ret = _nfs4_recover_proc_open(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1440 | if (ret != 0) | 
|  | 1441 | return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1442 | newstate = nfs4_opendata_to_nfs4_state(opendata); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1443 | if (IS_ERR(newstate)) | 
|  | 1444 | return PTR_ERR(newstate); | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1445 | nfs4_close_state(newstate, fmode); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1446 | *res = newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1447 | return 0; | 
|  | 1448 | } | 
|  | 1449 |  | 
|  | 1450 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) | 
|  | 1451 | { | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1452 | struct nfs4_state *newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1453 | int ret; | 
|  | 1454 |  | 
|  | 1455 | /* memory barrier prior to reading state->n_* */ | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1456 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 
| Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1457 | clear_bit(NFS_OPEN_STATE, &state->flags); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1458 | smp_rmb(); | 
|  | 1459 | if (state->n_rdwr != 0) { | 
| Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1460 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1461 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1462 | if (ret != 0) | 
|  | 1463 | return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1464 | if (newstate != state) | 
|  | 1465 | return -ESTALE; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1466 | } | 
|  | 1467 | if (state->n_wronly != 0) { | 
| Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1468 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1469 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1470 | if (ret != 0) | 
|  | 1471 | return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1472 | if (newstate != state) | 
|  | 1473 | return -ESTALE; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1474 | } | 
|  | 1475 | if (state->n_rdonly != 0) { | 
| Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1476 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1477 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1478 | if (ret != 0) | 
|  | 1479 | return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1480 | if (newstate != state) | 
|  | 1481 | return -ESTALE; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1482 | } | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1483 | /* | 
|  | 1484 | * We may have performed cached opens for all three recoveries. | 
|  | 1485 | * Check if we need to update the current stateid. | 
|  | 1486 | */ | 
|  | 1487 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1488 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1489 | write_seqlock(&state->seqlock); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1490 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1491 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1492 | write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1493 | } | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1494 | return 0; | 
|  | 1495 | } | 
|  | 1496 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | /* | 
|  | 1498 | * OPEN_RECLAIM: | 
|  | 1499 | * 	reclaim state on the server after a reboot. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | */ | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1501 | 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] | 1502 | { | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1503 | struct nfs_delegation *delegation; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1504 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1505 | fmode_t delegation_type = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | int status; | 
|  | 1507 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1508 | opendata = nfs4_open_recoverdata_alloc(ctx, state, | 
|  | 1509 | NFS4_OPEN_CLAIM_PREVIOUS); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1510 | if (IS_ERR(opendata)) | 
|  | 1511 | return PTR_ERR(opendata); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1512 | rcu_read_lock(); | 
|  | 1513 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1514 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) | 
| Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1515 | delegation_type = delegation->type; | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1516 | rcu_read_unlock(); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1517 | opendata->o_arg.u.delegation_type = delegation_type; | 
|  | 1518 | status = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1519 | nfs4_opendata_put(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | return status; | 
|  | 1521 | } | 
|  | 1522 |  | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1523 | 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] | 1524 | { | 
|  | 1525 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 1526 | struct nfs4_exception exception = { }; | 
|  | 1527 | int err; | 
|  | 1528 | do { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1529 | err = _nfs4_do_open_reclaim(ctx, state); | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1530 | trace_nfs4_open_reclaim(ctx, 0, err); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1531 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) | 
|  | 1532 | continue; | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1533 | if (err != -NFS4ERR_DELAY) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1534 | break; | 
|  | 1535 | nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } while (exception.retry); | 
|  | 1537 | return err; | 
|  | 1538 | } | 
|  | 1539 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1540 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 1541 | { | 
|  | 1542 | struct nfs_open_context *ctx; | 
|  | 1543 | int ret; | 
|  | 1544 |  | 
|  | 1545 | ctx = nfs4_state_find_open_context(state); | 
|  | 1546 | if (IS_ERR(ctx)) | 
| Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1547 | return -EAGAIN; | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1548 | ret = nfs4_do_open_reclaim(ctx, state); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1549 | put_nfs_open_context(ctx); | 
|  | 1550 | return ret; | 
|  | 1551 | } | 
|  | 1552 |  | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1553 | 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] | 1554 | { | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1555 | switch (err) { | 
|  | 1556 | default: | 
|  | 1557 | printk(KERN_ERR "NFS: %s: unhandled error " | 
|  | 1558 | "%d.\n", __func__, err); | 
|  | 1559 | case 0: | 
|  | 1560 | case -ENOENT: | 
|  | 1561 | case -ESTALE: | 
|  | 1562 | break; | 
|  | 1563 | case -NFS4ERR_BADSESSION: | 
|  | 1564 | case -NFS4ERR_BADSLOT: | 
|  | 1565 | case -NFS4ERR_BAD_HIGH_SLOT: | 
|  | 1566 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 1567 | case -NFS4ERR_DEADSESSION: | 
|  | 1568 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 1569 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); | 
|  | 1570 | return -EAGAIN; | 
|  | 1571 | case -NFS4ERR_STALE_CLIENTID: | 
|  | 1572 | case -NFS4ERR_STALE_STATEID: | 
|  | 1573 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 1574 | case -NFS4ERR_EXPIRED: | 
|  | 1575 | /* Don't recall a delegation if it was lost */ | 
|  | 1576 | nfs4_schedule_lease_recovery(server->nfs_client); | 
|  | 1577 | return -EAGAIN; | 
|  | 1578 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 1579 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 1580 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1581 | case -NFS4ERR_OPENMODE: | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1582 | nfs_inode_find_state_and_recover(state->inode, | 
|  | 1583 | stateid); | 
|  | 1584 | nfs4_schedule_stateid_recovery(server, state); | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1585 | return 0; | 
|  | 1586 | case -NFS4ERR_DELAY: | 
|  | 1587 | case -NFS4ERR_GRACE: | 
|  | 1588 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 1589 | ssleep(1); | 
|  | 1590 | return -EAGAIN; | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1591 | case -ENOMEM: | 
|  | 1592 | case -NFS4ERR_DENIED: | 
|  | 1593 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ | 
|  | 1594 | return 0; | 
| Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1595 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | return err; | 
|  | 1597 | } | 
|  | 1598 |  | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1599 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) | 
|  | 1600 | { | 
|  | 1601 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 1602 | struct nfs4_opendata *opendata; | 
|  | 1603 | int err; | 
|  | 1604 |  | 
|  | 1605 | opendata = nfs4_open_recoverdata_alloc(ctx, state, | 
|  | 1606 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); | 
|  | 1607 | if (IS_ERR(opendata)) | 
|  | 1608 | return PTR_ERR(opendata); | 
|  | 1609 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); | 
|  | 1610 | err = nfs4_open_recover(opendata, state); | 
|  | 1611 | nfs4_opendata_put(opendata); | 
|  | 1612 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); | 
|  | 1613 | } | 
|  | 1614 |  | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1615 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) | 
|  | 1616 | { | 
|  | 1617 | struct nfs4_opendata *data = calldata; | 
|  | 1618 |  | 
|  | 1619 | nfs40_setup_sequence(data->o_arg.server, &data->o_arg.seq_args, | 
|  | 1620 | &data->o_res.seq_res, task); | 
|  | 1621 | } | 
|  | 1622 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1623 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) | 
|  | 1624 | { | 
|  | 1625 | struct nfs4_opendata *data = calldata; | 
|  | 1626 |  | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1627 | nfs40_sequence_done(task, &data->o_res.seq_res); | 
|  | 1628 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1629 | data->rpc_status = task->tk_status; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1630 | if (data->rpc_status == 0) { | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1631 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); | 
| Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1632 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1633 | renew_lease(data->o_res.server, data->timestamp); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1634 | data->rpc_done = 1; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1635 | } | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1636 | } | 
|  | 1637 |  | 
|  | 1638 | static void nfs4_open_confirm_release(void *calldata) | 
|  | 1639 | { | 
|  | 1640 | struct nfs4_opendata *data = calldata; | 
|  | 1641 | struct nfs4_state *state = NULL; | 
|  | 1642 |  | 
|  | 1643 | /* If this request hasn't been cancelled, do nothing */ | 
|  | 1644 | if (data->cancelled == 0) | 
|  | 1645 | goto out_free; | 
|  | 1646 | /* In case of error, no cleanup! */ | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1647 | if (!data->rpc_done) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1648 | goto out_free; | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1649 | state = nfs4_opendata_to_nfs4_state(data); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1650 | if (!IS_ERR(state)) | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1651 | nfs4_close_state(state, data->o_arg.fmode); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1652 | out_free: | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1653 | nfs4_opendata_put(data); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1654 | } | 
|  | 1655 |  | 
|  | 1656 | static const struct rpc_call_ops nfs4_open_confirm_ops = { | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1657 | .rpc_call_prepare = nfs4_open_confirm_prepare, | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1658 | .rpc_call_done = nfs4_open_confirm_done, | 
|  | 1659 | .rpc_release = nfs4_open_confirm_release, | 
|  | 1660 | }; | 
|  | 1661 |  | 
|  | 1662 | /* | 
|  | 1663 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata | 
|  | 1664 | */ | 
|  | 1665 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) | 
|  | 1666 | { | 
|  | 1667 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); | 
|  | 1668 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1669 | struct  rpc_message msg = { | 
|  | 1670 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], | 
|  | 1671 | .rpc_argp = &data->c_arg, | 
|  | 1672 | .rpc_resp = &data->c_res, | 
|  | 1673 | .rpc_cred = data->owner->so_cred, | 
|  | 1674 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1675 | struct rpc_task_setup task_setup_data = { | 
|  | 1676 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1677 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1678 | .callback_ops = &nfs4_open_confirm_ops, | 
|  | 1679 | .callback_data = data, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1680 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1681 | .flags = RPC_TASK_ASYNC, | 
|  | 1682 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | int status; | 
|  | 1684 |  | 
| Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1685 | nfs4_init_sequence(&data->o_arg.seq_args, &data->o_res.seq_res, 1); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1686 | kref_get(&data->kref); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1687 | data->rpc_done = 0; | 
|  | 1688 | data->rpc_status = 0; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1689 | data->timestamp = jiffies; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1690 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1691 | if (IS_ERR(task)) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1692 | return PTR_ERR(task); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1693 | status = nfs4_wait_for_completion_rpc_task(task); | 
|  | 1694 | if (status != 0) { | 
|  | 1695 | data->cancelled = 1; | 
|  | 1696 | smp_wmb(); | 
|  | 1697 | } else | 
|  | 1698 | status = data->rpc_status; | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1699 | rpc_put_task(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | return status; | 
|  | 1701 | } | 
|  | 1702 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | { | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1705 | struct nfs4_opendata *data = calldata; | 
|  | 1706 | struct nfs4_state_owner *sp = data->owner; | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1707 | struct nfs_client *clp = sp->so_server->nfs_client; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1708 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1709 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1710 | goto out_wait; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1711 | /* | 
|  | 1712 | * Check if we still need to send an OPEN call, or if we can use | 
|  | 1713 | * a delegation instead. | 
|  | 1714 | */ | 
|  | 1715 | if (data->state != NULL) { | 
|  | 1716 | struct nfs_delegation *delegation; | 
|  | 1717 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1718 | 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] | 1719 | goto out_no_action; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1720 | rcu_read_lock(); | 
|  | 1721 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1722 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && | 
| Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1723 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1724 | can_open_delegated(delegation, data->o_arg.fmode)) | 
|  | 1725 | goto unlock_no_action; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1726 | rcu_read_unlock(); | 
|  | 1727 | } | 
| Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1728 | /* Update client id. */ | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1729 | data->o_arg.clientid = clp->cl_clientid; | 
| Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1730 | switch (data->o_arg.claim) { | 
|  | 1731 | case NFS4_OPEN_CLAIM_PREVIOUS: | 
|  | 1732 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | 
|  | 1733 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: | 
| Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1734 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; | 
| Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1735 | case NFS4_OPEN_CLAIM_FH: | 
|  | 1736 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1737 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); | 
|  | 1738 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1739 | data->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1740 | if (nfs4_setup_sequence(data->o_arg.server, | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1741 | &data->o_arg.seq_args, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1742 | &data->o_res.seq_res, | 
|  | 1743 | task) != 0) | 
|  | 1744 | nfs_release_seqid(data->o_arg.seqid); | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1745 |  | 
|  | 1746 | /* Set the create mode (note dependency on the session type) */ | 
|  | 1747 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; | 
|  | 1748 | if (data->o_arg.open_flags & O_EXCL) { | 
|  | 1749 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; | 
|  | 1750 | if (nfs4_has_persistent_session(clp)) | 
|  | 1751 | data->o_arg.createmode = NFS4_CREATE_GUARDED; | 
|  | 1752 | else if (clp->cl_mvops->minor_version > 0) | 
|  | 1753 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; | 
|  | 1754 | } | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1755 | return; | 
| Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1756 | unlock_no_action: | 
|  | 1757 | rcu_read_unlock(); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1758 | out_no_action: | 
|  | 1759 | task->tk_action = NULL; | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1760 | out_wait: | 
| Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1761 | nfs4_sequence_done(task, &data->o_res.seq_res); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1762 | } | 
|  | 1763 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1764 | static void nfs4_open_done(struct rpc_task *task, void *calldata) | 
|  | 1765 | { | 
|  | 1766 | struct nfs4_opendata *data = calldata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1768 | data->rpc_status = task->tk_status; | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1769 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1770 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) | 
|  | 1771 | return; | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1772 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1773 | if (task->tk_status == 0) { | 
| Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1774 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { | 
|  | 1775 | switch (data->o_res.f_attr->mode & S_IFMT) { | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1776 | case S_IFREG: | 
|  | 1777 | break; | 
|  | 1778 | case S_IFLNK: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1779 | data->rpc_status = -ELOOP; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1780 | break; | 
|  | 1781 | case S_IFDIR: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1782 | data->rpc_status = -EISDIR; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1783 | break; | 
|  | 1784 | default: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1785 | data->rpc_status = -ENOTDIR; | 
| Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1786 | } | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1787 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1788 | renew_lease(data->o_res.server, data->timestamp); | 
| Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1789 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) | 
|  | 1790 | nfs_confirm_seqid(&data->owner->so_seqid, 0); | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1791 | } | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1792 | data->rpc_done = 1; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1793 | } | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1794 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1795 | static void nfs4_open_release(void *calldata) | 
|  | 1796 | { | 
|  | 1797 | struct nfs4_opendata *data = calldata; | 
|  | 1798 | struct nfs4_state *state = NULL; | 
|  | 1799 |  | 
|  | 1800 | /* If this request hasn't been cancelled, do nothing */ | 
|  | 1801 | if (data->cancelled == 0) | 
|  | 1802 | goto out_free; | 
|  | 1803 | /* In case of error, no cleanup! */ | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1804 | if (data->rpc_status != 0 || !data->rpc_done) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1805 | goto out_free; | 
|  | 1806 | /* In case we need an open_confirm, no cleanup! */ | 
|  | 1807 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) | 
|  | 1808 | goto out_free; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1809 | state = nfs4_opendata_to_nfs4_state(data); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1810 | if (!IS_ERR(state)) | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1811 | nfs4_close_state(state, data->o_arg.fmode); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1812 | out_free: | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1813 | nfs4_opendata_put(data); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1814 | } | 
|  | 1815 |  | 
|  | 1816 | static const struct rpc_call_ops nfs4_open_ops = { | 
|  | 1817 | .rpc_call_prepare = nfs4_open_prepare, | 
|  | 1818 | .rpc_call_done = nfs4_open_done, | 
|  | 1819 | .rpc_release = nfs4_open_release, | 
|  | 1820 | }; | 
|  | 1821 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1822 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1823 | { | 
|  | 1824 | struct inode *dir = data->dir->d_inode; | 
|  | 1825 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 1826 | struct nfs_openargs *o_arg = &data->o_arg; | 
|  | 1827 | struct nfs_openres *o_res = &data->o_res; | 
|  | 1828 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1829 | struct rpc_message msg = { | 
|  | 1830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], | 
|  | 1831 | .rpc_argp = o_arg, | 
|  | 1832 | .rpc_resp = o_res, | 
|  | 1833 | .rpc_cred = data->owner->so_cred, | 
|  | 1834 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1835 | struct rpc_task_setup task_setup_data = { | 
|  | 1836 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1837 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1838 | .callback_ops = &nfs4_open_ops, | 
|  | 1839 | .callback_data = data, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1840 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1841 | .flags = RPC_TASK_ASYNC, | 
|  | 1842 | }; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1843 | int status; | 
|  | 1844 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1845 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1846 | kref_get(&data->kref); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1847 | data->rpc_done = 0; | 
|  | 1848 | data->rpc_status = 0; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1849 | data->cancelled = 0; | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1850 | data->is_recover = 0; | 
|  | 1851 | if (isrecover) { | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1852 | nfs4_set_sequence_privileged(&o_arg->seq_args); | 
| Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1853 | data->is_recover = 1; | 
|  | 1854 | } | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1855 | task = rpc_run_task(&task_setup_data); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1856 | if (IS_ERR(task)) | 
|  | 1857 | return PTR_ERR(task); | 
|  | 1858 | status = nfs4_wait_for_completion_rpc_task(task); | 
|  | 1859 | if (status != 0) { | 
|  | 1860 | data->cancelled = 1; | 
|  | 1861 | smp_wmb(); | 
|  | 1862 | } else | 
|  | 1863 | status = data->rpc_status; | 
|  | 1864 | rpc_put_task(task); | 
|  | 1865 |  | 
|  | 1866 | return status; | 
|  | 1867 | } | 
|  | 1868 |  | 
|  | 1869 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) | 
|  | 1870 | { | 
|  | 1871 | struct inode *dir = data->dir->d_inode; | 
|  | 1872 | struct nfs_openres *o_res = &data->o_res; | 
|  | 1873 | int status; | 
|  | 1874 |  | 
|  | 1875 | status = nfs4_run_open_task(data, 1); | 
|  | 1876 | if (status != 0 || !data->rpc_done) | 
|  | 1877 | return status; | 
|  | 1878 |  | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1879 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); | 
|  | 1880 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1881 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 
|  | 1882 | status = _nfs4_proc_open_confirm(data); | 
|  | 1883 | if (status != 0) | 
|  | 1884 | return status; | 
|  | 1885 | } | 
|  | 1886 |  | 
|  | 1887 | return status; | 
|  | 1888 | } | 
|  | 1889 |  | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1890 | static int nfs4_opendata_access(struct rpc_cred *cred, | 
|  | 1891 | struct nfs4_opendata *opendata, | 
| Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1892 | struct nfs4_state *state, fmode_t fmode, | 
|  | 1893 | int openflags) | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1894 | { | 
|  | 1895 | struct nfs_access_entry cache; | 
|  | 1896 | u32 mask; | 
|  | 1897 |  | 
|  | 1898 | /* access call failed or for some reason the server doesn't | 
|  | 1899 | * support any access modes -- defer access call until later */ | 
|  | 1900 | if (opendata->o_res.access_supported == 0) | 
|  | 1901 | return 0; | 
|  | 1902 |  | 
|  | 1903 | mask = 0; | 
| Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1904 | /* don't check MAY_WRITE - a newly created file may not have | 
| Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1905 | * write mode bits, but POSIX allows the creating process to write. | 
|  | 1906 | * use openflags to check for exec, because fmode won't | 
|  | 1907 | * always have FMODE_EXEC set when file open for exec. */ | 
|  | 1908 | if (openflags & __FMODE_EXEC) { | 
|  | 1909 | /* ONLY check for exec rights */ | 
|  | 1910 | mask = MAY_EXEC; | 
|  | 1911 | } else if (fmode & FMODE_READ) | 
|  | 1912 | mask = MAY_READ; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1913 |  | 
|  | 1914 | cache.cred = cred; | 
|  | 1915 | cache.jiffies = jiffies; | 
|  | 1916 | nfs_access_set_mask(&cache, opendata->o_res.access_result); | 
|  | 1917 | nfs_access_add_cache(state->inode, &cache); | 
|  | 1918 |  | 
| Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1919 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1920 | return 0; | 
|  | 1921 |  | 
|  | 1922 | /* even though OPEN succeeded, access is denied. Close the file */ | 
|  | 1923 | nfs4_close_state(state, fmode); | 
| Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1924 | return -EACCES; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1925 | } | 
|  | 1926 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1927 | /* | 
|  | 1928 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata | 
|  | 1929 | */ | 
|  | 1930 | static int _nfs4_proc_open(struct nfs4_opendata *data) | 
|  | 1931 | { | 
|  | 1932 | struct inode *dir = data->dir->d_inode; | 
|  | 1933 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 1934 | struct nfs_openargs *o_arg = &data->o_arg; | 
|  | 1935 | struct nfs_openres *o_res = &data->o_res; | 
|  | 1936 | int status; | 
|  | 1937 |  | 
|  | 1938 | status = nfs4_run_open_task(data, 0); | 
| Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1939 | if (!data->rpc_done) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1940 | return status; | 
| Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1941 | if (status != 0) { | 
|  | 1942 | if (status == -NFS4ERR_BADNAME && | 
|  | 1943 | !(o_arg->open_flags & O_CREAT)) | 
|  | 1944 | return -ENOENT; | 
|  | 1945 | return status; | 
|  | 1946 | } | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1947 |  | 
| Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1948 | nfs_fattr_map_and_free_names(server, &data->f_attr); | 
|  | 1949 |  | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1950 | if (o_arg->open_flags & O_CREAT) { | 
| Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1951 | update_changeattr(dir, &o_res->cinfo); | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1952 | if (o_arg->open_flags & O_EXCL) | 
|  | 1953 | data->file_created = 1; | 
|  | 1954 | else if (o_res->cinfo.before != o_res->cinfo.after) | 
|  | 1955 | data->file_created = 1; | 
|  | 1956 | } | 
| Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1957 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) | 
|  | 1958 | server->caps &= ~NFS_CAP_POSIX_LOCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1960 | status = _nfs4_proc_open_confirm(data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | if (status != 0) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1962 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } | 
|  | 1964 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1965 | _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] | 1966 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | } | 
|  | 1968 |  | 
| Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1969 | static int nfs4_recover_expired_lease(struct nfs_server *server) | 
|  | 1970 | { | 
|  | 1971 | return nfs4_client_recover_expired_lease(server->nfs_client); | 
|  | 1972 | } | 
|  | 1973 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | /* | 
|  | 1975 | * OPEN_EXPIRED: | 
|  | 1976 | * 	reclaim state on the server after a network partition. | 
|  | 1977 | * 	Assumes caller holds the appropriate lock | 
|  | 1978 | */ | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1979 | 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] | 1980 | { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1981 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1982 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 |  | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1984 | opendata = nfs4_open_recoverdata_alloc(ctx, state, | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1985 | NFS4_OPEN_CLAIM_FH); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1986 | if (IS_ERR(opendata)) | 
|  | 1987 | return PTR_ERR(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1988 | ret = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1989 | if (ret == -ESTALE) | 
| Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1990 | d_drop(ctx->dentry); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1991 | nfs4_opendata_put(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1992 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } | 
|  | 1994 |  | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1995 | 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] | 1996 | { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1997 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1998 | struct nfs4_exception exception = { }; | 
|  | 1999 | int err; | 
|  | 2000 |  | 
|  | 2001 | do { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2002 | err = _nfs4_open_expired(ctx, state); | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2003 | trace_nfs4_open_expired(ctx, 0, err); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2004 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) | 
|  | 2005 | continue; | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2006 | switch (err) { | 
|  | 2007 | default: | 
|  | 2008 | goto out; | 
|  | 2009 | case -NFS4ERR_GRACE: | 
|  | 2010 | case -NFS4ERR_DELAY: | 
|  | 2011 | nfs4_handle_exception(server, err, &exception); | 
|  | 2012 | err = 0; | 
|  | 2013 | } | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2014 | } while (exception.retry); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2015 | out: | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2016 | return err; | 
|  | 2017 | } | 
|  | 2018 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 2020 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | struct nfs_open_context *ctx; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2022 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2024 | ctx = nfs4_state_find_open_context(state); | 
|  | 2025 | if (IS_ERR(ctx)) | 
| Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2026 | return -EAGAIN; | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2027 | ret = nfs4_do_open_expired(ctx, state); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2028 | put_nfs_open_context(ctx); | 
|  | 2029 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } | 
|  | 2031 |  | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2032 | #if defined(CONFIG_NFS_V4_1) | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2033 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2034 | { | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2035 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2036 | nfs4_stateid *stateid = &state->stateid; | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2037 | struct nfs_delegation *delegation; | 
|  | 2038 | struct rpc_cred *cred = NULL; | 
|  | 2039 | int status = -NFS4ERR_BAD_STATEID; | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2040 |  | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2041 | /* If a state reset has been done, test_stateid is unneeded */ | 
|  | 2042 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
|  | 2043 | return; | 
|  | 2044 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2045 | /* Get the delegation credential for use by test/free_stateid */ | 
|  | 2046 | rcu_read_lock(); | 
|  | 2047 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
|  | 2048 | if (delegation != NULL && | 
|  | 2049 | nfs4_stateid_match(&delegation->stateid, stateid)) { | 
|  | 2050 | cred = get_rpccred(delegation->cred); | 
|  | 2051 | rcu_read_unlock(); | 
|  | 2052 | status = nfs41_test_stateid(server, stateid, cred); | 
| Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2053 | trace_nfs4_test_delegation_stateid(state, NULL, status); | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2054 | } else | 
|  | 2055 | rcu_read_unlock(); | 
|  | 2056 |  | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2057 | if (status != NFS_OK) { | 
|  | 2058 | /* Free the stateid unless the server explicitly | 
|  | 2059 | * informs us the stateid is unrecognized. */ | 
|  | 2060 | if (status != -NFS4ERR_BAD_STATEID) | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2061 | nfs41_free_stateid(server, stateid, cred); | 
| Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2062 | nfs_remove_bad_delegation(state->inode); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2063 |  | 
| Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 2064 | write_seqlock(&state->seqlock); | 
|  | 2065 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); | 
|  | 2066 | write_sequnlock(&state->seqlock); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2067 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 
|  | 2068 | } | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2069 |  | 
|  | 2070 | if (cred != NULL) | 
|  | 2071 | put_rpccred(cred); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2072 | } | 
|  | 2073 |  | 
|  | 2074 | /** | 
|  | 2075 | * nfs41_check_open_stateid - possibly free an open stateid | 
|  | 2076 | * | 
|  | 2077 | * @state: NFSv4 state for an inode | 
|  | 2078 | * | 
|  | 2079 | * Returns NFS_OK if recovery for this stateid is now finished. | 
|  | 2080 | * Otherwise a negative NFS4ERR value is returned. | 
|  | 2081 | */ | 
|  | 2082 | static int nfs41_check_open_stateid(struct nfs4_state *state) | 
|  | 2083 | { | 
|  | 2084 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2085 | nfs4_stateid *stateid = &state->open_stateid; | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2086 | struct rpc_cred *cred = state->owner->so_cred; | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2087 | int status; | 
|  | 2088 |  | 
|  | 2089 | /* If a state reset has been done, test_stateid is unneeded */ | 
|  | 2090 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && | 
|  | 2091 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && | 
|  | 2092 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) | 
|  | 2093 | return -NFS4ERR_BAD_STATEID; | 
|  | 2094 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2095 | status = nfs41_test_stateid(server, stateid, cred); | 
| Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2096 | trace_nfs4_test_open_stateid(state, NULL, status); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2097 | if (status != NFS_OK) { | 
|  | 2098 | /* Free the stateid unless the server explicitly | 
|  | 2099 | * informs us the stateid is unrecognized. */ | 
|  | 2100 | if (status != -NFS4ERR_BAD_STATEID) | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2101 | nfs41_free_stateid(server, stateid, cred); | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2102 |  | 
|  | 2103 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 2104 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 2105 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2106 | clear_bit(NFS_OPEN_STATE, &state->flags); | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2107 | } | 
|  | 2108 | return status; | 
|  | 2109 | } | 
|  | 2110 |  | 
|  | 2111 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
|  | 2112 | { | 
| Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2113 | int status; | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2114 |  | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2115 | nfs41_clear_delegation_stateid(state); | 
|  | 2116 | status = nfs41_check_open_stateid(state); | 
| Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2117 | if (status != NFS_OK) | 
|  | 2118 | status = nfs4_open_expired(sp, state); | 
|  | 2119 | return status; | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2120 | } | 
|  | 2121 | #endif | 
|  | 2122 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | /* | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2124 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* | 
|  | 2125 | * fields corresponding to attributes that were used to store the verifier. | 
|  | 2126 | * Make sure we clobber those fields in the later setattr call | 
|  | 2127 | */ | 
|  | 2128 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) | 
|  | 2129 | { | 
|  | 2130 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && | 
|  | 2131 | !(sattr->ia_valid & ATTR_ATIME_SET)) | 
|  | 2132 | sattr->ia_valid |= ATTR_ATIME; | 
|  | 2133 |  | 
|  | 2134 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && | 
|  | 2135 | !(sattr->ia_valid & ATTR_MTIME_SET)) | 
|  | 2136 | sattr->ia_valid |= ATTR_MTIME; | 
|  | 2137 | } | 
|  | 2138 |  | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2139 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, | 
|  | 2140 | fmode_t fmode, | 
|  | 2141 | int flags, | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2142 | struct nfs_open_context *ctx) | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2143 | { | 
|  | 2144 | struct nfs4_state_owner *sp = opendata->owner; | 
|  | 2145 | struct nfs_server *server = sp->so_server; | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2146 | struct dentry *dentry; | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2147 | struct nfs4_state *state; | 
|  | 2148 | unsigned int seq; | 
|  | 2149 | int ret; | 
|  | 2150 |  | 
|  | 2151 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); | 
|  | 2152 |  | 
|  | 2153 | ret = _nfs4_proc_open(opendata); | 
|  | 2154 | if (ret != 0) | 
|  | 2155 | goto out; | 
|  | 2156 |  | 
|  | 2157 | state = nfs4_opendata_to_nfs4_state(opendata); | 
|  | 2158 | ret = PTR_ERR(state); | 
|  | 2159 | if (IS_ERR(state)) | 
|  | 2160 | goto out; | 
|  | 2161 | if (server->caps & NFS_CAP_POSIX_LOCK) | 
|  | 2162 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); | 
|  | 2163 |  | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2164 | dentry = opendata->dentry; | 
|  | 2165 | if (dentry->d_inode == NULL) { | 
|  | 2166 | /* FIXME: Is this d_drop() ever needed? */ | 
|  | 2167 | d_drop(dentry); | 
|  | 2168 | dentry = d_add_unique(dentry, igrab(state->inode)); | 
|  | 2169 | if (dentry == NULL) { | 
|  | 2170 | dentry = opendata->dentry; | 
|  | 2171 | } else if (dentry != ctx->dentry) { | 
|  | 2172 | dput(ctx->dentry); | 
|  | 2173 | ctx->dentry = dget(dentry); | 
|  | 2174 | } | 
|  | 2175 | nfs_set_verifier(dentry, | 
|  | 2176 | nfs_save_change_attribute(opendata->dir->d_inode)); | 
|  | 2177 | } | 
|  | 2178 |  | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2179 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); | 
|  | 2180 | if (ret != 0) | 
|  | 2181 | goto out; | 
|  | 2182 |  | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2183 | ctx->state = state; | 
| Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2184 | if (dentry->d_inode == state->inode) { | 
|  | 2185 | nfs_inode_attach_open_context(ctx); | 
|  | 2186 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) | 
|  | 2187 | nfs4_schedule_stateid_recovery(server, state); | 
|  | 2188 | } | 
| Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2189 | out: | 
|  | 2190 | return ret; | 
|  | 2191 | } | 
|  | 2192 |  | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2193 | /* | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2194 | * Returns a referenced nfs4_state | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | */ | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2196 | static int _nfs4_do_open(struct inode *dir, | 
| Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2197 | struct nfs_open_context *ctx, | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2198 | int flags, | 
|  | 2199 | struct iattr *sattr, | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2200 | struct nfs4_label *label, | 
|  | 2201 | int *opened) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | { | 
|  | 2203 | struct nfs4_state_owner  *sp; | 
|  | 2204 | struct nfs4_state     *state = NULL; | 
|  | 2205 | struct nfs_server       *server = NFS_SERVER(dir); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2206 | struct nfs4_opendata *opendata; | 
| Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2207 | struct dentry *dentry = ctx->dentry; | 
|  | 2208 | struct rpc_cred *cred = ctx->cred; | 
|  | 2209 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; | 
|  | 2210 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2211 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2212 | struct nfs4_label *olabel = NULL; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2213 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 |  | 
|  | 2215 | /* Protect against reboot recovery conflicts */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | status = -ENOMEM; | 
| Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2217 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); | 
|  | 2218 | if (sp == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); | 
|  | 2220 | goto out_err; | 
|  | 2221 | } | 
| Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2222 | status = nfs4_recover_expired_lease(server); | 
|  | 2223 | if (status != 0) | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2224 | goto err_put_state_owner; | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2225 | if (dentry->d_inode != NULL) | 
|  | 2226 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); | 
| Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2227 | status = -ENOMEM; | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2228 | if (dentry->d_inode) | 
|  | 2229 | claim = NFS4_OPEN_CLAIM_FH; | 
| Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2230 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2231 | label, claim, GFP_KERNEL); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2232 | if (opendata == NULL) | 
| Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2233 | goto err_put_state_owner; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2235 | if (label) { | 
|  | 2236 | olabel = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 2237 | if (IS_ERR(olabel)) { | 
|  | 2238 | status = PTR_ERR(olabel); | 
|  | 2239 | goto err_opendata_put; | 
|  | 2240 | } | 
|  | 2241 | } | 
|  | 2242 |  | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2243 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { | 
|  | 2244 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); | 
|  | 2245 | if (!opendata->f_attr.mdsthreshold) | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2246 | goto err_free_label; | 
| Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2247 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2248 | } | 
| Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2249 | if (dentry->d_inode != NULL) | 
|  | 2250 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2251 |  | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2252 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2253 | if (status != 0) | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2254 | goto err_free_label; | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2255 | state = ctx->state; | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2256 |  | 
| Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2257 | if ((opendata->o_arg.open_flags & O_EXCL) && | 
|  | 2258 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2259 | nfs4_exclusive_attrset(opendata, sattr); | 
|  | 2260 |  | 
|  | 2261 | nfs_fattr_init(opendata->o_res.f_attr); | 
|  | 2262 | status = nfs4_do_setattr(state->inode, cred, | 
|  | 2263 | opendata->o_res.f_attr, sattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2264 | state, label, olabel); | 
|  | 2265 | if (status == 0) { | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2266 | nfs_setattr_update_inode(state->inode, sattr); | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2267 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2268 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2269 | } | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2270 | } | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2271 | if (opendata->file_created) | 
|  | 2272 | *opened |= FILE_CREATED; | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2273 |  | 
|  | 2274 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) | 
|  | 2275 | *ctx_th = opendata->f_attr.mdsthreshold; | 
|  | 2276 | else | 
|  | 2277 | kfree(opendata->f_attr.mdsthreshold); | 
|  | 2278 | opendata->f_attr.mdsthreshold = NULL; | 
|  | 2279 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2280 | nfs4_label_free(olabel); | 
|  | 2281 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2282 | nfs4_opendata_put(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | nfs4_put_state_owner(sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | return 0; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2285 | err_free_label: | 
|  | 2286 | nfs4_label_free(olabel); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2287 | err_opendata_put: | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2288 | kfree(opendata->f_attr.mdsthreshold); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2289 | nfs4_opendata_put(opendata); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2290 | err_put_state_owner: | 
|  | 2291 | nfs4_put_state_owner(sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | out_err: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | return status; | 
|  | 2294 | } | 
|  | 2295 |  | 
|  | 2296 |  | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2297 | static struct nfs4_state *nfs4_do_open(struct inode *dir, | 
| Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2298 | struct nfs_open_context *ctx, | 
| Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2299 | int flags, | 
|  | 2300 | struct iattr *sattr, | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2301 | struct nfs4_label *label, | 
|  | 2302 | int *opened) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | { | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2304 | struct nfs_server *server = NFS_SERVER(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | struct nfs4_exception exception = { }; | 
|  | 2306 | struct nfs4_state *res; | 
|  | 2307 | int status; | 
|  | 2308 |  | 
|  | 2309 | do { | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2310 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); | 
| Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2311 | res = ctx->state; | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2312 | trace_nfs4_open_file(ctx, flags, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | if (status == 0) | 
|  | 2314 | break; | 
|  | 2315 | /* NOTE: BAD_SEQID means the server and client disagree about the | 
|  | 2316 | * book-keeping w.r.t. state-changing operations | 
|  | 2317 | * (OPEN/CLOSE/LOCK/LOCKU...) | 
|  | 2318 | * It is actually a sign of a bug on the client or on the server. | 
|  | 2319 | * | 
|  | 2320 | * If we receive a BAD_SEQID error in the particular case of | 
| Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2321 | * doing an OPEN, we assume that nfs_increment_open_seqid() will | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | * have unhashed the old state_owner for us, and that we can | 
|  | 2323 | * therefore safely retry using a new one. We should still warn | 
|  | 2324 | * the user though... | 
|  | 2325 | */ | 
|  | 2326 | if (status == -NFS4ERR_BAD_SEQID) { | 
| Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2327 | pr_warn_ratelimited("NFS: v4 server %s " | 
| Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2328 | " returned a bad sequence-id error!\n", | 
|  | 2329 | NFS_SERVER(dir)->nfs_client->cl_hostname); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | exception.retry = 1; | 
|  | 2331 | continue; | 
|  | 2332 | } | 
| Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2333 | /* | 
|  | 2334 | * BAD_STATEID on OPEN means that the server cancelled our | 
|  | 2335 | * state before it received the OPEN_CONFIRM. | 
|  | 2336 | * Recover by retrying the request as per the discussion | 
|  | 2337 | * on Page 181 of RFC3530. | 
|  | 2338 | */ | 
|  | 2339 | if (status == -NFS4ERR_BAD_STATEID) { | 
|  | 2340 | exception.retry = 1; | 
|  | 2341 | continue; | 
|  | 2342 | } | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2343 | if (status == -EAGAIN) { | 
|  | 2344 | /* We must have found a delegation */ | 
|  | 2345 | exception.retry = 1; | 
|  | 2346 | continue; | 
|  | 2347 | } | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2348 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) | 
|  | 2349 | continue; | 
|  | 2350 | res = ERR_PTR(nfs4_handle_exception(server, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | status, &exception)); | 
|  | 2352 | } while (exception.retry); | 
|  | 2353 | return res; | 
|  | 2354 | } | 
|  | 2355 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2356 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
|  | 2357 | struct nfs_fattr *fattr, struct iattr *sattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2358 | struct nfs4_state *state, struct nfs4_label *ilabel, | 
|  | 2359 | struct nfs4_label *olabel) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2361 | struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | struct nfs_setattrargs  arg = { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2363 | .fh             = NFS_FH(inode), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | .iap            = sattr, | 
|  | 2365 | .server		= server, | 
|  | 2366 | .bitmask = server->attr_bitmask, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2367 | .label		= ilabel, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | }; | 
|  | 2369 | struct nfs_setattrres  res = { | 
|  | 2370 | .fattr		= fattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2371 | .label		= olabel, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | .server		= server, | 
|  | 2373 | }; | 
|  | 2374 | struct rpc_message msg = { | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2375 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETATTR], | 
|  | 2376 | .rpc_argp	= &arg, | 
|  | 2377 | .rpc_resp	= &res, | 
|  | 2378 | .rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | }; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2380 | unsigned long timestamp = jiffies; | 
| Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2381 | fmode_t fmode; | 
|  | 2382 | bool truncate; | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2383 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2385 | arg.bitmask = nfs4_bitmask(server, ilabel); | 
|  | 2386 | if (ilabel) | 
|  | 2387 | arg.bitmask = nfs4_bitmask(server, olabel); | 
|  | 2388 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2389 | nfs_fattr_init(fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 |  | 
| Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2391 | /* Servers should only apply open mode checks for file size changes */ | 
|  | 2392 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; | 
|  | 2393 | fmode = truncate ? FMODE_WRITE : FMODE_READ; | 
|  | 2394 |  | 
|  | 2395 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { | 
|  | 2396 | /* Use that stateid */ | 
|  | 2397 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { | 
| Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2398 | struct nfs_lockowner lockowner = { | 
|  | 2399 | .l_owner = current->files, | 
|  | 2400 | .l_pid = current->tgid, | 
|  | 2401 | }; | 
| Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2402 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, | 
| Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2403 | &lockowner); | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2404 | } else | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2405 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2407 | 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] | 2408 | if (status == 0 && state != NULL) | 
|  | 2409 | renew_lease(server, timestamp); | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2410 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | } | 
|  | 2412 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2413 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
|  | 2414 | struct nfs_fattr *fattr, struct iattr *sattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2415 | struct nfs4_state *state, struct nfs4_label *ilabel, | 
|  | 2416 | struct nfs4_label *olabel) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2418 | struct nfs_server *server = NFS_SERVER(inode); | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2419 | struct nfs4_exception exception = { | 
|  | 2420 | .state = state, | 
| Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2421 | .inode = inode, | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2422 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | int err; | 
|  | 2424 | do { | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2425 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel); | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 2426 | trace_nfs4_setattr(inode, err); | 
| Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2427 | switch (err) { | 
|  | 2428 | case -NFS4ERR_OPENMODE: | 
| Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2429 | if (!(sattr->ia_valid & ATTR_SIZE)) { | 
|  | 2430 | pr_warn_once("NFSv4: server %s is incorrectly " | 
|  | 2431 | "applying open mode checks to " | 
|  | 2432 | "a SETATTR that is not " | 
|  | 2433 | "changing file size.\n", | 
|  | 2434 | server->nfs_client->cl_hostname); | 
|  | 2435 | } | 
| Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2436 | if (state && !(state->state & FMODE_WRITE)) { | 
|  | 2437 | err = -EBADF; | 
|  | 2438 | if (sattr->ia_valid & ATTR_OPEN) | 
|  | 2439 | err = -EACCES; | 
|  | 2440 | goto out; | 
|  | 2441 | } | 
|  | 2442 | } | 
|  | 2443 | err = nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | } while (exception.retry); | 
| Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2445 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | return err; | 
|  | 2447 | } | 
|  | 2448 |  | 
|  | 2449 | struct nfs4_closedata { | 
|  | 2450 | struct inode *inode; | 
|  | 2451 | struct nfs4_state *state; | 
|  | 2452 | struct nfs_closeargs arg; | 
|  | 2453 | struct nfs_closeres res; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2454 | struct nfs_fattr fattr; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2455 | unsigned long timestamp; | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2456 | bool roc; | 
|  | 2457 | u32 roc_barrier; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | }; | 
|  | 2459 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2460 | static void nfs4_free_closedata(void *data) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2461 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2462 | struct nfs4_closedata *calldata = data; | 
|  | 2463 | struct nfs4_state_owner *sp = calldata->state->owner; | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2464 | struct super_block *sb = calldata->state->inode->i_sb; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2465 |  | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2466 | if (calldata->roc) | 
|  | 2467 | pnfs_roc_release(calldata->state->inode); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2468 | nfs4_put_open_state(calldata->state); | 
|  | 2469 | nfs_free_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2470 | nfs4_put_state_owner(sp); | 
| Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2471 | nfs_sb_deactive(sb); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2472 | kfree(calldata); | 
|  | 2473 | } | 
|  | 2474 |  | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2475 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, | 
|  | 2476 | fmode_t fmode) | 
|  | 2477 | { | 
|  | 2478 | spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2479 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2480 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { | 
|  | 2481 | case FMODE_WRITE: | 
|  | 2482 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 2483 | break; | 
|  | 2484 | case FMODE_READ: | 
|  | 2485 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 2486 | break; | 
|  | 2487 | case 0: | 
|  | 2488 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 2489 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 2490 | clear_bit(NFS_OPEN_STATE, &state->flags); | 
|  | 2491 | } | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2492 | spin_unlock(&state->owner->so_lock); | 
|  | 2493 | } | 
|  | 2494 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2495 | static void nfs4_close_done(struct rpc_task *task, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2497 | struct nfs4_closedata *calldata = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | struct nfs4_state *state = calldata->state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | struct nfs_server *server = NFS_SERVER(calldata->inode); | 
|  | 2500 |  | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2501 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2502 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) | 
|  | 2503 | return; | 
| Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2504 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | /* hmm. we are done with the inode, and in the process of freeing | 
|  | 2506 | * the state_owner. we keep this around to process errors | 
|  | 2507 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | switch (task->tk_status) { | 
|  | 2509 | case 0: | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2510 | if (calldata->roc) | 
|  | 2511 | pnfs_roc_set_barrier(state->inode, | 
|  | 2512 | calldata->roc_barrier); | 
| Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2513 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2514 | renew_lease(server, calldata->timestamp); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2515 | nfs4_close_clear_stateid_flags(state, | 
|  | 2516 | calldata->arg.fmode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | break; | 
|  | 2518 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2519 | case -NFS4ERR_OLD_STATEID: | 
|  | 2520 | case -NFS4ERR_BAD_STATEID: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2522 | if (calldata->arg.fmode == 0) | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2523 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | default: | 
| Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2525 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) | 
|  | 2526 | rpc_restart_call_prepare(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | } | 
| Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2528 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2529 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2530 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } | 
|  | 2532 |  | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2533 | static void nfs4_close_prepare(struct rpc_task *task, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2535 | struct nfs4_closedata *calldata = data; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2536 | struct nfs4_state *state = calldata->state; | 
| Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2537 | struct inode *inode = calldata->inode; | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2538 | int call_close = 0; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2539 |  | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2540 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2541 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2542 | goto out_wait; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2543 |  | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2544 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; | 
|  | 2545 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; | 
| Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2546 | spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2547 | /* Calculate the change in open mode */ | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2548 | if (state->n_rdwr == 0) { | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2549 | if (state->n_rdonly == 0) { | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2550 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); | 
|  | 2551 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); | 
|  | 2552 | calldata->arg.fmode &= ~FMODE_READ; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2553 | } | 
|  | 2554 | if (state->n_wronly == 0) { | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2555 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); | 
|  | 2556 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); | 
|  | 2557 | calldata->arg.fmode &= ~FMODE_WRITE; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2558 | } | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2559 | } | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2560 | if (!nfs4_valid_open_stateid(state)) | 
|  | 2561 | call_close = 0; | 
| Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2562 | spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2563 |  | 
|  | 2564 | if (!call_close) { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2565 | /* Note: exit _without_ calling nfs4_close_done */ | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2566 | goto out_no_action; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2567 | } | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2568 |  | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2569 | if (calldata->arg.fmode == 0) { | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2570 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2571 | if (calldata->roc && | 
| Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2572 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { | 
|  | 2573 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2574 | goto out_wait; | 
| Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2575 | } | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2576 | } | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2577 |  | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2578 | nfs_fattr_init(calldata->res.fattr); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2579 | calldata->timestamp = jiffies; | 
| Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2580 | if (nfs4_setup_sequence(NFS_SERVER(inode), | 
| Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2581 | &calldata->arg.seq_args, | 
|  | 2582 | &calldata->res.seq_res, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2583 | task) != 0) | 
|  | 2584 | nfs_release_seqid(calldata->arg.seqid); | 
| Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2585 | dprintk("%s: done!\n", __func__); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2586 | return; | 
|  | 2587 | out_no_action: | 
|  | 2588 | task->tk_action = NULL; | 
|  | 2589 | out_wait: | 
|  | 2590 | nfs4_sequence_done(task, &calldata->res.seq_res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } | 
|  | 2592 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2593 | static const struct rpc_call_ops nfs4_close_ops = { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2594 | .rpc_call_prepare = nfs4_close_prepare, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2595 | .rpc_call_done = nfs4_close_done, | 
|  | 2596 | .rpc_release = nfs4_free_closedata, | 
|  | 2597 | }; | 
|  | 2598 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | /* | 
|  | 2600 | * It is possible for data to be read/written from a mem-mapped file | 
|  | 2601 | * after the sys_close call (which hits the vfs layer as a flush). | 
|  | 2602 | * This means that we can't safely call nfsv4 close on a file until | 
|  | 2603 | * the inode is cleared. This in turn means that we are not good | 
|  | 2604 | * NFSv4 citizens - we do not indicate to the server to update the file's | 
|  | 2605 | * share state even when we are done with one of the three share | 
|  | 2606 | * stateid's in the inode. | 
|  | 2607 | * | 
|  | 2608 | * NOTE: Caller must be holding the sp->so_owner semaphore! | 
|  | 2609 | */ | 
| Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2610 | 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] | 2611 | { | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2612 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | struct nfs4_closedata *calldata; | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2614 | struct nfs4_state_owner *sp = state->owner; | 
|  | 2615 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2616 | struct rpc_message msg = { | 
|  | 2617 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], | 
|  | 2618 | .rpc_cred = state->owner->so_cred, | 
|  | 2619 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2620 | struct rpc_task_setup task_setup_data = { | 
|  | 2621 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2622 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2623 | .callback_ops = &nfs4_close_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2624 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2625 | .flags = RPC_TASK_ASYNC, | 
|  | 2626 | }; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2627 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 |  | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 2629 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, | 
|  | 2630 | &task_setup_data.rpc_client, &msg); | 
|  | 2631 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2632 | calldata = kzalloc(sizeof(*calldata), gfp_mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | if (calldata == NULL) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2634 | goto out; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2635 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2636 | calldata->inode = state->inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | calldata->state = state; | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2638 | calldata->arg.fh = NFS_FH(state->inode); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2639 | calldata->arg.stateid = &state->open_stateid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | /* Serialization for the sequence id */ | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2641 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2642 | if (calldata->arg.seqid == NULL) | 
|  | 2643 | goto out_free_calldata; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2644 | calldata->arg.fmode = 0; | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2645 | calldata->arg.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2646 | calldata->res.fattr = &calldata->fattr; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2647 | calldata->res.seqid = calldata->arg.seqid; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2648 | calldata->res.server = server; | 
| Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2649 | calldata->roc = pnfs_roc(state->inode); | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2650 | nfs_sb_active(calldata->inode->i_sb); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2651 |  | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2652 | msg.rpc_argp = &calldata->arg; | 
|  | 2653 | msg.rpc_resp = &calldata->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2654 | task_setup_data.callback_data = calldata; | 
|  | 2655 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2656 | if (IS_ERR(task)) | 
|  | 2657 | return PTR_ERR(task); | 
| Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2658 | status = 0; | 
|  | 2659 | if (wait) | 
|  | 2660 | status = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2661 | rpc_put_task(task); | 
| Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2662 | return status; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2663 | out_free_calldata: | 
|  | 2664 | kfree(calldata); | 
|  | 2665 | out: | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2666 | nfs4_put_open_state(state); | 
|  | 2667 | nfs4_put_state_owner(sp); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2668 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | } | 
|  | 2670 |  | 
| Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2671 | static struct inode * | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2672 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, | 
|  | 2673 | int open_flags, struct iattr *attr, int *opened) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | struct nfs4_state *state; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2676 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; | 
|  | 2677 |  | 
|  | 2678 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 |  | 
| Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2680 | /* Protect against concurrent sillydeletes */ | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2681 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2682 |  | 
|  | 2683 | nfs4_label_release_security(label); | 
|  | 2684 |  | 
| Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2685 | if (IS_ERR(state)) | 
|  | 2686 | return ERR_CAST(state); | 
| Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2687 | return state->inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | } | 
|  | 2689 |  | 
| Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2690 | 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] | 2691 | { | 
|  | 2692 | if (ctx->state == NULL) | 
|  | 2693 | return; | 
|  | 2694 | if (is_sync) | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2695 | nfs4_close_sync(ctx->state, ctx->mode); | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2696 | else | 
| Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2697 | nfs4_close_state(ctx->state, ctx->mode); | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2698 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 |  | 
|  | 2700 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 
|  | 2701 | { | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2702 | struct nfs4_server_caps_arg args = { | 
|  | 2703 | .fhandle = fhandle, | 
|  | 2704 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | struct nfs4_server_caps_res res = {}; | 
|  | 2706 | struct rpc_message msg = { | 
|  | 2707 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2708 | .rpc_argp = &args, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | .rpc_resp = &res, | 
|  | 2710 | }; | 
|  | 2711 | int status; | 
|  | 2712 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2713 | 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] | 2714 | if (status == 0) { | 
|  | 2715 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); | 
| Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2716 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| | 
|  | 2717 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| | 
|  | 2718 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| | 
|  | 2719 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| | 
|  | 2720 | NFS_CAP_CTIME|NFS_CAP_MTIME); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) | 
|  | 2722 | server->caps |= NFS_CAP_ACLS; | 
|  | 2723 | if (res.has_links != 0) | 
|  | 2724 | server->caps |= NFS_CAP_HARDLINKS; | 
|  | 2725 | if (res.has_symlinks != 0) | 
|  | 2726 | server->caps |= NFS_CAP_SYMLINKS; | 
| Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2727 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) | 
|  | 2728 | server->caps |= NFS_CAP_FILEID; | 
|  | 2729 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) | 
|  | 2730 | server->caps |= NFS_CAP_MODE; | 
|  | 2731 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) | 
|  | 2732 | server->caps |= NFS_CAP_NLINK; | 
|  | 2733 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) | 
|  | 2734 | server->caps |= NFS_CAP_OWNER; | 
|  | 2735 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) | 
|  | 2736 | server->caps |= NFS_CAP_OWNER_GROUP; | 
|  | 2737 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) | 
|  | 2738 | server->caps |= NFS_CAP_ATIME; | 
|  | 2739 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) | 
|  | 2740 | server->caps |= NFS_CAP_CTIME; | 
|  | 2741 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) | 
|  | 2742 | server->caps |= NFS_CAP_MTIME; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2743 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 2744 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) | 
|  | 2745 | server->caps |= NFS_CAP_SECURITY_LABEL; | 
|  | 2746 | #endif | 
|  | 2747 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, | 
|  | 2748 | sizeof(server->attr_bitmask)); | 
| Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2749 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2750 | if (server->caps & NFS_CAP_SECURITY_LABEL) { | 
|  | 2751 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; | 
|  | 2752 | res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL; | 
|  | 2753 | } | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2754 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); | 
|  | 2755 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; | 
|  | 2756 | server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | server->acl_bitmask = res.acl_bitmask; | 
| Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2758 | server->fh_expire_type = res.fh_expire_type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | } | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2760 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | return status; | 
|  | 2762 | } | 
|  | 2763 |  | 
| Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2764 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | { | 
|  | 2766 | struct nfs4_exception exception = { }; | 
|  | 2767 | int err; | 
|  | 2768 | do { | 
|  | 2769 | err = nfs4_handle_exception(server, | 
|  | 2770 | _nfs4_server_capabilities(server, fhandle), | 
|  | 2771 | &exception); | 
|  | 2772 | } while (exception.retry); | 
|  | 2773 | return err; | 
|  | 2774 | } | 
|  | 2775 |  | 
|  | 2776 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 2777 | struct nfs_fsinfo *info) | 
|  | 2778 | { | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2779 | u32 bitmask[3]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | struct nfs4_lookup_root_arg args = { | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2781 | .bitmask = bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | }; | 
|  | 2783 | struct nfs4_lookup_res res = { | 
|  | 2784 | .server = server, | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2785 | .fattr = info->fattr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | .fh = fhandle, | 
|  | 2787 | }; | 
|  | 2788 | struct rpc_message msg = { | 
|  | 2789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], | 
|  | 2790 | .rpc_argp = &args, | 
|  | 2791 | .rpc_resp = &res, | 
|  | 2792 | }; | 
| Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2793 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2794 | bitmask[0] = nfs4_fattr_bitmap[0]; | 
|  | 2795 | bitmask[1] = nfs4_fattr_bitmap[1]; | 
|  | 2796 | /* | 
|  | 2797 | * Process the label in the upcoming getfattr | 
|  | 2798 | */ | 
|  | 2799 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; | 
|  | 2800 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2801 | nfs_fattr_init(info->fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2802 | 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] | 2803 | } | 
|  | 2804 |  | 
|  | 2805 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 2806 | struct nfs_fsinfo *info) | 
|  | 2807 | { | 
|  | 2808 | struct nfs4_exception exception = { }; | 
|  | 2809 | int err; | 
|  | 2810 | do { | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2811 | err = _nfs4_lookup_root(server, fhandle, info); | 
| Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 2812 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2813 | switch (err) { | 
|  | 2814 | case 0: | 
|  | 2815 | case -NFS4ERR_WRONGSEC: | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2816 | goto out; | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2817 | default: | 
|  | 2818 | err = nfs4_handle_exception(server, err, &exception); | 
|  | 2819 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | } while (exception.retry); | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2821 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | return err; | 
|  | 2823 | } | 
|  | 2824 |  | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2825 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 2826 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) | 
|  | 2827 | { | 
| Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2828 | struct rpc_auth_create_args auth_args = { | 
|  | 2829 | .pseudoflavor = flavor, | 
|  | 2830 | }; | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2831 | struct rpc_auth *auth; | 
|  | 2832 | int ret; | 
|  | 2833 |  | 
| Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 2834 | auth = rpcauth_create(&auth_args, server->client); | 
| Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2835 | if (IS_ERR(auth)) { | 
| Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2836 | ret = -EACCES; | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2837 | goto out; | 
|  | 2838 | } | 
|  | 2839 | ret = nfs4_lookup_root(server, fhandle, info); | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2840 | out: | 
|  | 2841 | return ret; | 
|  | 2842 | } | 
|  | 2843 |  | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2844 | /* | 
|  | 2845 | * Retry pseudoroot lookup with various security flavors.  We do this when: | 
|  | 2846 | * | 
|  | 2847 | *   NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC | 
|  | 2848 | *   NFSv4.1: the server does not support the SECINFO_NO_NAME operation | 
|  | 2849 | * | 
|  | 2850 | * Returns zero on success, or a negative NFS4ERR value, or a | 
|  | 2851 | * negative errno value. | 
|  | 2852 | */ | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2853 | 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] | 2854 | struct nfs_fsinfo *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | { | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2856 | /* Per 3530bis 15.33.5 */ | 
|  | 2857 | static const rpc_authflavor_t flav_array[] = { | 
|  | 2858 | RPC_AUTH_GSS_KRB5P, | 
|  | 2859 | RPC_AUTH_GSS_KRB5I, | 
|  | 2860 | RPC_AUTH_GSS_KRB5, | 
| Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2861 | RPC_AUTH_UNIX,			/* courtesy */ | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2862 | RPC_AUTH_NULL, | 
|  | 2863 | }; | 
|  | 2864 | int status = -EPERM; | 
|  | 2865 | size_t i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 |  | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2867 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2868 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2869 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) | 
| Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2870 | continue; | 
|  | 2871 | break; | 
| Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2872 | } | 
| Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2873 |  | 
| Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2874 | /* | 
|  | 2875 | * -EACCESS could mean that the user doesn't have correct permissions | 
|  | 2876 | * to access the mount.  It could also mean that we tried to mount | 
|  | 2877 | * with a gss auth flavor, but rpc.gssd isn't running.  Either way, | 
|  | 2878 | * existing mount programs don't handle -EACCES very well so it should | 
|  | 2879 | * be mapped to -EPERM instead. | 
|  | 2880 | */ | 
|  | 2881 | if (status == -EACCES) | 
|  | 2882 | status = -EPERM; | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2883 | return status; | 
|  | 2884 | } | 
|  | 2885 |  | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2886 | static int nfs4_do_find_root_sec(struct nfs_server *server, | 
|  | 2887 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) | 
|  | 2888 | { | 
|  | 2889 | int mv = server->nfs_client->cl_minorversion; | 
|  | 2890 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); | 
|  | 2891 | } | 
|  | 2892 |  | 
|  | 2893 | /** | 
|  | 2894 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot | 
|  | 2895 | * @server: initialized nfs_server handle | 
|  | 2896 | * @fhandle: we fill in the pseudo-fs root file handle | 
|  | 2897 | * @info: we fill in an FSINFO struct | 
| Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 2898 | * @auth_probe: probe the auth flavours | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2899 | * | 
|  | 2900 | * Returns zero on success, or a negative errno. | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2901 | */ | 
| Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2902 | 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] | 2903 | struct nfs_fsinfo *info, | 
|  | 2904 | bool auth_probe) | 
| Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2905 | { | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2906 | int status; | 
|  | 2907 |  | 
| Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 2908 | switch (auth_probe) { | 
|  | 2909 | case false: | 
|  | 2910 | status = nfs4_lookup_root(server, fhandle, info); | 
|  | 2911 | if (status != -NFS4ERR_WRONGSEC) | 
|  | 2912 | break; | 
|  | 2913 | /* Did user force a 'sec=' mount option? */ | 
|  | 2914 | if (server->flags & NFS_MOUNT_SECFLAVOUR) | 
|  | 2915 | break; | 
|  | 2916 | default: | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2917 | status = nfs4_do_find_root_sec(server, fhandle, info); | 
| Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 2918 | } | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2919 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | if (status == 0) | 
|  | 2921 | status = nfs4_server_capabilities(server, fhandle); | 
|  | 2922 | if (status == 0) | 
|  | 2923 | status = nfs4_do_fsinfo(server, fhandle, info); | 
| Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2924 |  | 
| Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2925 | return nfs4_map_errors(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | } | 
|  | 2927 |  | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2928 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, | 
|  | 2929 | struct nfs_fsinfo *info) | 
|  | 2930 | { | 
|  | 2931 | int error; | 
|  | 2932 | struct nfs_fattr *fattr = info->fattr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2933 | struct nfs4_label *label = NULL; | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2934 |  | 
|  | 2935 | error = nfs4_server_capabilities(server, mntfh); | 
|  | 2936 | if (error < 0) { | 
|  | 2937 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); | 
|  | 2938 | return error; | 
|  | 2939 | } | 
|  | 2940 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2941 | label = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 2942 | if (IS_ERR(label)) | 
|  | 2943 | return PTR_ERR(label); | 
|  | 2944 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2945 | error = nfs4_proc_getattr(server, mntfh, fattr, label); | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2946 | if (error < 0) { | 
|  | 2947 | dprintk("nfs4_get_root: getattr error = %d\n", -error); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2948 | goto err_free_label; | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2949 | } | 
|  | 2950 |  | 
|  | 2951 | if (fattr->valid & NFS_ATTR_FATTR_FSID && | 
|  | 2952 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) | 
|  | 2953 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); | 
|  | 2954 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2955 | err_free_label: | 
|  | 2956 | nfs4_label_free(label); | 
|  | 2957 |  | 
| Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2958 | return error; | 
|  | 2959 | } | 
|  | 2960 |  | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2961 | /* | 
|  | 2962 | * Get locations and (maybe) other attributes of a referral. | 
|  | 2963 | * Note that we'll actually follow the referral later when | 
|  | 2964 | * we detect fsid mismatch in inode revalidation | 
|  | 2965 | */ | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2966 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, | 
|  | 2967 | const struct qstr *name, struct nfs_fattr *fattr, | 
|  | 2968 | struct nfs_fh *fhandle) | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2969 | { | 
|  | 2970 | int status = -ENOMEM; | 
|  | 2971 | struct page *page = NULL; | 
|  | 2972 | struct nfs4_fs_locations *locations = NULL; | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2973 |  | 
|  | 2974 | page = alloc_page(GFP_KERNEL); | 
|  | 2975 | if (page == NULL) | 
|  | 2976 | goto out; | 
|  | 2977 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); | 
|  | 2978 | if (locations == NULL) | 
|  | 2979 | goto out; | 
|  | 2980 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2981 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2982 | if (status != 0) | 
|  | 2983 | goto out; | 
|  | 2984 | /* Make sure server returned a different fsid for the referral */ | 
|  | 2985 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2986 | dprintk("%s: server did not return a different fsid for" | 
|  | 2987 | " a referral at %s\n", __func__, name->name); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2988 | status = -EIO; | 
|  | 2989 | goto out; | 
|  | 2990 | } | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2991 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ | 
|  | 2992 | nfs_fixup_referral_attributes(&locations->fattr); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2993 |  | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2994 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2995 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2996 | memset(fhandle, 0, sizeof(struct nfs_fh)); | 
|  | 2997 | out: | 
|  | 2998 | if (page) | 
|  | 2999 | __free_page(page); | 
| Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3000 | kfree(locations); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3001 | return status; | 
|  | 3002 | } | 
|  | 3003 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3004 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3005 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | { | 
|  | 3007 | struct nfs4_getattr_arg args = { | 
|  | 3008 | .fh = fhandle, | 
|  | 3009 | .bitmask = server->attr_bitmask, | 
|  | 3010 | }; | 
|  | 3011 | struct nfs4_getattr_res res = { | 
|  | 3012 | .fattr = fattr, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3013 | .label = label, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | .server = server, | 
|  | 3015 | }; | 
|  | 3016 | struct rpc_message msg = { | 
|  | 3017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], | 
|  | 3018 | .rpc_argp = &args, | 
|  | 3019 | .rpc_resp = &res, | 
|  | 3020 | }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3021 |  | 
|  | 3022 | args.bitmask = nfs4_bitmask(server, label); | 
|  | 3023 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3024 | nfs_fattr_init(fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3025 | 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] | 3026 | } | 
|  | 3027 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3028 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3029 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | { | 
|  | 3031 | struct nfs4_exception exception = { }; | 
|  | 3032 | int err; | 
|  | 3033 | do { | 
| Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3034 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); | 
|  | 3035 | trace_nfs4_getattr(server, fhandle, fattr, err); | 
|  | 3036 | err = nfs4_handle_exception(server, err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | &exception); | 
|  | 3038 | } while (exception.retry); | 
|  | 3039 | return err; | 
|  | 3040 | } | 
|  | 3041 |  | 
|  | 3042 | /* | 
|  | 3043 | * The file is not closed if it is opened due to the a request to change | 
|  | 3044 | * the size of the file. The open call will not be needed once the | 
|  | 3045 | * VFS layer lookup-intents are implemented. | 
|  | 3046 | * | 
|  | 3047 | * Close is called when the inode is destroyed. | 
|  | 3048 | * If we haven't opened the file for O_WRONLY, we | 
|  | 3049 | * need to in the size_change case to obtain a stateid. | 
|  | 3050 | * | 
|  | 3051 | * Got race? | 
|  | 3052 | * Because OPEN is always done by name in nfsv4, it is | 
|  | 3053 | * possible that we opened a different file by the same | 
|  | 3054 | * name.  We can recognize this race condition, but we | 
|  | 3055 | * can't do anything about it besides returning an error. | 
|  | 3056 | * | 
|  | 3057 | * This will be fixed with VFS changes (lookup-intent). | 
|  | 3058 | */ | 
|  | 3059 | static int | 
|  | 3060 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, | 
|  | 3061 | struct iattr *sattr) | 
|  | 3062 | { | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3063 | struct inode *inode = dentry->d_inode; | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3064 | struct rpc_cred *cred = NULL; | 
| Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3065 | struct nfs4_state *state = NULL; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3066 | struct nfs4_label *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | int status; | 
|  | 3068 |  | 
| Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3069 | if (pnfs_ld_layoutret_on_setattr(inode)) | 
| Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3070 | pnfs_commit_and_return_layout(inode); | 
| Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3071 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3072 | nfs_fattr_init(fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 |  | 
| Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3074 | /* Deal with open(O_TRUNC) */ | 
|  | 3075 | if (sattr->ia_valid & ATTR_OPEN) | 
| Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3076 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); | 
| Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3077 |  | 
|  | 3078 | /* Optimization: if the end result is no change, don't RPC */ | 
| Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3079 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) | 
| Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3080 | return 0; | 
|  | 3081 |  | 
| Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3082 | /* Search for an existing open(O_WRITE) file */ | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3083 | if (sattr->ia_valid & ATTR_FILE) { | 
|  | 3084 | struct nfs_open_context *ctx; | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3085 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3086 | ctx = nfs_file_open_context(sattr->ia_file); | 
| Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3087 | if (ctx) { | 
|  | 3088 | cred = ctx->cred; | 
|  | 3089 | state = ctx->state; | 
|  | 3090 | } | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3091 | } | 
|  | 3092 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3093 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); | 
|  | 3094 | if (IS_ERR(label)) | 
|  | 3095 | return PTR_ERR(label); | 
|  | 3096 |  | 
|  | 3097 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3098 | if (status == 0) { | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 3099 | nfs_setattr_update_inode(inode, sattr); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3100 | nfs_setsecurity(inode, fattr, label); | 
|  | 3101 | } | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3102 | nfs4_label_free(label); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | return status; | 
|  | 3104 | } | 
|  | 3105 |  | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3106 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, | 
|  | 3107 | const struct qstr *name, struct nfs_fh *fhandle, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3108 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3109 | { | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3110 | struct nfs_server *server = NFS_SERVER(dir); | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3111 | int		       status; | 
|  | 3112 | struct nfs4_lookup_arg args = { | 
|  | 3113 | .bitmask = server->attr_bitmask, | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3114 | .dir_fh = NFS_FH(dir), | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3115 | .name = name, | 
|  | 3116 | }; | 
|  | 3117 | struct nfs4_lookup_res res = { | 
|  | 3118 | .server = server, | 
|  | 3119 | .fattr = fattr, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3120 | .label = label, | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3121 | .fh = fhandle, | 
|  | 3122 | }; | 
|  | 3123 | struct rpc_message msg = { | 
|  | 3124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], | 
|  | 3125 | .rpc_argp = &args, | 
|  | 3126 | .rpc_resp = &res, | 
|  | 3127 | }; | 
|  | 3128 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3129 | args.bitmask = nfs4_bitmask(server, label); | 
|  | 3130 |  | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3131 | nfs_fattr_init(fattr); | 
|  | 3132 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | dprintk("NFS call  lookup %s\n", name->name); | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3134 | 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] | 3135 | dprintk("NFS reply lookup: %d\n", status); | 
|  | 3136 | return status; | 
|  | 3137 | } | 
|  | 3138 |  | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3139 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3140 | { | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3141 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3142 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; | 
| Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3143 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; | 
|  | 3144 | fattr->nlink = 2; | 
|  | 3145 | } | 
|  | 3146 |  | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3147 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, | 
|  | 3148 | struct qstr *name, struct nfs_fh *fhandle, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3149 | struct nfs_fattr *fattr, struct nfs4_label *label) | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3150 | { | 
|  | 3151 | struct nfs4_exception exception = { }; | 
|  | 3152 | struct rpc_clnt *client = *clnt; | 
|  | 3153 | int err; | 
|  | 3154 | do { | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3155 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3156 | trace_nfs4_lookup(dir, name, err); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3157 | switch (err) { | 
|  | 3158 | case -NFS4ERR_BADNAME: | 
|  | 3159 | err = -ENOENT; | 
|  | 3160 | goto out; | 
|  | 3161 | case -NFS4ERR_MOVED: | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3162 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3163 | goto out; | 
|  | 3164 | case -NFS4ERR_WRONGSEC: | 
|  | 3165 | err = -EPERM; | 
|  | 3166 | if (client != *clnt) | 
|  | 3167 | goto out; | 
| Trond Myklebust | 41d058c | 2013-09-07 17:49:05 -0400 | [diff] [blame] | 3168 | /* No security negotiation if the user specified 'sec=' */ | 
|  | 3169 | if (NFS_SERVER(dir)->flags & NFS_MOUNT_SECFLAVOUR) | 
|  | 3170 | goto out; | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3171 | client = nfs4_create_sec_client(client, dir, name); | 
|  | 3172 | if (IS_ERR(client)) | 
|  | 3173 | return PTR_ERR(client); | 
|  | 3174 |  | 
|  | 3175 | exception.retry = 1; | 
|  | 3176 | break; | 
|  | 3177 | default: | 
|  | 3178 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); | 
|  | 3179 | } | 
|  | 3180 | } while (exception.retry); | 
|  | 3181 |  | 
|  | 3182 | out: | 
|  | 3183 | if (err == 0) | 
|  | 3184 | *clnt = client; | 
|  | 3185 | else if (client != *clnt) | 
|  | 3186 | rpc_shutdown_client(client); | 
|  | 3187 |  | 
|  | 3188 | return err; | 
|  | 3189 | } | 
|  | 3190 |  | 
| Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 3191 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3192 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, | 
|  | 3193 | struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | { | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3195 | int status; | 
|  | 3196 | struct rpc_clnt *client = NFS_CLIENT(dir); | 
| Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3197 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3198 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3199 | if (client != NFS_CLIENT(dir)) { | 
|  | 3200 | rpc_shutdown_client(client); | 
|  | 3201 | nfs_fixup_secinfo_attributes(fattr); | 
|  | 3202 | } | 
|  | 3203 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | } | 
|  | 3205 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3206 | struct rpc_clnt * | 
|  | 3207 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, | 
|  | 3208 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
|  | 3209 | { | 
| Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3210 | struct rpc_clnt *client = NFS_CLIENT(dir); | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3211 | int status; | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3212 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3213 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); | 
| Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3214 | if (status < 0) | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3215 | return ERR_PTR(status); | 
| Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3216 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3217 | } | 
|  | 3218 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
|  | 3220 | { | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3221 | struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | struct nfs4_accessargs args = { | 
|  | 3223 | .fh = NFS_FH(inode), | 
| Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3224 | .bitmask = server->cache_consistency_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | }; | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3226 | struct nfs4_accessres res = { | 
|  | 3227 | .server = server, | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3228 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | struct rpc_message msg = { | 
|  | 3230 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], | 
|  | 3231 | .rpc_argp = &args, | 
|  | 3232 | .rpc_resp = &res, | 
|  | 3233 | .rpc_cred = entry->cred, | 
|  | 3234 | }; | 
|  | 3235 | int mode = entry->mask; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3236 | int status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 |  | 
|  | 3238 | /* | 
|  | 3239 | * Determine which access bits we want to ask for... | 
|  | 3240 | */ | 
|  | 3241 | if (mode & MAY_READ) | 
|  | 3242 | args.access |= NFS4_ACCESS_READ; | 
|  | 3243 | if (S_ISDIR(inode->i_mode)) { | 
|  | 3244 | if (mode & MAY_WRITE) | 
|  | 3245 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; | 
|  | 3246 | if (mode & MAY_EXEC) | 
|  | 3247 | args.access |= NFS4_ACCESS_LOOKUP; | 
|  | 3248 | } else { | 
|  | 3249 | if (mode & MAY_WRITE) | 
|  | 3250 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; | 
|  | 3251 | if (mode & MAY_EXEC) | 
|  | 3252 | args.access |= NFS4_ACCESS_EXECUTE; | 
|  | 3253 | } | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3254 |  | 
|  | 3255 | res.fattr = nfs_alloc_fattr(); | 
|  | 3256 | if (res.fattr == NULL) | 
|  | 3257 | return -ENOMEM; | 
|  | 3258 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3259 | 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] | 3260 | if (!status) { | 
| Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3261 | nfs_access_set_mask(entry, res.access); | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3262 | nfs_refresh_inode(inode, res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | } | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3264 | nfs_free_fattr(res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | return status; | 
|  | 3266 | } | 
|  | 3267 |  | 
|  | 3268 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
|  | 3269 | { | 
|  | 3270 | struct nfs4_exception exception = { }; | 
|  | 3271 | int err; | 
|  | 3272 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3273 | err = _nfs4_proc_access(inode, entry); | 
|  | 3274 | trace_nfs4_access(inode, err); | 
|  | 3275 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | &exception); | 
|  | 3277 | } while (exception.retry); | 
|  | 3278 | return err; | 
|  | 3279 | } | 
|  | 3280 |  | 
|  | 3281 | /* | 
|  | 3282 | * TODO: For the time being, we don't try to get any attributes | 
|  | 3283 | * along with any of the zero-copy operations READ, READDIR, | 
|  | 3284 | * READLINK, WRITE. | 
|  | 3285 | * | 
|  | 3286 | * In the case of the first three, we want to put the GETATTR | 
|  | 3287 | * after the read-type operation -- this is because it is hard | 
|  | 3288 | * to predict the length of a GETATTR response in v4, and thus | 
|  | 3289 | * align the READ data correctly.  This means that the GETATTR | 
|  | 3290 | * may end up partially falling into the page cache, and we should | 
|  | 3291 | * shift it into the 'tail' of the xdr_buf before processing. | 
|  | 3292 | * To do this efficiently, we need to know the total length | 
|  | 3293 | * of data received, which doesn't seem to be available outside | 
|  | 3294 | * of the RPC layer. | 
|  | 3295 | * | 
|  | 3296 | * In the case of WRITE, we also want to put the GETATTR after | 
|  | 3297 | * the operation -- in this case because we want to make sure | 
| Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3298 | * we get the post-operation mtime and size. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | * | 
|  | 3300 | * Both of these changes to the XDR layer would in fact be quite | 
|  | 3301 | * minor, but I decided to leave them for a subsequent patch. | 
|  | 3302 | */ | 
|  | 3303 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, | 
|  | 3304 | unsigned int pgbase, unsigned int pglen) | 
|  | 3305 | { | 
|  | 3306 | struct nfs4_readlink args = { | 
|  | 3307 | .fh       = NFS_FH(inode), | 
|  | 3308 | .pgbase	  = pgbase, | 
|  | 3309 | .pglen    = pglen, | 
|  | 3310 | .pages    = &page, | 
|  | 3311 | }; | 
| Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3312 | struct nfs4_readlink_res res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | struct rpc_message msg = { | 
|  | 3314 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], | 
|  | 3315 | .rpc_argp = &args, | 
| Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3316 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | }; | 
|  | 3318 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3319 | 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] | 3320 | } | 
|  | 3321 |  | 
|  | 3322 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, | 
|  | 3323 | unsigned int pgbase, unsigned int pglen) | 
|  | 3324 | { | 
|  | 3325 | struct nfs4_exception exception = { }; | 
|  | 3326 | int err; | 
|  | 3327 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3328 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); | 
|  | 3329 | trace_nfs4_readlink(inode, err); | 
|  | 3330 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | &exception); | 
|  | 3332 | } while (exception.retry); | 
|  | 3333 | return err; | 
|  | 3334 | } | 
|  | 3335 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | /* | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3337 | * 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] | 3338 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | static int | 
|  | 3340 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3341 | int flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | { | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3343 | struct nfs4_label l, *ilabel = NULL; | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3344 | struct nfs_open_context *ctx; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | struct nfs4_state *state; | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3346 | int opened = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | int status = 0; | 
|  | 3348 |  | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3349 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); | 
|  | 3350 | if (IS_ERR(ctx)) | 
|  | 3351 | return PTR_ERR(ctx); | 
|  | 3352 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3353 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 3354 |  | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3355 | sattr->ia_mode &= ~current_umask(); | 
| Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3356 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | if (IS_ERR(state)) { | 
|  | 3358 | status = PTR_ERR(state); | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3359 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | out: | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3362 | nfs4_label_release_security(ilabel); | 
| Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3363 | put_nfs_open_context(ctx); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | return status; | 
|  | 3365 | } | 
|  | 3366 |  | 
|  | 3367 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) | 
|  | 3368 | { | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3369 | struct nfs_server *server = NFS_SERVER(dir); | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3370 | struct nfs_removeargs args = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | .fh = NFS_FH(dir), | 
| Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3372 | .name = *name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | }; | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3374 | struct nfs_removeres res = { | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3375 | .server = server, | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3376 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | struct rpc_message msg = { | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3378 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], | 
|  | 3379 | .rpc_argp = &args, | 
|  | 3380 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | }; | 
| Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3382 | int status; | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3383 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3384 | 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] | 3385 | if (status == 0) | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3386 | update_changeattr(dir, &res.cinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | return status; | 
|  | 3388 | } | 
|  | 3389 |  | 
|  | 3390 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) | 
|  | 3391 | { | 
|  | 3392 | struct nfs4_exception exception = { }; | 
|  | 3393 | int err; | 
|  | 3394 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3395 | err = _nfs4_proc_remove(dir, name); | 
|  | 3396 | trace_nfs4_remove(dir, name, err); | 
|  | 3397 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | &exception); | 
|  | 3399 | } while (exception.retry); | 
|  | 3400 | return err; | 
|  | 3401 | } | 
|  | 3402 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3403 | 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] | 3404 | { | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3405 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 3406 | struct nfs_removeargs *args = msg->rpc_argp; | 
|  | 3407 | struct nfs_removeres *res = msg->rpc_resp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3409 | res->server = server; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3411 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3412 |  | 
|  | 3413 | nfs_fattr_init(res->dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | } | 
|  | 3415 |  | 
| Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3416 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) | 
|  | 3417 | { | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3418 | nfs4_setup_sequence(NFS_SERVER(data->dir), | 
|  | 3419 | &data->args.seq_args, | 
|  | 3420 | &data->res.seq_res, | 
|  | 3421 | task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | } | 
|  | 3423 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3424 | 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] | 3425 | { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3426 | struct nfs_unlinkdata *data = task->tk_calldata; | 
|  | 3427 | struct nfs_removeres *res = &data->res; | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3428 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3429 | if (!nfs4_sequence_done(task, &res->seq_res)) | 
|  | 3430 | return 0; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3431 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3432 | return 0; | 
|  | 3433 | update_changeattr(dir, &res->cinfo); | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3434 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | } | 
|  | 3436 |  | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3437 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) | 
|  | 3438 | { | 
|  | 3439 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 3440 | struct nfs_renameargs *arg = msg->rpc_argp; | 
|  | 3441 | struct nfs_renameres *res = msg->rpc_resp; | 
|  | 3442 |  | 
|  | 3443 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3444 | res->server = server; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3445 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3446 | } | 
|  | 3447 |  | 
| Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3448 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) | 
|  | 3449 | { | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3450 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), | 
|  | 3451 | &data->args.seq_args, | 
|  | 3452 | &data->res.seq_res, | 
|  | 3453 | task); | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3454 | } | 
|  | 3455 |  | 
|  | 3456 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, | 
|  | 3457 | struct inode *new_dir) | 
|  | 3458 | { | 
| Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3459 | struct nfs_renamedata *data = task->tk_calldata; | 
|  | 3460 | struct nfs_renameres *res = &data->res; | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3461 |  | 
|  | 3462 | if (!nfs4_sequence_done(task, &res->seq_res)) | 
|  | 3463 | return 0; | 
|  | 3464 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) | 
|  | 3465 | return 0; | 
|  | 3466 |  | 
|  | 3467 | update_changeattr(old_dir, &res->old_cinfo); | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3468 | update_changeattr(new_dir, &res->new_cinfo); | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3469 | return 1; | 
|  | 3470 | } | 
|  | 3471 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | 
|  | 3473 | struct inode *new_dir, struct qstr *new_name) | 
|  | 3474 | { | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3475 | struct nfs_server *server = NFS_SERVER(old_dir); | 
| Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3476 | struct nfs_renameargs arg = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | .old_dir = NFS_FH(old_dir), | 
|  | 3478 | .new_dir = NFS_FH(new_dir), | 
|  | 3479 | .old_name = old_name, | 
|  | 3480 | .new_name = new_name, | 
|  | 3481 | }; | 
| Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3482 | struct nfs_renameres res = { | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3483 | .server = server, | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3484 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | struct rpc_message msg = { | 
|  | 3486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], | 
|  | 3487 | .rpc_argp = &arg, | 
|  | 3488 | .rpc_resp = &res, | 
|  | 3489 | }; | 
| Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3490 | int status = -ENOMEM; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3491 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3492 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | if (!status) { | 
|  | 3494 | update_changeattr(old_dir, &res.old_cinfo); | 
|  | 3495 | update_changeattr(new_dir, &res.new_cinfo); | 
|  | 3496 | } | 
|  | 3497 | return status; | 
|  | 3498 | } | 
|  | 3499 |  | 
|  | 3500 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | 
|  | 3501 | struct inode *new_dir, struct qstr *new_name) | 
|  | 3502 | { | 
|  | 3503 | struct nfs4_exception exception = { }; | 
|  | 3504 | int err; | 
|  | 3505 | do { | 
| Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3506 | err = _nfs4_proc_rename(old_dir, old_name, | 
|  | 3507 | new_dir, new_name); | 
|  | 3508 | trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err); | 
|  | 3509 | err = nfs4_handle_exception(NFS_SERVER(old_dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | &exception); | 
|  | 3511 | } while (exception.retry); | 
|  | 3512 | return err; | 
|  | 3513 | } | 
|  | 3514 |  | 
|  | 3515 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 
|  | 3516 | { | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3517 | struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | struct nfs4_link_arg arg = { | 
|  | 3519 | .fh     = NFS_FH(inode), | 
|  | 3520 | .dir_fh = NFS_FH(dir), | 
|  | 3521 | .name   = name, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3522 | .bitmask = server->attr_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | }; | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3524 | struct nfs4_link_res res = { | 
|  | 3525 | .server = server, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3526 | .label = NULL, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3527 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | struct rpc_message msg = { | 
|  | 3529 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], | 
|  | 3530 | .rpc_argp = &arg, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3531 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | }; | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3533 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 |  | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3535 | res.fattr = nfs_alloc_fattr(); | 
| Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3536 | if (res.fattr == NULL) | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3537 | goto out; | 
|  | 3538 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3539 | res.label = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 3540 | if (IS_ERR(res.label)) { | 
|  | 3541 | status = PTR_ERR(res.label); | 
|  | 3542 | goto out; | 
|  | 3543 | } | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3544 | arg.bitmask = nfs4_bitmask(server, res.label); | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3545 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3546 | 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] | 3547 | if (!status) { | 
|  | 3548 | update_changeattr(dir, &res.cinfo); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3549 | status = nfs_post_op_update_inode(inode, res.fattr); | 
|  | 3550 | if (!status) | 
|  | 3551 | nfs_setsecurity(inode, res.fattr, res.label); | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3552 | } | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3553 |  | 
|  | 3554 |  | 
|  | 3555 | nfs4_label_free(res.label); | 
|  | 3556 |  | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3557 | out: | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3558 | nfs_free_fattr(res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | return status; | 
|  | 3560 | } | 
|  | 3561 |  | 
|  | 3562 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 
|  | 3563 | { | 
|  | 3564 | struct nfs4_exception exception = { }; | 
|  | 3565 | int err; | 
|  | 3566 | do { | 
|  | 3567 | err = nfs4_handle_exception(NFS_SERVER(inode), | 
|  | 3568 | _nfs4_proc_link(inode, dir, name), | 
|  | 3569 | &exception); | 
|  | 3570 | } while (exception.retry); | 
|  | 3571 | return err; | 
|  | 3572 | } | 
|  | 3573 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3574 | struct nfs4_createdata { | 
|  | 3575 | struct rpc_message msg; | 
|  | 3576 | struct nfs4_create_arg arg; | 
|  | 3577 | struct nfs4_create_res res; | 
|  | 3578 | struct nfs_fh fh; | 
|  | 3579 | struct nfs_fattr fattr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3580 | struct nfs4_label *label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3581 | }; | 
|  | 3582 |  | 
|  | 3583 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, | 
|  | 3584 | struct qstr *name, struct iattr *sattr, u32 ftype) | 
|  | 3585 | { | 
|  | 3586 | struct nfs4_createdata *data; | 
|  | 3587 |  | 
|  | 3588 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 
|  | 3589 | if (data != NULL) { | 
|  | 3590 | struct nfs_server *server = NFS_SERVER(dir); | 
|  | 3591 |  | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3592 | data->label = nfs4_label_alloc(server, GFP_KERNEL); | 
|  | 3593 | if (IS_ERR(data->label)) | 
|  | 3594 | goto out_free; | 
|  | 3595 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3596 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; | 
|  | 3597 | data->msg.rpc_argp = &data->arg; | 
|  | 3598 | data->msg.rpc_resp = &data->res; | 
|  | 3599 | data->arg.dir_fh = NFS_FH(dir); | 
|  | 3600 | data->arg.server = server; | 
|  | 3601 | data->arg.name = name; | 
|  | 3602 | data->arg.attrs = sattr; | 
|  | 3603 | data->arg.ftype = ftype; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3604 | data->arg.bitmask = nfs4_bitmask(server, data->label); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3605 | data->res.server = server; | 
|  | 3606 | data->res.fh = &data->fh; | 
|  | 3607 | data->res.fattr = &data->fattr; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3608 | data->res.label = data->label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3609 | nfs_fattr_init(data->res.fattr); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3610 | } | 
|  | 3611 | return data; | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3612 | out_free: | 
|  | 3613 | kfree(data); | 
|  | 3614 | return NULL; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3615 | } | 
|  | 3616 |  | 
|  | 3617 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) | 
|  | 3618 | { | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3619 | 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] | 3620 | &data->arg.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3621 | if (status == 0) { | 
|  | 3622 | update_changeattr(dir, &data->res.dir_cinfo); | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3623 | 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] | 3624 | } | 
|  | 3625 | return status; | 
|  | 3626 | } | 
|  | 3627 |  | 
|  | 3628 | static void nfs4_free_createdata(struct nfs4_createdata *data) | 
|  | 3629 | { | 
| David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3630 | nfs4_label_free(data->label); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3631 | kfree(data); | 
|  | 3632 | } | 
|  | 3633 |  | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3634 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3635 | struct page *page, unsigned int len, struct iattr *sattr, | 
|  | 3636 | struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3638 | struct nfs4_createdata *data; | 
|  | 3639 | int status = -ENAMETOOLONG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 |  | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3641 | if (len > NFS4_MAXPATHLEN) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3642 | goto out; | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3643 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3644 | status = -ENOMEM; | 
|  | 3645 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); | 
|  | 3646 | if (data == NULL) | 
|  | 3647 | goto out; | 
|  | 3648 |  | 
|  | 3649 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; | 
|  | 3650 | data->arg.u.symlink.pages = &page; | 
|  | 3651 | data->arg.u.symlink.len = len; | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3652 | data->arg.label = label; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3654 | status = nfs4_do_create(dir, dentry, data); | 
|  | 3655 |  | 
|  | 3656 | nfs4_free_createdata(data); | 
|  | 3657 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | return status; | 
|  | 3659 | } | 
|  | 3660 |  | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3661 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3662 | struct page *page, unsigned int len, struct iattr *sattr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | { | 
|  | 3664 | struct nfs4_exception exception = { }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3665 | struct nfs4_label l, *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | int err; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3667 |  | 
|  | 3668 | label = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 3669 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3671 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); | 
|  | 3672 | trace_nfs4_symlink(dir, &dentry->d_name, err); | 
|  | 3673 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | &exception); | 
|  | 3675 | } while (exception.retry); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3676 |  | 
|  | 3677 | nfs4_label_release_security(label); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | return err; | 
|  | 3679 | } | 
|  | 3680 |  | 
|  | 3681 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3682 | struct iattr *sattr, struct nfs4_label *label) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3684 | struct nfs4_createdata *data; | 
|  | 3685 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3687 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); | 
|  | 3688 | if (data == NULL) | 
|  | 3689 | goto out; | 
|  | 3690 |  | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3691 | data->arg.label = label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3692 | status = nfs4_do_create(dir, dentry, data); | 
|  | 3693 |  | 
|  | 3694 | nfs4_free_createdata(data); | 
|  | 3695 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | return status; | 
|  | 3697 | } | 
|  | 3698 |  | 
|  | 3699 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 
|  | 3700 | struct iattr *sattr) | 
|  | 3701 | { | 
|  | 3702 | struct nfs4_exception exception = { }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3703 | struct nfs4_label l, *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | int err; | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3705 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3706 | label = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 3707 |  | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3708 | sattr->ia_mode &= ~current_umask(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3710 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); | 
|  | 3711 | trace_nfs4_mkdir(dir, &dentry->d_name, err); | 
|  | 3712 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | &exception); | 
|  | 3714 | } while (exception.retry); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3715 | nfs4_label_release_security(label); | 
|  | 3716 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | return err; | 
|  | 3718 | } | 
|  | 3719 |  | 
|  | 3720 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3721 | u64 cookie, struct page **pages, unsigned int count, int plus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | { | 
|  | 3723 | struct inode		*dir = dentry->d_inode; | 
|  | 3724 | struct nfs4_readdir_arg args = { | 
|  | 3725 | .fh = NFS_FH(dir), | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3726 | .pages = pages, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | .pgbase = 0, | 
|  | 3728 | .count = count, | 
| Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3729 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, | 
| Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3730 | .plus = plus, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | }; | 
|  | 3732 | struct nfs4_readdir_res res; | 
|  | 3733 | struct rpc_message msg = { | 
|  | 3734 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], | 
|  | 3735 | .rpc_argp = &args, | 
|  | 3736 | .rpc_resp = &res, | 
|  | 3737 | .rpc_cred = cred, | 
|  | 3738 | }; | 
|  | 3739 | int			status; | 
|  | 3740 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3741 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, | 
| Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3742 | dentry->d_parent->d_name.name, | 
|  | 3743 | dentry->d_name.name, | 
|  | 3744 | (unsigned long long)cookie); | 
| Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3745 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | res.pgbase = args.pgbase; | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3747 | 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] | 3748 | if (status >= 0) { | 
| Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3749 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); | 
| Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3750 | status += args.pgbase; | 
|  | 3751 | } | 
| Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3752 |  | 
|  | 3753 | nfs_invalidate_atime(dir); | 
|  | 3754 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3755 | dprintk("%s: returns %d\n", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | return status; | 
|  | 3757 | } | 
|  | 3758 |  | 
|  | 3759 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3760 | u64 cookie, struct page **pages, unsigned int count, int plus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | { | 
|  | 3762 | struct nfs4_exception exception = { }; | 
|  | 3763 | int err; | 
|  | 3764 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3765 | err = _nfs4_proc_readdir(dentry, cred, cookie, | 
|  | 3766 | pages, count, plus); | 
|  | 3767 | trace_nfs4_readdir(dentry->d_inode, err); | 
|  | 3768 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | &exception); | 
|  | 3770 | } while (exception.retry); | 
|  | 3771 | return err; | 
|  | 3772 | } | 
|  | 3773 |  | 
|  | 3774 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3775 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3777 | struct nfs4_createdata *data; | 
|  | 3778 | int mode = sattr->ia_mode; | 
|  | 3779 | int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3781 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); | 
|  | 3782 | if (data == NULL) | 
|  | 3783 | goto out; | 
|  | 3784 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | if (S_ISFIFO(mode)) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3786 | data->arg.ftype = NF4FIFO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | else if (S_ISBLK(mode)) { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3788 | data->arg.ftype = NF4BLK; | 
|  | 3789 | data->arg.u.device.specdata1 = MAJOR(rdev); | 
|  | 3790 | data->arg.u.device.specdata2 = MINOR(rdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | } | 
|  | 3792 | else if (S_ISCHR(mode)) { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3793 | data->arg.ftype = NF4CHR; | 
|  | 3794 | data->arg.u.device.specdata1 = MAJOR(rdev); | 
|  | 3795 | data->arg.u.device.specdata2 = MINOR(rdev); | 
| Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3796 | } else if (!S_ISSOCK(mode)) { | 
|  | 3797 | status = -EINVAL; | 
|  | 3798 | goto out_free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | } | 
| David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3800 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3801 | data->arg.label = label; | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3802 | status = nfs4_do_create(dir, dentry, data); | 
| Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3803 | out_free: | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3804 | nfs4_free_createdata(data); | 
|  | 3805 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | return status; | 
|  | 3807 | } | 
|  | 3808 |  | 
|  | 3809 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 
|  | 3810 | struct iattr *sattr, dev_t rdev) | 
|  | 3811 | { | 
|  | 3812 | struct nfs4_exception exception = { }; | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3813 | struct nfs4_label l, *label = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | int err; | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3815 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3816 | label = nfs4_label_init_security(dir, dentry, sattr, &l); | 
|  | 3817 |  | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3818 | sattr->ia_mode &= ~current_umask(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3820 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); | 
|  | 3821 | trace_nfs4_mknod(dir, &dentry->d_name, err); | 
|  | 3822 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | &exception); | 
|  | 3824 | } while (exception.retry); | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3825 |  | 
|  | 3826 | nfs4_label_release_security(label); | 
|  | 3827 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | return err; | 
|  | 3829 | } | 
|  | 3830 |  | 
|  | 3831 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3832 | struct nfs_fsstat *fsstat) | 
|  | 3833 | { | 
|  | 3834 | struct nfs4_statfs_arg args = { | 
|  | 3835 | .fh = fhandle, | 
|  | 3836 | .bitmask = server->attr_bitmask, | 
|  | 3837 | }; | 
| Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3838 | struct nfs4_statfs_res res = { | 
|  | 3839 | .fsstat = fsstat, | 
|  | 3840 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | struct rpc_message msg = { | 
|  | 3842 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], | 
|  | 3843 | .rpc_argp = &args, | 
| Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3844 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | }; | 
|  | 3846 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3847 | nfs_fattr_init(fsstat->fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3848 | 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] | 3849 | } | 
|  | 3850 |  | 
|  | 3851 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) | 
|  | 3852 | { | 
|  | 3853 | struct nfs4_exception exception = { }; | 
|  | 3854 | int err; | 
|  | 3855 | do { | 
|  | 3856 | err = nfs4_handle_exception(server, | 
|  | 3857 | _nfs4_proc_statfs(server, fhandle, fsstat), | 
|  | 3858 | &exception); | 
|  | 3859 | } while (exception.retry); | 
|  | 3860 | return err; | 
|  | 3861 | } | 
|  | 3862 |  | 
|  | 3863 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3864 | struct nfs_fsinfo *fsinfo) | 
|  | 3865 | { | 
|  | 3866 | struct nfs4_fsinfo_arg args = { | 
|  | 3867 | .fh = fhandle, | 
|  | 3868 | .bitmask = server->attr_bitmask, | 
|  | 3869 | }; | 
| Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3870 | struct nfs4_fsinfo_res res = { | 
|  | 3871 | .fsinfo = fsinfo, | 
|  | 3872 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | struct rpc_message msg = { | 
|  | 3874 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], | 
|  | 3875 | .rpc_argp = &args, | 
| Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3876 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | }; | 
|  | 3878 |  | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3879 | 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] | 3880 | } | 
|  | 3881 |  | 
|  | 3882 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 
|  | 3883 | { | 
|  | 3884 | struct nfs4_exception exception = { }; | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3885 | unsigned long now = jiffies; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | int err; | 
|  | 3887 |  | 
|  | 3888 | do { | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3889 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); | 
| Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3890 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); | 
| Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3891 | if (err == 0) { | 
|  | 3892 | struct nfs_client *clp = server->nfs_client; | 
|  | 3893 |  | 
|  | 3894 | spin_lock(&clp->cl_lock); | 
|  | 3895 | clp->cl_lease_time = fsinfo->lease_time * HZ; | 
|  | 3896 | clp->cl_last_renewal = now; | 
|  | 3897 | spin_unlock(&clp->cl_lock); | 
|  | 3898 | break; | 
|  | 3899 | } | 
|  | 3900 | err = nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | } while (exception.retry); | 
|  | 3902 | return err; | 
|  | 3903 | } | 
|  | 3904 |  | 
|  | 3905 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 
|  | 3906 | { | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3907 | int error; | 
|  | 3908 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3909 | nfs_fattr_init(fsinfo->fattr); | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3910 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); | 
| Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3911 | if (error == 0) { | 
|  | 3912 | /* block layout checks this! */ | 
|  | 3913 | server->pnfs_blksize = fsinfo->blksize; | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3914 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); | 
| Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3915 | } | 
| Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3916 |  | 
|  | 3917 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | } | 
|  | 3919 |  | 
|  | 3920 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3921 | struct nfs_pathconf *pathconf) | 
|  | 3922 | { | 
|  | 3923 | struct nfs4_pathconf_arg args = { | 
|  | 3924 | .fh = fhandle, | 
|  | 3925 | .bitmask = server->attr_bitmask, | 
|  | 3926 | }; | 
| Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3927 | struct nfs4_pathconf_res res = { | 
|  | 3928 | .pathconf = pathconf, | 
|  | 3929 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | struct rpc_message msg = { | 
|  | 3931 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], | 
|  | 3932 | .rpc_argp = &args, | 
| Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3933 | .rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | }; | 
|  | 3935 |  | 
|  | 3936 | /* None of the pathconf attributes are mandatory to implement */ | 
|  | 3937 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { | 
|  | 3938 | memset(pathconf, 0, sizeof(*pathconf)); | 
|  | 3939 | return 0; | 
|  | 3940 | } | 
|  | 3941 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3942 | nfs_fattr_init(pathconf->fattr); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3943 | 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] | 3944 | } | 
|  | 3945 |  | 
|  | 3946 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 3947 | struct nfs_pathconf *pathconf) | 
|  | 3948 | { | 
|  | 3949 | struct nfs4_exception exception = { }; | 
|  | 3950 | int err; | 
|  | 3951 |  | 
|  | 3952 | do { | 
|  | 3953 | err = nfs4_handle_exception(server, | 
|  | 3954 | _nfs4_proc_pathconf(server, fhandle, pathconf), | 
|  | 3955 | &exception); | 
|  | 3956 | } while (exception.retry); | 
|  | 3957 | return err; | 
|  | 3958 | } | 
|  | 3959 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3960 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3961 | const struct nfs_open_context *ctx, | 
|  | 3962 | const struct nfs_lock_context *l_ctx, | 
|  | 3963 | fmode_t fmode) | 
|  | 3964 | { | 
|  | 3965 | const struct nfs_lockowner *lockowner = NULL; | 
|  | 3966 |  | 
|  | 3967 | if (l_ctx != NULL) | 
|  | 3968 | lockowner = &l_ctx->lockowner; | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3969 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3970 | } | 
|  | 3971 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); | 
|  | 3972 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3973 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, | 
|  | 3974 | const struct nfs_open_context *ctx, | 
|  | 3975 | const struct nfs_lock_context *l_ctx, | 
|  | 3976 | fmode_t fmode) | 
|  | 3977 | { | 
|  | 3978 | nfs4_stateid current_stateid; | 
|  | 3979 |  | 
|  | 3980 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) | 
|  | 3981 | return false; | 
|  | 3982 | return nfs4_stateid_match(stateid, ¤t_stateid); | 
|  | 3983 | } | 
|  | 3984 |  | 
|  | 3985 | static bool nfs4_error_stateid_expired(int err) | 
|  | 3986 | { | 
|  | 3987 | switch (err) { | 
|  | 3988 | case -NFS4ERR_DELEG_REVOKED: | 
|  | 3989 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 3990 | case -NFS4ERR_BAD_STATEID: | 
|  | 3991 | case -NFS4ERR_STALE_STATEID: | 
|  | 3992 | case -NFS4ERR_OLD_STATEID: | 
|  | 3993 | case -NFS4ERR_OPENMODE: | 
|  | 3994 | case -NFS4ERR_EXPIRED: | 
|  | 3995 | return true; | 
|  | 3996 | } | 
|  | 3997 | return false; | 
|  | 3998 | } | 
|  | 3999 |  | 
| Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4000 | void __nfs4_read_done_cb(struct nfs_read_data *data) | 
|  | 4001 | { | 
| Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4002 | nfs_invalidate_atime(data->header->inode); | 
| Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4003 | } | 
|  | 4004 |  | 
| Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4005 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | { | 
| Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4007 | struct nfs_server *server = NFS_SERVER(data->header->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 |  | 
| Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4009 | trace_nfs4_read(data, task->tk_status); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4010 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4011 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4012 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | } | 
| Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4014 |  | 
| Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4015 | __nfs4_read_done_cb(data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | if (task->tk_status > 0) | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4017 | renew_lease(server, data->timestamp); | 
|  | 4018 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | } | 
|  | 4020 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4021 | static bool nfs4_read_stateid_changed(struct rpc_task *task, | 
|  | 4022 | struct nfs_readargs *args) | 
|  | 4023 | { | 
|  | 4024 |  | 
|  | 4025 | if (!nfs4_error_stateid_expired(task->tk_status) || | 
|  | 4026 | nfs4_stateid_is_current(&args->stateid, | 
|  | 4027 | args->context, | 
|  | 4028 | args->lock_context, | 
|  | 4029 | FMODE_READ)) | 
|  | 4030 | return false; | 
|  | 4031 | rpc_restart_call_prepare(task); | 
|  | 4032 | return true; | 
|  | 4033 | } | 
|  | 4034 |  | 
| Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4035 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) | 
|  | 4036 | { | 
|  | 4037 |  | 
|  | 4038 | dprintk("--> %s\n", __func__); | 
|  | 4039 |  | 
|  | 4040 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 4041 | return -EAGAIN; | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4042 | if (nfs4_read_stateid_changed(task, &data->args)) | 
|  | 4043 | return -EAGAIN; | 
| Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4044 | return data->read_done_cb ? data->read_done_cb(task, data) : | 
|  | 4045 | nfs4_read_done_cb(task, data); | 
| Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4046 | } | 
|  | 4047 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4048 | static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | data->timestamp   = jiffies; | 
| Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4051 | data->read_done_cb = nfs4_read_done_cb; | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4052 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4053 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | } | 
|  | 4055 |  | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4056 | static int nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) | 
| Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4057 | { | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4058 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4059 | &data->args.seq_args, | 
|  | 4060 | &data->res.seq_res, | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4061 | task)) | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4062 | return 0; | 
|  | 4063 | if (nfs4_set_rw_stateid(&data->args.stateid, data->args.context, | 
|  | 4064 | data->args.lock_context, FMODE_READ) == -EIO) | 
|  | 4065 | return -EIO; | 
|  | 4066 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &data->args.context->flags))) | 
|  | 4067 | return -EIO; | 
|  | 4068 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | } | 
|  | 4070 |  | 
| Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4071 | static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | { | 
| Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4073 | struct inode *inode = data->header->inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 |  | 
| Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4075 | trace_nfs4_write(data, task->tk_status); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4076 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4077 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4078 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | } | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4080 | if (task->tk_status >= 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | renew_lease(NFS_SERVER(inode), data->timestamp); | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4082 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4083 | } | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4084 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } | 
|  | 4086 |  | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4087 | static bool nfs4_write_stateid_changed(struct rpc_task *task, | 
|  | 4088 | struct nfs_writeargs *args) | 
|  | 4089 | { | 
|  | 4090 |  | 
|  | 4091 | if (!nfs4_error_stateid_expired(task->tk_status) || | 
|  | 4092 | nfs4_stateid_is_current(&args->stateid, | 
|  | 4093 | args->context, | 
|  | 4094 | args->lock_context, | 
|  | 4095 | FMODE_WRITE)) | 
|  | 4096 | return false; | 
|  | 4097 | rpc_restart_call_prepare(task); | 
|  | 4098 | return true; | 
|  | 4099 | } | 
|  | 4100 |  | 
| Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4101 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) | 
|  | 4102 | { | 
|  | 4103 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 4104 | return -EAGAIN; | 
| Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4105 | if (nfs4_write_stateid_changed(task, &data->args)) | 
|  | 4106 | return -EAGAIN; | 
| Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4107 | return data->write_done_cb ? data->write_done_cb(task, data) : | 
|  | 4108 | nfs4_write_done_cb(task, data); | 
| Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4109 | } | 
|  | 4110 |  | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4111 | static | 
|  | 4112 | bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data) | 
| Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4113 | { | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4114 | const struct nfs_pgio_header *hdr = data->header; | 
|  | 4115 |  | 
|  | 4116 | /* Don't request attributes for pNFS or O_DIRECT writes */ | 
|  | 4117 | if (data->ds_clp != NULL || hdr->dreq != NULL) | 
|  | 4118 | return false; | 
|  | 4119 | /* Otherwise, request attributes if and only if we don't hold | 
|  | 4120 | * a delegation | 
|  | 4121 | */ | 
| Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4122 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; | 
| Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4123 | } | 
| Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4124 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4125 | static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | { | 
| Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 4127 | struct nfs_server *server = NFS_SERVER(data->header->inode); | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4128 |  | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4129 | if (!nfs4_write_need_cache_consistency_data(data)) { | 
| Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4130 | data->args.bitmask = NULL; | 
|  | 4131 | data->res.fattr = NULL; | 
|  | 4132 | } else | 
|  | 4133 | data->args.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4134 |  | 
| Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4135 | if (!data->write_done_cb) | 
|  | 4136 | data->write_done_cb = nfs4_write_done_cb; | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4137 | data->res.server = server; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | data->timestamp   = jiffies; | 
|  | 4139 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4140 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4141 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | } | 
|  | 4143 |  | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4144 | static int nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) | 
| Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 4145 | { | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4146 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4147 | &data->args.seq_args, | 
|  | 4148 | &data->res.seq_res, | 
| Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4149 | task)) | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4150 | return 0; | 
|  | 4151 | if (nfs4_set_rw_stateid(&data->args.stateid, data->args.context, | 
|  | 4152 | data->args.lock_context, FMODE_WRITE) == -EIO) | 
|  | 4153 | return -EIO; | 
|  | 4154 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &data->args.context->flags))) | 
|  | 4155 | return -EIO; | 
|  | 4156 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | } | 
|  | 4158 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4159 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) | 
|  | 4160 | { | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4161 | nfs4_setup_sequence(NFS_SERVER(data->inode), | 
|  | 4162 | &data->args.seq_args, | 
|  | 4163 | &data->res.seq_res, | 
|  | 4164 | task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | } | 
|  | 4166 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4167 | 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] | 4168 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | struct inode *inode = data->inode; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4170 |  | 
| Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4171 | trace_nfs4_commit(data, task->tk_status); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4172 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4173 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4174 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | } | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4176 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | } | 
|  | 4178 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4179 | 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] | 4180 | { | 
|  | 4181 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 4182 | return -EAGAIN; | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4183 | return data->commit_done_cb(task, data); | 
| Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4184 | } | 
|  | 4185 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4186 | 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] | 4187 | { | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4188 | struct nfs_server *server = NFS_SERVER(data->inode); | 
| Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4189 |  | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4190 | if (data->commit_done_cb == NULL) | 
|  | 4191 | data->commit_done_cb = nfs4_commit_done_cb; | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4192 | data->res.server = server; | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4193 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4194 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | } | 
|  | 4196 |  | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4197 | struct nfs4_renewdata { | 
|  | 4198 | struct nfs_client	*client; | 
|  | 4199 | unsigned long		timestamp; | 
|  | 4200 | }; | 
|  | 4201 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | /* | 
|  | 4203 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special | 
|  | 4204 | * standalone procedure for queueing an asynchronous RENEW. | 
|  | 4205 | */ | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4206 | static void nfs4_renew_release(void *calldata) | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4207 | { | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4208 | struct nfs4_renewdata *data = calldata; | 
|  | 4209 | struct nfs_client *clp = data->client; | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4210 |  | 
| Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4211 | if (atomic_read(&clp->cl_count) > 1) | 
|  | 4212 | nfs4_schedule_state_renewal(clp); | 
|  | 4213 | nfs_put_client(clp); | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4214 | kfree(data); | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4215 | } | 
|  | 4216 |  | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4217 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | { | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4219 | struct nfs4_renewdata *data = calldata; | 
|  | 4220 | struct nfs_client *clp = data->client; | 
|  | 4221 | unsigned long timestamp = data->timestamp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4223 | trace_nfs4_renew_async(clp, task->tk_status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | if (task->tk_status < 0) { | 
| Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4225 | /* Unless we're shutting down, schedule state recovery! */ | 
| Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4226 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) | 
|  | 4227 | return; | 
|  | 4228 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4229 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4230 | return; | 
|  | 4231 | } | 
|  | 4232 | nfs4_schedule_path_down_recovery(clp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | } | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4234 | do_renew_lease(clp, timestamp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | } | 
|  | 4236 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4237 | static const struct rpc_call_ops nfs4_renew_ops = { | 
|  | 4238 | .rpc_call_done = nfs4_renew_done, | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4239 | .rpc_release = nfs4_renew_release, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4240 | }; | 
|  | 4241 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4242 | 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] | 4243 | { | 
|  | 4244 | struct rpc_message msg = { | 
|  | 4245 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 
|  | 4246 | .rpc_argp	= clp, | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4247 | .rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | }; | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4249 | struct nfs4_renewdata *data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4251 | if (renew_flags == 0) | 
|  | 4252 | return 0; | 
| Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4253 | if (!atomic_inc_not_zero(&clp->cl_count)) | 
|  | 4254 | return -EIO; | 
| Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4255 | data = kmalloc(sizeof(*data), GFP_NOFS); | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4256 | if (data == NULL) | 
|  | 4257 | return -ENOMEM; | 
|  | 4258 | data->client = clp; | 
|  | 4259 | data->timestamp = jiffies; | 
| Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4260 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4261 | &nfs4_renew_ops, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | } | 
|  | 4263 |  | 
| Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4264 | 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] | 4265 | { | 
|  | 4266 | struct rpc_message msg = { | 
|  | 4267 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 
|  | 4268 | .rpc_argp	= clp, | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4269 | .rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | }; | 
|  | 4271 | unsigned long now = jiffies; | 
|  | 4272 | int status; | 
|  | 4273 |  | 
| Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4274 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | if (status < 0) | 
|  | 4276 | return status; | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4277 | do_renew_lease(clp, now); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | return 0; | 
|  | 4279 | } | 
|  | 4280 |  | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4281 | static inline int nfs4_server_supports_acls(struct nfs_server *server) | 
|  | 4282 | { | 
|  | 4283 | return (server->caps & NFS_CAP_ACLS) | 
|  | 4284 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) | 
|  | 4285 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); | 
|  | 4286 | } | 
|  | 4287 |  | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4288 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that | 
|  | 4289 | * 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] | 4290 | * the stack. | 
|  | 4291 | */ | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4292 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4293 |  | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4294 | static int buf_to_pages_noslab(const void *buf, size_t buflen, | 
|  | 4295 | struct page **pages, unsigned int *pgbase) | 
|  | 4296 | { | 
|  | 4297 | struct page *newpage, **spages; | 
|  | 4298 | int rc = 0; | 
|  | 4299 | size_t len; | 
|  | 4300 | spages = pages; | 
|  | 4301 |  | 
|  | 4302 | do { | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4303 | len = min_t(size_t, PAGE_SIZE, buflen); | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4304 | newpage = alloc_page(GFP_KERNEL); | 
|  | 4305 |  | 
|  | 4306 | if (newpage == NULL) | 
|  | 4307 | goto unwind; | 
|  | 4308 | memcpy(page_address(newpage), buf, len); | 
|  | 4309 | buf += len; | 
|  | 4310 | buflen -= len; | 
|  | 4311 | *pages++ = newpage; | 
|  | 4312 | rc++; | 
|  | 4313 | } while (buflen != 0); | 
|  | 4314 |  | 
|  | 4315 | return rc; | 
|  | 4316 |  | 
|  | 4317 | unwind: | 
|  | 4318 | for(; rc > 0; rc--) | 
|  | 4319 | __free_page(spages[rc-1]); | 
|  | 4320 | return -ENOMEM; | 
|  | 4321 | } | 
|  | 4322 |  | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4323 | struct nfs4_cached_acl { | 
|  | 4324 | int cached; | 
|  | 4325 | size_t len; | 
| Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4326 | char data[0]; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4327 | }; | 
|  | 4328 |  | 
|  | 4329 | 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] | 4330 | { | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4331 | struct nfs_inode *nfsi = NFS_I(inode); | 
|  | 4332 |  | 
|  | 4333 | spin_lock(&inode->i_lock); | 
|  | 4334 | kfree(nfsi->nfs4_acl); | 
|  | 4335 | nfsi->nfs4_acl = acl; | 
|  | 4336 | spin_unlock(&inode->i_lock); | 
|  | 4337 | } | 
|  | 4338 |  | 
|  | 4339 | static void nfs4_zap_acl_attr(struct inode *inode) | 
|  | 4340 | { | 
|  | 4341 | nfs4_set_cached_acl(inode, NULL); | 
|  | 4342 | } | 
|  | 4343 |  | 
|  | 4344 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) | 
|  | 4345 | { | 
|  | 4346 | struct nfs_inode *nfsi = NFS_I(inode); | 
|  | 4347 | struct nfs4_cached_acl *acl; | 
|  | 4348 | int ret = -ENOENT; | 
|  | 4349 |  | 
|  | 4350 | spin_lock(&inode->i_lock); | 
|  | 4351 | acl = nfsi->nfs4_acl; | 
|  | 4352 | if (acl == NULL) | 
|  | 4353 | goto out; | 
|  | 4354 | if (buf == NULL) /* user is just asking for length */ | 
|  | 4355 | goto out_len; | 
|  | 4356 | if (acl->cached == 0) | 
|  | 4357 | goto out; | 
|  | 4358 | ret = -ERANGE; /* see getxattr(2) man page */ | 
|  | 4359 | if (acl->len > buflen) | 
|  | 4360 | goto out; | 
|  | 4361 | memcpy(buf, acl->data, acl->len); | 
|  | 4362 | out_len: | 
|  | 4363 | ret = acl->len; | 
|  | 4364 | out: | 
|  | 4365 | spin_unlock(&inode->i_lock); | 
|  | 4366 | return ret; | 
|  | 4367 | } | 
|  | 4368 |  | 
| Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4369 | 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] | 4370 | { | 
|  | 4371 | struct nfs4_cached_acl *acl; | 
| Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4372 | size_t buflen = sizeof(*acl) + acl_len; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4373 |  | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4374 | if (buflen <= PAGE_SIZE) { | 
| Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4375 | acl = kmalloc(buflen, GFP_KERNEL); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4376 | if (acl == NULL) | 
|  | 4377 | goto out; | 
|  | 4378 | acl->cached = 1; | 
| Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4379 | _copy_from_pages(acl->data, pages, pgbase, acl_len); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4380 | } else { | 
|  | 4381 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); | 
|  | 4382 | if (acl == NULL) | 
|  | 4383 | goto out; | 
|  | 4384 | acl->cached = 0; | 
|  | 4385 | } | 
|  | 4386 | acl->len = acl_len; | 
|  | 4387 | out: | 
|  | 4388 | nfs4_set_cached_acl(inode, acl); | 
|  | 4389 | } | 
|  | 4390 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4391 | /* | 
|  | 4392 | * The getxattr API returns the required buffer length when called with a | 
|  | 4393 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating | 
|  | 4394 | * the required buf.  On a NULL buf, we send a page of data to the server | 
|  | 4395 | * guessing that the ACL request can be serviced by a page. If so, we cache | 
|  | 4396 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by | 
|  | 4397 | * the cache. If not so, we throw away the page, and cache the required | 
|  | 4398 | * length. The next getxattr call will then produce another round trip to | 
|  | 4399 | * the server, this time with the input buf of the required size. | 
|  | 4400 | */ | 
| Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4401 | 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] | 4402 | { | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4403 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4404 | struct nfs_getaclargs args = { | 
|  | 4405 | .fh = NFS_FH(inode), | 
|  | 4406 | .acl_pages = pages, | 
|  | 4407 | .acl_len = buflen, | 
|  | 4408 | }; | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4409 | struct nfs_getaclres res = { | 
|  | 4410 | .acl_len = buflen, | 
|  | 4411 | }; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4412 | struct rpc_message msg = { | 
|  | 4413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], | 
|  | 4414 | .rpc_argp = &args, | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4415 | .rpc_resp = &res, | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4416 | }; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4417 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); | 
|  | 4418 | int ret = -ENOMEM, i; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4419 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4420 | /* As long as we're doing a round trip to the server anyway, | 
|  | 4421 | * let's be prepared for a page of acl data. */ | 
|  | 4422 | if (npages == 0) | 
|  | 4423 | npages = 1; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4424 | if (npages > ARRAY_SIZE(pages)) | 
|  | 4425 | return -ERANGE; | 
| Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4426 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4427 | for (i = 0; i < npages; i++) { | 
|  | 4428 | pages[i] = alloc_page(GFP_KERNEL); | 
|  | 4429 | if (!pages[i]) | 
|  | 4430 | goto out_free; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4431 | } | 
| Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4432 |  | 
|  | 4433 | /* for decoding across pages */ | 
|  | 4434 | res.acl_scratch = alloc_page(GFP_KERNEL); | 
|  | 4435 | if (!res.acl_scratch) | 
|  | 4436 | goto out_free; | 
|  | 4437 |  | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4438 | args.acl_len = npages * PAGE_SIZE; | 
|  | 4439 | args.acl_pgbase = 0; | 
| Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4440 |  | 
| Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4441 | 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] | 4442 | __func__, buf, buflen, npages, args.acl_len); | 
|  | 4443 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), | 
|  | 4444 | &msg, &args.seq_args, &res.seq_res, 0); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4445 | if (ret) | 
|  | 4446 | goto out_free; | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4447 |  | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4448 | /* Handle the case where the passed-in buffer is too short */ | 
|  | 4449 | if (res.acl_flags & NFS4_ACL_TRUNC) { | 
|  | 4450 | /* Did the user only issue a request for the acl length? */ | 
|  | 4451 | if (buf == NULL) | 
|  | 4452 | goto out_ok; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4453 | ret = -ERANGE; | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4454 | goto out_free; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4455 | } | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4456 | 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] | 4457 | if (buf) { | 
|  | 4458 | if (res.acl_len > buflen) { | 
|  | 4459 | ret = -ERANGE; | 
|  | 4460 | goto out_free; | 
|  | 4461 | } | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4462 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); | 
| Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4463 | } | 
| Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4464 | out_ok: | 
|  | 4465 | ret = res.acl_len; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4466 | out_free: | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4467 | for (i = 0; i < npages; i++) | 
|  | 4468 | if (pages[i]) | 
|  | 4469 | __free_page(pages[i]); | 
| Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4470 | if (res.acl_scratch) | 
|  | 4471 | __free_page(res.acl_scratch); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4472 | return ret; | 
|  | 4473 | } | 
|  | 4474 |  | 
| Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4475 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) | 
|  | 4476 | { | 
|  | 4477 | struct nfs4_exception exception = { }; | 
|  | 4478 | ssize_t ret; | 
|  | 4479 | do { | 
|  | 4480 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4481 | trace_nfs4_get_acl(inode, ret); | 
| Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4482 | if (ret >= 0) | 
|  | 4483 | break; | 
|  | 4484 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); | 
|  | 4485 | } while (exception.retry); | 
|  | 4486 | return ret; | 
|  | 4487 | } | 
|  | 4488 |  | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4489 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) | 
|  | 4490 | { | 
|  | 4491 | struct nfs_server *server = NFS_SERVER(inode); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4492 | int ret; | 
|  | 4493 |  | 
|  | 4494 | if (!nfs4_server_supports_acls(server)) | 
|  | 4495 | return -EOPNOTSUPP; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4496 | ret = nfs_revalidate_inode(server, inode); | 
|  | 4497 | if (ret < 0) | 
|  | 4498 | return ret; | 
| Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4499 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) | 
|  | 4500 | nfs_zap_acl_cache(inode); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4501 | ret = nfs4_read_cached_acl(inode, buf, buflen); | 
|  | 4502 | if (ret != -ENOENT) | 
| Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4503 | /* -ENOENT is returned if there is no ACL or if there is an ACL | 
|  | 4504 | * but no cached acl data, just the acl length */ | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4505 | return ret; | 
|  | 4506 | return nfs4_get_acl_uncached(inode, buf, buflen); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4507 | } | 
|  | 4508 |  | 
| Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4509 | 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] | 4510 | { | 
|  | 4511 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 4512 | struct page *pages[NFS4ACL_MAXPAGES]; | 
|  | 4513 | struct nfs_setaclargs arg = { | 
|  | 4514 | .fh		= NFS_FH(inode), | 
|  | 4515 | .acl_pages	= pages, | 
|  | 4516 | .acl_len	= buflen, | 
|  | 4517 | }; | 
| Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4518 | struct nfs_setaclres res; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4519 | struct rpc_message msg = { | 
|  | 4520 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETACL], | 
|  | 4521 | .rpc_argp	= &arg, | 
| Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4522 | .rpc_resp	= &res, | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4523 | }; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4524 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4525 | int ret, i; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4526 |  | 
|  | 4527 | if (!nfs4_server_supports_acls(server)) | 
|  | 4528 | return -EOPNOTSUPP; | 
| Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4529 | if (npages > ARRAY_SIZE(pages)) | 
|  | 4530 | return -ERANGE; | 
| Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4531 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); | 
|  | 4532 | if (i < 0) | 
|  | 4533 | return i; | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4534 | nfs4_inode_return_delegation(inode); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4535 | 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] | 4536 |  | 
|  | 4537 | /* | 
|  | 4538 | * Free each page after tx, so the only ref left is | 
|  | 4539 | * held by the network stack | 
|  | 4540 | */ | 
|  | 4541 | for (; i > 0; i--) | 
|  | 4542 | put_page(pages[i-1]); | 
|  | 4543 |  | 
| Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4544 | /* | 
|  | 4545 | * Acl update can result in inode attribute update. | 
|  | 4546 | * so mark the attribute cache invalid. | 
|  | 4547 | */ | 
|  | 4548 | spin_lock(&inode->i_lock); | 
|  | 4549 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; | 
|  | 4550 | spin_unlock(&inode->i_lock); | 
| Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4551 | nfs_access_zap_cache(inode); | 
|  | 4552 | nfs_zap_acl_cache(inode); | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4553 | return ret; | 
|  | 4554 | } | 
|  | 4555 |  | 
| Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4556 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) | 
|  | 4557 | { | 
|  | 4558 | struct nfs4_exception exception = { }; | 
|  | 4559 | int err; | 
|  | 4560 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4561 | err = __nfs4_proc_set_acl(inode, buf, buflen); | 
|  | 4562 | trace_nfs4_set_acl(inode, err); | 
|  | 4563 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4564 | &exception); | 
|  | 4565 | } while (exception.retry); | 
|  | 4566 | return err; | 
|  | 4567 | } | 
|  | 4568 |  | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4569 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 4570 | static int _nfs4_get_security_label(struct inode *inode, void *buf, | 
|  | 4571 | size_t buflen) | 
|  | 4572 | { | 
|  | 4573 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 4574 | struct nfs_fattr fattr; | 
|  | 4575 | struct nfs4_label label = {0, 0, buflen, buf}; | 
|  | 4576 |  | 
|  | 4577 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; | 
|  | 4578 | struct nfs4_getattr_arg args = { | 
|  | 4579 | .fh		= NFS_FH(inode), | 
|  | 4580 | .bitmask	= bitmask, | 
|  | 4581 | }; | 
|  | 4582 | struct nfs4_getattr_res res = { | 
|  | 4583 | .fattr		= &fattr, | 
|  | 4584 | .label		= &label, | 
|  | 4585 | .server		= server, | 
|  | 4586 | }; | 
|  | 4587 | struct rpc_message msg = { | 
|  | 4588 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_GETATTR], | 
|  | 4589 | .rpc_argp	= &args, | 
|  | 4590 | .rpc_resp	= &res, | 
|  | 4591 | }; | 
|  | 4592 | int ret; | 
|  | 4593 |  | 
|  | 4594 | nfs_fattr_init(&fattr); | 
|  | 4595 |  | 
|  | 4596 | ret = rpc_call_sync(server->client, &msg, 0); | 
|  | 4597 | if (ret) | 
|  | 4598 | return ret; | 
|  | 4599 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) | 
|  | 4600 | return -ENOENT; | 
|  | 4601 | if (buflen < label.len) | 
|  | 4602 | return -ERANGE; | 
|  | 4603 | return 0; | 
|  | 4604 | } | 
|  | 4605 |  | 
|  | 4606 | static int nfs4_get_security_label(struct inode *inode, void *buf, | 
|  | 4607 | size_t buflen) | 
|  | 4608 | { | 
|  | 4609 | struct nfs4_exception exception = { }; | 
|  | 4610 | int err; | 
|  | 4611 |  | 
|  | 4612 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) | 
|  | 4613 | return -EOPNOTSUPP; | 
|  | 4614 |  | 
|  | 4615 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4616 | err = _nfs4_get_security_label(inode, buf, buflen); | 
|  | 4617 | trace_nfs4_get_security_label(inode, err); | 
|  | 4618 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4619 | &exception); | 
|  | 4620 | } while (exception.retry); | 
|  | 4621 | return err; | 
|  | 4622 | } | 
|  | 4623 |  | 
|  | 4624 | static int _nfs4_do_set_security_label(struct inode *inode, | 
|  | 4625 | struct nfs4_label *ilabel, | 
|  | 4626 | struct nfs_fattr *fattr, | 
|  | 4627 | struct nfs4_label *olabel) | 
|  | 4628 | { | 
|  | 4629 |  | 
|  | 4630 | struct iattr sattr = {0}; | 
|  | 4631 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 4632 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; | 
|  | 4633 | struct nfs_setattrargs args = { | 
|  | 4634 | .fh             = NFS_FH(inode), | 
|  | 4635 | .iap            = &sattr, | 
|  | 4636 | .server		= server, | 
|  | 4637 | .bitmask	= bitmask, | 
|  | 4638 | .label		= ilabel, | 
|  | 4639 | }; | 
|  | 4640 | struct nfs_setattrres res = { | 
|  | 4641 | .fattr		= fattr, | 
|  | 4642 | .label		= olabel, | 
|  | 4643 | .server		= server, | 
|  | 4644 | }; | 
|  | 4645 | struct rpc_message msg = { | 
|  | 4646 | .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], | 
|  | 4647 | .rpc_argp       = &args, | 
|  | 4648 | .rpc_resp       = &res, | 
|  | 4649 | }; | 
|  | 4650 | int status; | 
|  | 4651 |  | 
|  | 4652 | nfs4_stateid_copy(&args.stateid, &zero_stateid); | 
|  | 4653 |  | 
|  | 4654 | status = rpc_call_sync(server->client, &msg, 0); | 
|  | 4655 | if (status) | 
|  | 4656 | dprintk("%s failed: %d\n", __func__, status); | 
|  | 4657 |  | 
|  | 4658 | return status; | 
|  | 4659 | } | 
|  | 4660 |  | 
|  | 4661 | static int nfs4_do_set_security_label(struct inode *inode, | 
|  | 4662 | struct nfs4_label *ilabel, | 
|  | 4663 | struct nfs_fattr *fattr, | 
|  | 4664 | struct nfs4_label *olabel) | 
|  | 4665 | { | 
|  | 4666 | struct nfs4_exception exception = { }; | 
|  | 4667 | int err; | 
|  | 4668 |  | 
|  | 4669 | do { | 
| Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4670 | err = _nfs4_do_set_security_label(inode, ilabel, | 
|  | 4671 | fattr, olabel); | 
|  | 4672 | trace_nfs4_set_security_label(inode, err); | 
|  | 4673 | err = nfs4_handle_exception(NFS_SERVER(inode), err, | 
| David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4674 | &exception); | 
|  | 4675 | } while (exception.retry); | 
|  | 4676 | return err; | 
|  | 4677 | } | 
|  | 4678 |  | 
|  | 4679 | static int | 
|  | 4680 | nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen) | 
|  | 4681 | { | 
|  | 4682 | struct nfs4_label ilabel, *olabel = NULL; | 
|  | 4683 | struct nfs_fattr fattr; | 
|  | 4684 | struct rpc_cred *cred; | 
|  | 4685 | struct inode *inode = dentry->d_inode; | 
|  | 4686 | int status; | 
|  | 4687 |  | 
|  | 4688 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) | 
|  | 4689 | return -EOPNOTSUPP; | 
|  | 4690 |  | 
|  | 4691 | nfs_fattr_init(&fattr); | 
|  | 4692 |  | 
|  | 4693 | ilabel.pi = 0; | 
|  | 4694 | ilabel.lfs = 0; | 
|  | 4695 | ilabel.label = (char *)buf; | 
|  | 4696 | ilabel.len = buflen; | 
|  | 4697 |  | 
|  | 4698 | cred = rpc_lookup_cred(); | 
|  | 4699 | if (IS_ERR(cred)) | 
|  | 4700 | return PTR_ERR(cred); | 
|  | 4701 |  | 
|  | 4702 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); | 
|  | 4703 | if (IS_ERR(olabel)) { | 
|  | 4704 | status = -PTR_ERR(olabel); | 
|  | 4705 | goto out; | 
|  | 4706 | } | 
|  | 4707 |  | 
|  | 4708 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); | 
|  | 4709 | if (status == 0) | 
|  | 4710 | nfs_setsecurity(inode, &fattr, olabel); | 
|  | 4711 |  | 
|  | 4712 | nfs4_label_free(olabel); | 
|  | 4713 | out: | 
|  | 4714 | put_rpccred(cred); | 
|  | 4715 | return status; | 
|  | 4716 | } | 
|  | 4717 | #endif	/* CONFIG_NFS_V4_SECURITY_LABEL */ | 
|  | 4718 |  | 
|  | 4719 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | static int | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4721 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | { | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4723 | struct nfs_client *clp = server->nfs_client; | 
|  | 4724 |  | 
|  | 4725 | if (task->tk_status >= 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | return 0; | 
|  | 4727 | switch(task->tk_status) { | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4728 | case -NFS4ERR_DELEG_REVOKED: | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4729 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 4730 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4731 | if (state == NULL) | 
|  | 4732 | break; | 
|  | 4733 | nfs_remove_bad_delegation(state->inode); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4734 | case -NFS4ERR_OPENMODE: | 
|  | 4735 | if (state == NULL) | 
|  | 4736 | break; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4737 | if (nfs4_schedule_stateid_recovery(server, state) < 0) | 
|  | 4738 | goto stateid_invalid; | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4739 | goto wait_on_recovery; | 
| Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4740 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4741 | if (state != NULL) { | 
|  | 4742 | if (nfs4_schedule_stateid_recovery(server, state) < 0) | 
|  | 4743 | goto stateid_invalid; | 
|  | 4744 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4746 | case -NFS4ERR_STALE_CLIENTID: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4747 | nfs4_schedule_lease_recovery(clp); | 
|  | 4748 | goto wait_on_recovery; | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4749 | #if defined(CONFIG_NFS_V4_1) | 
|  | 4750 | case -NFS4ERR_BADSESSION: | 
|  | 4751 | case -NFS4ERR_BADSLOT: | 
|  | 4752 | case -NFS4ERR_BAD_HIGH_SLOT: | 
|  | 4753 | case -NFS4ERR_DEADSESSION: | 
|  | 4754 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
|  | 4755 | case -NFS4ERR_SEQ_FALSE_RETRY: | 
|  | 4756 | case -NFS4ERR_SEQ_MISORDERED: | 
|  | 4757 | dprintk("%s ERROR %d, Reset session\n", __func__, | 
|  | 4758 | task->tk_status); | 
| Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4759 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4760 | task->tk_status = 0; | 
|  | 4761 | return -EAGAIN; | 
|  | 4762 | #endif /* CONFIG_NFS_V4_1 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4764 | nfs_inc_server_stats(server, NFSIOS_DELAY); | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4765 | case -NFS4ERR_GRACE: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
|  | 4767 | task->tk_status = 0; | 
|  | 4768 | return -EAGAIN; | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4769 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | case -NFS4ERR_OLD_STATEID: | 
|  | 4771 | task->tk_status = 0; | 
|  | 4772 | return -EAGAIN; | 
|  | 4773 | } | 
|  | 4774 | task->tk_status = nfs4_map_errors(task->tk_status); | 
|  | 4775 | return 0; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4776 | stateid_invalid: | 
|  | 4777 | task->tk_status = -EIO; | 
|  | 4778 | return 0; | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4779 | wait_on_recovery: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4780 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4781 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) | 
|  | 4782 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); | 
|  | 4783 | task->tk_status = 0; | 
|  | 4784 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | } | 
|  | 4786 |  | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4787 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, | 
|  | 4788 | nfs4_verifier *bootverf) | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4789 | { | 
|  | 4790 | __be32 verf[2]; | 
|  | 4791 |  | 
| Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4792 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { | 
|  | 4793 | /* An impossible timestamp guarantees this value | 
|  | 4794 | * will never match a generated boot time. */ | 
|  | 4795 | verf[0] = 0; | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4796 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); | 
| Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4797 | } else { | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4798 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 4799 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); | 
|  | 4800 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); | 
| Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4801 | } | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4802 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); | 
|  | 4803 | } | 
|  | 4804 |  | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4805 | static unsigned int | 
|  | 4806 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, | 
|  | 4807 | char *buf, size_t len) | 
|  | 4808 | { | 
|  | 4809 | unsigned int result; | 
|  | 4810 |  | 
|  | 4811 | rcu_read_lock(); | 
|  | 4812 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", | 
|  | 4813 | clp->cl_ipaddr, | 
|  | 4814 | rpc_peeraddr2str(clp->cl_rpcclient, | 
|  | 4815 | RPC_DISPLAY_ADDR), | 
|  | 4816 | rpc_peeraddr2str(clp->cl_rpcclient, | 
|  | 4817 | RPC_DISPLAY_PROTO)); | 
|  | 4818 | rcu_read_unlock(); | 
|  | 4819 | return result; | 
|  | 4820 | } | 
|  | 4821 |  | 
|  | 4822 | static unsigned int | 
|  | 4823 | nfs4_init_uniform_client_string(const struct nfs_client *clp, | 
|  | 4824 | char *buf, size_t len) | 
|  | 4825 | { | 
| Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4826 | const char *nodename = clp->cl_rpcclient->cl_nodename; | 
| Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4827 |  | 
|  | 4828 | if (nfs4_client_id_uniquifier[0] != '\0') | 
| Trond Myklebust | 55b5929 | 2013-07-24 16:36:35 -0400 | [diff] [blame] | 4829 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", | 
|  | 4830 | clp->rpc_ops->version, | 
|  | 4831 | clp->cl_minorversion, | 
|  | 4832 | nfs4_client_id_uniquifier, | 
|  | 4833 | nodename); | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4834 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", | 
|  | 4835 | clp->rpc_ops->version, clp->cl_minorversion, | 
| Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4836 | nodename); | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4837 | } | 
|  | 4838 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4839 | /** | 
|  | 4840 | * nfs4_proc_setclientid - Negotiate client ID | 
|  | 4841 | * @clp: state data structure | 
|  | 4842 | * @program: RPC program for NFSv4 callback service | 
|  | 4843 | * @port: IP port number for NFS4 callback service | 
|  | 4844 | * @cred: RPC credential to use for this call | 
|  | 4845 | * @res: where to place the result | 
|  | 4846 | * | 
|  | 4847 | * Returns zero, a negative errno, or a negative NFS4ERR status code. | 
|  | 4848 | */ | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4849 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, | 
|  | 4850 | unsigned short port, struct rpc_cred *cred, | 
|  | 4851 | struct nfs4_setclientid_res *res) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | { | 
|  | 4853 | nfs4_verifier sc_verifier; | 
|  | 4854 | struct nfs4_setclientid setclientid = { | 
|  | 4855 | .sc_verifier = &sc_verifier, | 
|  | 4856 | .sc_prog = program, | 
| Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4857 | .sc_cb_ident = clp->cl_cb_ident, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | }; | 
|  | 4859 | struct rpc_message msg = { | 
|  | 4860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], | 
|  | 4861 | .rpc_argp = &setclientid, | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4862 | .rpc_resp = res, | 
| Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4863 | .rpc_cred = cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | }; | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4865 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 |  | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4867 | /* nfs_client_id4 */ | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4868 | nfs4_init_boot_verifier(clp, &sc_verifier); | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4869 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) | 
|  | 4870 | setclientid.sc_name_len = | 
|  | 4871 | nfs4_init_uniform_client_string(clp, | 
|  | 4872 | setclientid.sc_name, | 
|  | 4873 | sizeof(setclientid.sc_name)); | 
|  | 4874 | else | 
|  | 4875 | setclientid.sc_name_len = | 
|  | 4876 | nfs4_init_nonuniform_client_string(clp, | 
|  | 4877 | setclientid.sc_name, | 
|  | 4878 | sizeof(setclientid.sc_name)); | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4879 | /* cb_client4 */ | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4880 | rcu_read_lock(); | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4881 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, | 
| Djalal Harouni | fe2d539 | 2013-06-18 17:58:12 +0100 | [diff] [blame] | 4882 | sizeof(setclientid.sc_netid), "%s", | 
| Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4883 | rpc_peeraddr2str(clp->cl_rpcclient, | 
|  | 4884 | RPC_DISPLAY_NETID)); | 
| Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4885 | rcu_read_unlock(); | 
|  | 4886 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, | 
| Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4887 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | clp->cl_ipaddr, port >> 8, port & 255); | 
|  | 4889 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4890 | dprintk("NFS call  setclientid auth=%s, '%.*s'\n", | 
|  | 4891 | clp->cl_rpcclient->cl_auth->au_ops->au_name, | 
|  | 4892 | setclientid.sc_name_len, setclientid.sc_name); | 
|  | 4893 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4894 | trace_nfs4_setclientid(clp, status); | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4895 | dprintk("NFS reply setclientid: %d\n", status); | 
|  | 4896 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } | 
|  | 4898 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4899 | /** | 
|  | 4900 | * nfs4_proc_setclientid_confirm - Confirm client ID | 
|  | 4901 | * @clp: state data structure | 
|  | 4902 | * @res: result of a previous SETCLIENTID | 
|  | 4903 | * @cred: RPC credential to use for this call | 
|  | 4904 | * | 
|  | 4905 | * Returns zero, a negative errno, or a negative NFS4ERR status code. | 
|  | 4906 | */ | 
| Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4907 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4908 | struct nfs4_setclientid_res *arg, | 
|  | 4909 | struct rpc_cred *cred) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | struct rpc_message msg = { | 
|  | 4912 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4913 | .rpc_argp = arg, | 
| Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4914 | .rpc_cred = cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | int status; | 
|  | 4917 |  | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4918 | dprintk("NFS call  setclientid_confirm auth=%s, (client ID %llx)\n", | 
|  | 4919 | clp->cl_rpcclient->cl_auth->au_ops->au_name, | 
|  | 4920 | clp->cl_clientid); | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4921 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4922 | trace_nfs4_setclientid_confirm(clp, status); | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4923 | dprintk("NFS reply setclientid_confirm: %d\n", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | return status; | 
|  | 4925 | } | 
|  | 4926 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4927 | struct nfs4_delegreturndata { | 
|  | 4928 | struct nfs4_delegreturnargs args; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4929 | struct nfs4_delegreturnres res; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4930 | struct nfs_fh fh; | 
|  | 4931 | nfs4_stateid stateid; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4932 | unsigned long timestamp; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4933 | struct nfs_fattr fattr; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4934 | int rpc_status; | 
|  | 4935 | }; | 
|  | 4936 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4937 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) | 
|  | 4938 | { | 
|  | 4939 | struct nfs4_delegreturndata *data = calldata; | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4940 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4941 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 4942 | return; | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4943 |  | 
| Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 4944 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4945 | switch (task->tk_status) { | 
|  | 4946 | case -NFS4ERR_STALE_STATEID: | 
|  | 4947 | case -NFS4ERR_EXPIRED: | 
|  | 4948 | case 0: | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4949 | renew_lease(data->res.server, data->timestamp); | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4950 | break; | 
|  | 4951 | default: | 
|  | 4952 | if (nfs4_async_handle_error(task, data->res.server, NULL) == | 
|  | 4953 | -EAGAIN) { | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4954 | rpc_restart_call_prepare(task); | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4955 | return; | 
|  | 4956 | } | 
|  | 4957 | } | 
|  | 4958 | data->rpc_status = task->tk_status; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4959 | } | 
|  | 4960 |  | 
|  | 4961 | static void nfs4_delegreturn_release(void *calldata) | 
|  | 4962 | { | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4963 | kfree(calldata); | 
|  | 4964 | } | 
|  | 4965 |  | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4966 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) | 
|  | 4967 | { | 
|  | 4968 | struct nfs4_delegreturndata *d_data; | 
|  | 4969 |  | 
|  | 4970 | d_data = (struct nfs4_delegreturndata *)data; | 
|  | 4971 |  | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4972 | nfs4_setup_sequence(d_data->res.server, | 
|  | 4973 | &d_data->args.seq_args, | 
|  | 4974 | &d_data->res.seq_res, | 
|  | 4975 | task); | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4976 | } | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4977 |  | 
| Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4978 | static const struct rpc_call_ops nfs4_delegreturn_ops = { | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4979 | .rpc_call_prepare = nfs4_delegreturn_prepare, | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4980 | .rpc_call_done = nfs4_delegreturn_done, | 
|  | 4981 | .rpc_release = nfs4_delegreturn_release, | 
|  | 4982 | }; | 
|  | 4983 |  | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4984 | 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] | 4985 | { | 
|  | 4986 | struct nfs4_delegreturndata *data; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4987 | struct nfs_server *server = NFS_SERVER(inode); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4988 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4989 | struct rpc_message msg = { | 
|  | 4990 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], | 
|  | 4991 | .rpc_cred = cred, | 
|  | 4992 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4993 | struct rpc_task_setup task_setup_data = { | 
|  | 4994 | .rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4995 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4996 | .callback_ops = &nfs4_delegreturn_ops, | 
|  | 4997 | .flags = RPC_TASK_ASYNC, | 
|  | 4998 | }; | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4999 | int status = 0; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5000 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5001 | data = kzalloc(sizeof(*data), GFP_NOFS); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5002 | if (data == NULL) | 
|  | 5003 | return -ENOMEM; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5004 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5005 | data->args.fhandle = &data->fh; | 
|  | 5006 | data->args.stateid = &data->stateid; | 
| Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5007 | data->args.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5008 | nfs_copy_fh(&data->fh, NFS_FH(inode)); | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5009 | nfs4_stateid_copy(&data->stateid, stateid); | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5010 | data->res.fattr = &data->fattr; | 
|  | 5011 | data->res.server = server; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5012 | nfs_fattr_init(data->res.fattr); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5013 | data->timestamp = jiffies; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5014 | data->rpc_status = 0; | 
|  | 5015 |  | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5016 | task_setup_data.callback_data = data; | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5017 | msg.rpc_argp = &data->args; | 
|  | 5018 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5019 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5020 | if (IS_ERR(task)) | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5021 | return PTR_ERR(task); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5022 | if (!issync) | 
|  | 5023 | goto out; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5024 | status = nfs4_wait_for_completion_rpc_task(task); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5025 | if (status != 0) | 
|  | 5026 | goto out; | 
|  | 5027 | status = data->rpc_status; | 
| Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5028 | if (status == 0) | 
|  | 5029 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); | 
|  | 5030 | else | 
|  | 5031 | nfs_refresh_inode(inode, &data->fattr); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5032 | out: | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5033 | rpc_put_task(task); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5034 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | } | 
|  | 5036 |  | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5037 | 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] | 5038 | { | 
|  | 5039 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 5040 | struct nfs4_exception exception = { }; | 
|  | 5041 | int err; | 
|  | 5042 | do { | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5043 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); | 
| Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5044 | trace_nfs4_delegreturn(inode, err); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | switch (err) { | 
|  | 5046 | case -NFS4ERR_STALE_STATEID: | 
|  | 5047 | case -NFS4ERR_EXPIRED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | case 0: | 
|  | 5049 | return 0; | 
|  | 5050 | } | 
|  | 5051 | err = nfs4_handle_exception(server, err, &exception); | 
|  | 5052 | } while (exception.retry); | 
|  | 5053 | return err; | 
|  | 5054 | } | 
|  | 5055 |  | 
|  | 5056 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) | 
|  | 5057 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) | 
|  | 5058 |  | 
|  | 5059 | /* | 
|  | 5060 | * sleep, with exponential backoff, and retry the LOCK operation. | 
|  | 5061 | */ | 
|  | 5062 | static unsigned long | 
|  | 5063 | nfs4_set_lock_task_retry(unsigned long timeout) | 
|  | 5064 | { | 
| Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 5065 | freezable_schedule_timeout_killable_unsafe(timeout); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | timeout <<= 1; | 
|  | 5067 | if (timeout > NFS4_LOCK_MAXTIMEOUT) | 
|  | 5068 | return NFS4_LOCK_MAXTIMEOUT; | 
|  | 5069 | return timeout; | 
|  | 5070 | } | 
|  | 5071 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 5073 | { | 
|  | 5074 | struct inode *inode = state->inode; | 
|  | 5075 | struct nfs_server *server = NFS_SERVER(inode); | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5076 | struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5077 | struct nfs_lockt_args arg = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5078 | .fh = NFS_FH(inode), | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5079 | .fl = request, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | }; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5081 | struct nfs_lockt_res res = { | 
|  | 5082 | .denied = request, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | }; | 
|  | 5084 | struct rpc_message msg = { | 
|  | 5085 | .rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_LOCKT], | 
|  | 5086 | .rpc_argp       = &arg, | 
|  | 5087 | .rpc_resp       = &res, | 
|  | 5088 | .rpc_cred	= state->owner->so_cred, | 
|  | 5089 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | struct nfs4_lock_state *lsp; | 
|  | 5091 | int status; | 
|  | 5092 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5093 | arg.lock_owner.clientid = clp->cl_clientid; | 
| Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5094 | status = nfs4_set_lock_state(state, request); | 
|  | 5095 | if (status != 0) | 
|  | 5096 | goto out; | 
|  | 5097 | lsp = request->fl_u.nfs4_fl.owner; | 
| Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5098 | arg.lock_owner.id = lsp->ls_seqid.owner_id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5099 | arg.lock_owner.s_dev = server->s_dev; | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5100 | 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] | 5101 | switch (status) { | 
|  | 5102 | case 0: | 
|  | 5103 | request->fl_type = F_UNLCK; | 
|  | 5104 | break; | 
|  | 5105 | case -NFS4ERR_DENIED: | 
|  | 5106 | status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5107 | } | 
| J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5108 | request->fl_ops->fl_release_private(request); | 
| Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5109 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | return status; | 
|  | 5111 | } | 
|  | 5112 |  | 
|  | 5113 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 5114 | { | 
|  | 5115 | struct nfs4_exception exception = { }; | 
|  | 5116 | int err; | 
|  | 5117 |  | 
|  | 5118 | do { | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5119 | err = _nfs4_proc_getlk(state, cmd, request); | 
|  | 5120 | trace_nfs4_get_lock(request, state, cmd, err); | 
|  | 5121 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | &exception); | 
|  | 5123 | } while (exception.retry); | 
|  | 5124 | return err; | 
|  | 5125 | } | 
|  | 5126 |  | 
|  | 5127 | static int do_vfs_lock(struct file *file, struct file_lock *fl) | 
|  | 5128 | { | 
|  | 5129 | int res = 0; | 
|  | 5130 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { | 
|  | 5131 | case FL_POSIX: | 
|  | 5132 | res = posix_lock_file_wait(file, fl); | 
|  | 5133 | break; | 
|  | 5134 | case FL_FLOCK: | 
|  | 5135 | res = flock_lock_file_wait(file, fl); | 
|  | 5136 | break; | 
|  | 5137 | default: | 
|  | 5138 | BUG(); | 
|  | 5139 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | return res; | 
|  | 5141 | } | 
|  | 5142 |  | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5143 | struct nfs4_unlockdata { | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5144 | struct nfs_locku_args arg; | 
|  | 5145 | struct nfs_locku_res res; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5146 | struct nfs4_lock_state *lsp; | 
|  | 5147 | struct nfs_open_context *ctx; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5148 | struct file_lock fl; | 
|  | 5149 | const struct nfs_server *server; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5150 | unsigned long timestamp; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5151 | }; | 
|  | 5152 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5153 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, | 
|  | 5154 | struct nfs_open_context *ctx, | 
|  | 5155 | struct nfs4_lock_state *lsp, | 
|  | 5156 | struct nfs_seqid *seqid) | 
|  | 5157 | { | 
|  | 5158 | struct nfs4_unlockdata *p; | 
|  | 5159 | struct inode *inode = lsp->ls_state->inode; | 
|  | 5160 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5161 | p = kzalloc(sizeof(*p), GFP_NOFS); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5162 | if (p == NULL) | 
|  | 5163 | return NULL; | 
|  | 5164 | p->arg.fh = NFS_FH(inode); | 
|  | 5165 | p->arg.fl = &p->fl; | 
|  | 5166 | p->arg.seqid = seqid; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5167 | p->res.seqid = seqid; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5168 | p->arg.stateid = &lsp->ls_stateid; | 
|  | 5169 | p->lsp = lsp; | 
|  | 5170 | atomic_inc(&lsp->ls_count); | 
|  | 5171 | /* Ensure we don't close file until we're done freeing locks! */ | 
|  | 5172 | p->ctx = get_nfs_open_context(ctx); | 
|  | 5173 | memcpy(&p->fl, fl, sizeof(p->fl)); | 
|  | 5174 | p->server = NFS_SERVER(inode); | 
|  | 5175 | return p; | 
|  | 5176 | } | 
|  | 5177 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5178 | static void nfs4_locku_release_calldata(void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5179 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5180 | struct nfs4_unlockdata *calldata = data; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5181 | nfs_free_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5182 | nfs4_put_lock_state(calldata->lsp); | 
|  | 5183 | put_nfs_open_context(calldata->ctx); | 
|  | 5184 | kfree(calldata); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5185 | } | 
|  | 5186 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5187 | static void nfs4_locku_done(struct rpc_task *task, void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5188 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5189 | struct nfs4_unlockdata *calldata = data; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5190 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5191 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) | 
|  | 5192 | return; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5193 | switch (task->tk_status) { | 
|  | 5194 | case 0: | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5195 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, | 
|  | 5196 | &calldata->res.stateid); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5197 | renew_lease(calldata->server, calldata->timestamp); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5198 | break; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5199 | case -NFS4ERR_BAD_STATEID: | 
|  | 5200 | case -NFS4ERR_OLD_STATEID: | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5201 | case -NFS4ERR_STALE_STATEID: | 
|  | 5202 | case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5203 | break; | 
|  | 5204 | default: | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5205 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5206 | rpc_restart_call_prepare(task); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5207 | } | 
| Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5208 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5209 | } | 
|  | 5210 |  | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5211 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5212 | { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5213 | struct nfs4_unlockdata *calldata = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5215 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5216 | goto out_wait; | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5217 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5218 | /* Note: exit _without_ running nfs4_locku_done */ | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5219 | goto out_no_action; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5220 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5221 | calldata->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5222 | if (nfs4_setup_sequence(calldata->server, | 
| Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5223 | &calldata->arg.seq_args, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5224 | &calldata->res.seq_res, | 
|  | 5225 | task) != 0) | 
|  | 5226 | nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5227 | return; | 
|  | 5228 | out_no_action: | 
|  | 5229 | task->tk_action = NULL; | 
|  | 5230 | out_wait: | 
|  | 5231 | nfs4_sequence_done(task, &calldata->res.seq_res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | } | 
|  | 5233 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5234 | static const struct rpc_call_ops nfs4_locku_ops = { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5235 | .rpc_call_prepare = nfs4_locku_prepare, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5236 | .rpc_call_done = nfs4_locku_done, | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5237 | .rpc_release = nfs4_locku_release_calldata, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5238 | }; | 
|  | 5239 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5240 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, | 
|  | 5241 | struct nfs_open_context *ctx, | 
|  | 5242 | struct nfs4_lock_state *lsp, | 
|  | 5243 | struct nfs_seqid *seqid) | 
|  | 5244 | { | 
|  | 5245 | struct nfs4_unlockdata *data; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5246 | struct rpc_message msg = { | 
|  | 5247 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], | 
|  | 5248 | .rpc_cred = ctx->cred, | 
|  | 5249 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5250 | struct rpc_task_setup task_setup_data = { | 
|  | 5251 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5252 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5253 | .callback_ops = &nfs4_locku_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5254 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5255 | .flags = RPC_TASK_ASYNC, | 
|  | 5256 | }; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5257 |  | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5258 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, | 
|  | 5259 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); | 
|  | 5260 |  | 
| Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5261 | /* Ensure this is an unlock - when canceling a lock, the | 
|  | 5262 | * canceled lock is passed in, and it won't be an unlock. | 
|  | 5263 | */ | 
|  | 5264 | fl->fl_type = F_UNLCK; | 
|  | 5265 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5266 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); | 
|  | 5267 | if (data == NULL) { | 
|  | 5268 | nfs_free_seqid(seqid); | 
|  | 5269 | return ERR_PTR(-ENOMEM); | 
|  | 5270 | } | 
|  | 5271 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5272 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5273 | msg.rpc_argp = &data->arg; | 
|  | 5274 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5275 | task_setup_data.callback_data = data; | 
|  | 5276 | return rpc_run_task(&task_setup_data); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5277 | } | 
|  | 5278 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 5280 | { | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5281 | struct inode *inode = state->inode; | 
|  | 5282 | struct nfs4_state_owner *sp = state->owner; | 
|  | 5283 | struct nfs_inode *nfsi = NFS_I(inode); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5284 | struct nfs_seqid *seqid; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5285 | struct nfs4_lock_state *lsp; | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5286 | struct rpc_task *task; | 
|  | 5287 | int status = 0; | 
| Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5288 | unsigned char fl_flags = request->fl_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 |  | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5290 | status = nfs4_set_lock_state(state, request); | 
|  | 5291 | /* Unlock _before_ we do the RPC call */ | 
|  | 5292 | request->fl_flags |= FL_EXISTS; | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5293 | /* Exclude nfs_delegation_claim_locks() */ | 
|  | 5294 | mutex_lock(&sp->so_delegreturn_mutex); | 
|  | 5295 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5296 | down_read(&nfsi->rwsem); | 
|  | 5297 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { | 
|  | 5298 | up_read(&nfsi->rwsem); | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5299 | mutex_unlock(&sp->so_delegreturn_mutex); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5300 | goto out; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5301 | } | 
|  | 5302 | up_read(&nfsi->rwsem); | 
| Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5303 | mutex_unlock(&sp->so_delegreturn_mutex); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5304 | if (status != 0) | 
|  | 5305 | goto out; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5306 | /* Is this a delegated lock? */ | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5307 | lsp = request->fl_u.nfs4_fl.owner; | 
| Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5308 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) | 
|  | 5309 | goto out; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5310 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5311 | status = -ENOMEM; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5312 | if (seqid == NULL) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5313 | goto out; | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5314 | 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] | 5315 | status = PTR_ERR(task); | 
|  | 5316 | if (IS_ERR(task)) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5317 | goto out; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5318 | status = nfs4_wait_for_completion_rpc_task(task); | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5319 | rpc_put_task(task); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5320 | out: | 
| Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5321 | request->fl_flags = fl_flags; | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5322 | trace_nfs4_unlock(request, state, F_SETLK, status); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5323 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | } | 
|  | 5325 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5326 | struct nfs4_lockdata { | 
|  | 5327 | struct nfs_lock_args arg; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5328 | struct nfs_lock_res res; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5329 | struct nfs4_lock_state *lsp; | 
|  | 5330 | struct nfs_open_context *ctx; | 
|  | 5331 | struct file_lock fl; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5332 | unsigned long timestamp; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5333 | int rpc_status; | 
|  | 5334 | int cancelled; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5335 | struct nfs_server *server; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5336 | }; | 
|  | 5337 |  | 
|  | 5338 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5339 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, | 
|  | 5340 | gfp_t gfp_mask) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5341 | { | 
|  | 5342 | struct nfs4_lockdata *p; | 
|  | 5343 | struct inode *inode = lsp->ls_state->inode; | 
|  | 5344 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 5345 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5346 | p = kzalloc(sizeof(*p), gfp_mask); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5347 | if (p == NULL) | 
|  | 5348 | return NULL; | 
|  | 5349 |  | 
|  | 5350 | p->arg.fh = NFS_FH(inode); | 
|  | 5351 | p->arg.fl = &p->fl; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5352 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5353 | if (p->arg.open_seqid == NULL) | 
|  | 5354 | goto out_free; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5355 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5356 | if (p->arg.lock_seqid == NULL) | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5357 | goto out_free_seqid; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5358 | p->arg.lock_stateid = &lsp->ls_stateid; | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5359 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; | 
| Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5360 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5361 | p->arg.lock_owner.s_dev = server->s_dev; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5362 | p->res.lock_seqid = p->arg.lock_seqid; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5363 | p->lsp = lsp; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5364 | p->server = server; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5365 | atomic_inc(&lsp->ls_count); | 
|  | 5366 | p->ctx = get_nfs_open_context(ctx); | 
|  | 5367 | memcpy(&p->fl, fl, sizeof(p->fl)); | 
|  | 5368 | return p; | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5369 | out_free_seqid: | 
|  | 5370 | nfs_free_seqid(p->arg.open_seqid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5371 | out_free: | 
|  | 5372 | kfree(p); | 
|  | 5373 | return NULL; | 
|  | 5374 | } | 
|  | 5375 |  | 
|  | 5376 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) | 
|  | 5377 | { | 
|  | 5378 | struct nfs4_lockdata *data = calldata; | 
|  | 5379 | struct nfs4_state *state = data->lsp->ls_state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5381 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5382 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5383 | goto out_wait; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5384 | /* Do we need to do an open_to_lock_owner? */ | 
|  | 5385 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5386 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5387 | goto out_release_lock_seqid; | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5388 | } | 
| Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 5389 | data->arg.open_stateid = &state->open_stateid; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5390 | data->arg.new_lock_owner = 1; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5391 | data->res.open_seqid = data->arg.open_seqid; | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5392 | } else | 
|  | 5393 | data->arg.new_lock_owner = 0; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5394 | if (!nfs4_valid_open_stateid(state)) { | 
|  | 5395 | data->rpc_status = -EBADF; | 
|  | 5396 | task->tk_action = NULL; | 
|  | 5397 | goto out_release_open_seqid; | 
|  | 5398 | } | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5399 | data->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5400 | if (nfs4_setup_sequence(data->server, | 
|  | 5401 | &data->arg.seq_args, | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5402 | &data->res.seq_res, | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5403 | task) == 0) | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5404 | return; | 
| Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5405 | out_release_open_seqid: | 
| Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5406 | nfs_release_seqid(data->arg.open_seqid); | 
|  | 5407 | out_release_lock_seqid: | 
|  | 5408 | nfs_release_seqid(data->arg.lock_seqid); | 
| Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5409 | out_wait: | 
|  | 5410 | nfs4_sequence_done(task, &data->res.seq_res); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5411 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5412 | } | 
|  | 5413 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5414 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) | 
|  | 5415 | { | 
|  | 5416 | struct nfs4_lockdata *data = calldata; | 
|  | 5417 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5418 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5419 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5420 | if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
|  | 5421 | return; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5422 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5423 | data->rpc_status = task->tk_status; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5424 | if (data->arg.new_lock_owner != 0) { | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5425 | if (data->rpc_status == 0) | 
|  | 5426 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); | 
|  | 5427 | else | 
|  | 5428 | goto out; | 
|  | 5429 | } | 
|  | 5430 | if (data->rpc_status == 0) { | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5431 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5432 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); | 
| Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 5433 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5434 | } | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5435 | out: | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5436 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5437 | } | 
|  | 5438 |  | 
|  | 5439 | static void nfs4_lock_release(void *calldata) | 
|  | 5440 | { | 
|  | 5441 | struct nfs4_lockdata *data = calldata; | 
|  | 5442 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5443 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5444 | nfs_free_seqid(data->arg.open_seqid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5445 | if (data->cancelled != 0) { | 
|  | 5446 | struct rpc_task *task; | 
|  | 5447 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, | 
|  | 5448 | data->arg.lock_seqid); | 
|  | 5449 | if (!IS_ERR(task)) | 
| Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5450 | rpc_put_task_async(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5451 | dprintk("%s: cancelling lock!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5452 | } else | 
|  | 5453 | nfs_free_seqid(data->arg.lock_seqid); | 
|  | 5454 | nfs4_put_lock_state(data->lsp); | 
|  | 5455 | put_nfs_open_context(data->ctx); | 
|  | 5456 | kfree(data); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5457 | dprintk("%s: done!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5458 | } | 
|  | 5459 |  | 
|  | 5460 | static const struct rpc_call_ops nfs4_lock_ops = { | 
|  | 5461 | .rpc_call_prepare = nfs4_lock_prepare, | 
|  | 5462 | .rpc_call_done = nfs4_lock_done, | 
|  | 5463 | .rpc_release = nfs4_lock_release, | 
|  | 5464 | }; | 
|  | 5465 |  | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5466 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) | 
|  | 5467 | { | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5468 | switch (error) { | 
|  | 5469 | case -NFS4ERR_ADMIN_REVOKED: | 
|  | 5470 | case -NFS4ERR_BAD_STATEID: | 
| Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5471 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5472 | if (new_lock_owner != 0 || | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5473 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) | 
| Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5474 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5475 | break; | 
|  | 5476 | case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5477 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; | 
| Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5478 | case -NFS4ERR_EXPIRED: | 
|  | 5479 | nfs4_schedule_lease_recovery(server->nfs_client); | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5480 | }; | 
|  | 5481 | } | 
|  | 5482 |  | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5483 | 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] | 5484 | { | 
|  | 5485 | struct nfs4_lockdata *data; | 
|  | 5486 | struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5487 | struct rpc_message msg = { | 
|  | 5488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], | 
|  | 5489 | .rpc_cred = state->owner->so_cred, | 
|  | 5490 | }; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5491 | struct rpc_task_setup task_setup_data = { | 
|  | 5492 | .rpc_client = NFS_CLIENT(state->inode), | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5493 | .rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5494 | .callback_ops = &nfs4_lock_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5495 | .workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5496 | .flags = RPC_TASK_ASYNC, | 
|  | 5497 | }; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5498 | int ret; | 
|  | 5499 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5500 | dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5501 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5502 | fl->fl_u.nfs4_fl.owner, | 
|  | 5503 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5504 | if (data == NULL) | 
|  | 5505 | return -ENOMEM; | 
|  | 5506 | if (IS_SETLKW(cmd)) | 
|  | 5507 | data->arg.block = 1; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5508 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5509 | msg.rpc_argp = &data->arg; | 
|  | 5510 | msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5511 | task_setup_data.callback_data = data; | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5512 | if (recovery_type > NFS_LOCK_NEW) { | 
|  | 5513 | if (recovery_type == NFS_LOCK_RECLAIM) | 
|  | 5514 | data->arg.reclaim = NFS_LOCK_RECLAIM; | 
|  | 5515 | nfs4_set_sequence_privileged(&data->arg.seq_args); | 
|  | 5516 | } | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5517 | task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5518 | if (IS_ERR(task)) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5519 | return PTR_ERR(task); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5520 | ret = nfs4_wait_for_completion_rpc_task(task); | 
|  | 5521 | if (ret == 0) { | 
|  | 5522 | ret = data->rpc_status; | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5523 | if (ret) | 
|  | 5524 | nfs4_handle_setlk_error(data->server, data->lsp, | 
|  | 5525 | data->arg.new_lock_owner, ret); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5526 | } else | 
|  | 5527 | data->cancelled = 1; | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5528 | rpc_put_task(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5529 | dprintk("%s: done, ret = %d!\n", __func__, ret); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5530 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | } | 
|  | 5532 |  | 
|  | 5533 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) | 
|  | 5534 | { | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5535 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5536 | struct nfs4_exception exception = { | 
|  | 5537 | .inode = state->inode, | 
|  | 5538 | }; | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5539 | int err; | 
|  | 5540 |  | 
|  | 5541 | do { | 
| Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5542 | /* Cache the lock if possible... */ | 
|  | 5543 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) | 
|  | 5544 | return 0; | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5545 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5546 | trace_nfs4_lock_reclaim(request, state, F_SETLK, err); | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5547 | if (err != -NFS4ERR_DELAY) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5548 | break; | 
|  | 5549 | nfs4_handle_exception(server, err, &exception); | 
|  | 5550 | } while (exception.retry); | 
|  | 5551 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | } | 
|  | 5553 |  | 
|  | 5554 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) | 
|  | 5555 | { | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5556 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5557 | struct nfs4_exception exception = { | 
|  | 5558 | .inode = state->inode, | 
|  | 5559 | }; | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5560 | int err; | 
|  | 5561 |  | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5562 | err = nfs4_set_lock_state(state, request); | 
|  | 5563 | if (err != 0) | 
|  | 5564 | return err; | 
| Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 5565 | if (!recover_lost_locks) { | 
| NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5566 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); | 
|  | 5567 | return 0; | 
|  | 5568 | } | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5569 | do { | 
| Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5570 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) | 
|  | 5571 | return 0; | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5572 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5573 | trace_nfs4_lock_expired(request, state, F_SETLK, err); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5574 | switch (err) { | 
|  | 5575 | default: | 
|  | 5576 | goto out; | 
|  | 5577 | case -NFS4ERR_GRACE: | 
|  | 5578 | case -NFS4ERR_DELAY: | 
|  | 5579 | nfs4_handle_exception(server, err, &exception); | 
|  | 5580 | err = 0; | 
|  | 5581 | } | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5582 | } while (exception.retry); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5583 | out: | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5584 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | } | 
|  | 5586 |  | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5587 | #if defined(CONFIG_NFS_V4_1) | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5588 | /** | 
|  | 5589 | * nfs41_check_expired_locks - possibly free a lock stateid | 
|  | 5590 | * | 
|  | 5591 | * @state: NFSv4 state for an inode | 
|  | 5592 | * | 
|  | 5593 | * Returns NFS_OK if recovery for this stateid is now finished. | 
|  | 5594 | * Otherwise a negative NFS4ERR value is returned. | 
|  | 5595 | */ | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5596 | static int nfs41_check_expired_locks(struct nfs4_state *state) | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5597 | { | 
| Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5598 | int status, ret = -NFS4ERR_BAD_STATEID; | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5599 | struct nfs4_lock_state *lsp; | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5600 | struct nfs_server *server = NFS_SERVER(state->inode); | 
|  | 5601 |  | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5602 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5603 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5604 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; | 
|  | 5605 |  | 
|  | 5606 | status = nfs41_test_stateid(server, | 
|  | 5607 | &lsp->ls_stateid, | 
|  | 5608 | cred); | 
| Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 5609 | trace_nfs4_test_lock_stateid(state, lsp, status); | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5610 | if (status != NFS_OK) { | 
| Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5611 | /* Free the stateid unless the server | 
|  | 5612 | * informs us the stateid is unrecognized. */ | 
| Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5613 | if (status != -NFS4ERR_BAD_STATEID) | 
|  | 5614 | nfs41_free_stateid(server, | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5615 | &lsp->ls_stateid, | 
|  | 5616 | cred); | 
| Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5617 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); | 
| Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5618 | ret = status; | 
|  | 5619 | } | 
|  | 5620 | } | 
|  | 5621 | }; | 
|  | 5622 |  | 
|  | 5623 | return ret; | 
|  | 5624 | } | 
|  | 5625 |  | 
|  | 5626 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) | 
|  | 5627 | { | 
|  | 5628 | int status = NFS_OK; | 
|  | 5629 |  | 
|  | 5630 | if (test_bit(LK_STATE_IN_USE, &state->flags)) | 
|  | 5631 | status = nfs41_check_expired_locks(state); | 
| Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5632 | if (status != NFS_OK) | 
|  | 5633 | status = nfs4_lock_expired(state, request); | 
|  | 5634 | return status; | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5635 | } | 
|  | 5636 | #endif | 
|  | 5637 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 5639 | { | 
| Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5640 | struct nfs4_state_owner *sp = state->owner; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5641 | struct nfs_inode *nfsi = NFS_I(state->inode); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5642 | unsigned char fl_flags = request->fl_flags; | 
| Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5643 | unsigned int seq; | 
| Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5644 | int status = -ENOLCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 |  | 
| Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5646 | if ((fl_flags & FL_POSIX) && | 
|  | 5647 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) | 
|  | 5648 | goto out; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5649 | /* Is this a delegated open? */ | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5650 | status = nfs4_set_lock_state(state, request); | 
|  | 5651 | if (status != 0) | 
|  | 5652 | goto out; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5653 | request->fl_flags |= FL_ACCESS; | 
|  | 5654 | status = do_vfs_lock(request->fl_file, request); | 
|  | 5655 | if (status < 0) | 
|  | 5656 | goto out; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5657 | down_read(&nfsi->rwsem); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5658 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5659 | /* Yes: cache locks! */ | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5660 | /* ...but avoid races with delegation recall... */ | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5661 | request->fl_flags = fl_flags & ~FL_SLEEP; | 
|  | 5662 | status = do_vfs_lock(request->fl_file, request); | 
|  | 5663 | goto out_unlock; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5664 | } | 
| Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5665 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); | 
|  | 5666 | up_read(&nfsi->rwsem); | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5667 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5668 | if (status != 0) | 
| Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5669 | goto out; | 
|  | 5670 | down_read(&nfsi->rwsem); | 
|  | 5671 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { | 
|  | 5672 | status = -NFS4ERR_DELAY; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5673 | goto out_unlock; | 
| Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5674 | } | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5675 | /* Note: we always want to sleep here! */ | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5676 | request->fl_flags = fl_flags | FL_SLEEP; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5677 | if (do_vfs_lock(request->fl_file, request) < 0) | 
| Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5678 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " | 
|  | 5679 | "manager!\n", __func__); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5680 | out_unlock: | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5681 | up_read(&nfsi->rwsem); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5682 | out: | 
|  | 5683 | request->fl_flags = fl_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | return status; | 
|  | 5685 | } | 
|  | 5686 |  | 
|  | 5687 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
|  | 5688 | { | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5689 | struct nfs4_exception exception = { | 
|  | 5690 | .state = state, | 
| Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5691 | .inode = state->inode, | 
| Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5692 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | int err; | 
|  | 5694 |  | 
|  | 5695 | do { | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5696 | err = _nfs4_proc_setlk(state, cmd, request); | 
| Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5697 | trace_nfs4_set_lock(request, state, cmd, err); | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5698 | if (err == -NFS4ERR_DENIED) | 
|  | 5699 | err = -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | err = nfs4_handle_exception(NFS_SERVER(state->inode), | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5701 | err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | } while (exception.retry); | 
|  | 5703 | return err; | 
|  | 5704 | } | 
|  | 5705 |  | 
|  | 5706 | static int | 
|  | 5707 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) | 
|  | 5708 | { | 
|  | 5709 | struct nfs_open_context *ctx; | 
|  | 5710 | struct nfs4_state *state; | 
|  | 5711 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; | 
|  | 5712 | int status; | 
|  | 5713 |  | 
|  | 5714 | /* verify open state */ | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5715 | ctx = nfs_file_open_context(filp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | state = ctx->state; | 
|  | 5717 |  | 
|  | 5718 | if (request->fl_start < 0 || request->fl_end < 0) | 
|  | 5719 | return -EINVAL; | 
|  | 5720 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5721 | if (IS_GETLK(cmd)) { | 
|  | 5722 | if (state != NULL) | 
|  | 5723 | return nfs4_proc_getlk(state, F_GETLK, request); | 
|  | 5724 | return 0; | 
|  | 5725 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5726 |  | 
|  | 5727 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) | 
|  | 5728 | return -EINVAL; | 
|  | 5729 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5730 | if (request->fl_type == F_UNLCK) { | 
|  | 5731 | if (state != NULL) | 
|  | 5732 | return nfs4_proc_unlck(state, cmd, request); | 
|  | 5733 | return 0; | 
|  | 5734 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5736 | if (state == NULL) | 
|  | 5737 | return -ENOLCK; | 
| Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5738 | /* | 
|  | 5739 | * Don't rely on the VFS having checked the file open mode, | 
|  | 5740 | * since it won't do this for flock() locks. | 
|  | 5741 | */ | 
| Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5742 | switch (request->fl_type) { | 
| Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5743 | case F_RDLCK: | 
|  | 5744 | if (!(filp->f_mode & FMODE_READ)) | 
|  | 5745 | return -EBADF; | 
|  | 5746 | break; | 
|  | 5747 | case F_WRLCK: | 
|  | 5748 | if (!(filp->f_mode & FMODE_WRITE)) | 
|  | 5749 | return -EBADF; | 
|  | 5750 | } | 
|  | 5751 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | do { | 
|  | 5753 | status = nfs4_proc_setlk(state, cmd, request); | 
|  | 5754 | if ((status != -EAGAIN) || IS_SETLK(cmd)) | 
|  | 5755 | break; | 
|  | 5756 | timeout = nfs4_set_lock_task_retry(timeout); | 
|  | 5757 | status = -ERESTARTSYS; | 
|  | 5758 | if (signalled()) | 
|  | 5759 | break; | 
|  | 5760 | } while(status < 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5761 | return status; | 
|  | 5762 | } | 
|  | 5763 |  | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5764 | 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] | 5765 | { | 
|  | 5766 | struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5767 | int err; | 
|  | 5768 |  | 
|  | 5769 | err = nfs4_set_lock_state(state, fl); | 
|  | 5770 | if (err != 0) | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5771 | return err; | 
| Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5772 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); | 
| Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5773 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); | 
| Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5774 | } | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5775 |  | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5776 | struct nfs_release_lockowner_data { | 
|  | 5777 | struct nfs4_lock_state *lsp; | 
| Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5778 | struct nfs_server *server; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5779 | struct nfs_release_lockowner_args args; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5780 | struct nfs4_sequence_args seq_args; | 
|  | 5781 | struct nfs4_sequence_res seq_res; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5782 | }; | 
|  | 5783 |  | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5784 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) | 
|  | 5785 | { | 
|  | 5786 | struct nfs_release_lockowner_data *data = calldata; | 
|  | 5787 | nfs40_setup_sequence(data->server, | 
|  | 5788 | &data->seq_args, &data->seq_res, task); | 
|  | 5789 | } | 
|  | 5790 |  | 
|  | 5791 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) | 
|  | 5792 | { | 
|  | 5793 | struct nfs_release_lockowner_data *data = calldata; | 
|  | 5794 | nfs40_sequence_done(task, &data->seq_res); | 
|  | 5795 | } | 
|  | 5796 |  | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5797 | static void nfs4_release_lockowner_release(void *calldata) | 
|  | 5798 | { | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5799 | struct nfs_release_lockowner_data *data = calldata; | 
| Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5800 | nfs4_free_lock_state(data->server, data->lsp); | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5801 | kfree(calldata); | 
|  | 5802 | } | 
|  | 5803 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5804 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5805 | .rpc_call_prepare = nfs4_release_lockowner_prepare, | 
|  | 5806 | .rpc_call_done = nfs4_release_lockowner_done, | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5807 | .rpc_release = nfs4_release_lockowner_release, | 
|  | 5808 | }; | 
|  | 5809 |  | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5810 | static int nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5811 | { | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5812 | struct nfs_release_lockowner_data *data; | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5813 | struct rpc_message msg = { | 
|  | 5814 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], | 
|  | 5815 | }; | 
|  | 5816 |  | 
|  | 5817 | if (server->nfs_client->cl_mvops->minor_version != 0) | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5818 | return -EINVAL; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5819 |  | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5820 | data = kmalloc(sizeof(*data), GFP_NOFS); | 
|  | 5821 | if (!data) | 
|  | 5822 | return -ENOMEM; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5823 | nfs4_init_sequence(&data->seq_args, &data->seq_res, 0); | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5824 | data->lsp = lsp; | 
| Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5825 | data->server = server; | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5826 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; | 
|  | 5827 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; | 
|  | 5828 | data->args.lock_owner.s_dev = server->s_dev; | 
| Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 5829 |  | 
| Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5830 | msg.rpc_argp = &data->args; | 
|  | 5831 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); | 
|  | 5832 | return 0; | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5833 | } | 
|  | 5834 |  | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5835 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" | 
|  | 5836 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5837 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, | 
|  | 5838 | const void *buf, size_t buflen, | 
|  | 5839 | int flags, int type) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5840 | { | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5841 | if (strcmp(key, "") != 0) | 
|  | 5842 | return -EINVAL; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5843 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5844 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5845 | } | 
|  | 5846 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5847 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, | 
|  | 5848 | void *buf, size_t buflen, int type) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5849 | { | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5850 | if (strcmp(key, "") != 0) | 
|  | 5851 | return -EINVAL; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5852 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5853 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5854 | } | 
|  | 5855 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5856 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, | 
|  | 5857 | size_t list_len, const char *name, | 
|  | 5858 | size_t name_len, int type) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5859 | { | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5860 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5861 |  | 
| J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5862 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) | 
|  | 5863 | return 0; | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5864 |  | 
|  | 5865 | if (list && len <= list_len) | 
|  | 5866 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5867 | return len; | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5868 | } | 
|  | 5869 |  | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 5870 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 5871 | static inline int nfs4_server_supports_labels(struct nfs_server *server) | 
|  | 5872 | { | 
|  | 5873 | return server->caps & NFS_CAP_SECURITY_LABEL; | 
|  | 5874 | } | 
|  | 5875 |  | 
|  | 5876 | static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, | 
|  | 5877 | const void *buf, size_t buflen, | 
|  | 5878 | int flags, int type) | 
|  | 5879 | { | 
|  | 5880 | if (security_ismaclabel(key)) | 
|  | 5881 | return nfs4_set_security_label(dentry, buf, buflen); | 
|  | 5882 |  | 
|  | 5883 | return -EOPNOTSUPP; | 
|  | 5884 | } | 
|  | 5885 |  | 
|  | 5886 | static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, | 
|  | 5887 | void *buf, size_t buflen, int type) | 
|  | 5888 | { | 
|  | 5889 | if (security_ismaclabel(key)) | 
|  | 5890 | return nfs4_get_security_label(dentry->d_inode, buf, buflen); | 
|  | 5891 | return -EOPNOTSUPP; | 
|  | 5892 | } | 
|  | 5893 |  | 
|  | 5894 | static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, | 
|  | 5895 | size_t list_len, const char *name, | 
|  | 5896 | size_t name_len, int type) | 
|  | 5897 | { | 
|  | 5898 | size_t len = 0; | 
|  | 5899 |  | 
|  | 5900 | if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) { | 
|  | 5901 | len = security_inode_listsecurity(dentry->d_inode, NULL, 0); | 
|  | 5902 | if (list && len <= list_len) | 
|  | 5903 | security_inode_listsecurity(dentry->d_inode, list, len); | 
|  | 5904 | } | 
|  | 5905 | return len; | 
|  | 5906 | } | 
|  | 5907 |  | 
|  | 5908 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { | 
|  | 5909 | .prefix = XATTR_SECURITY_PREFIX, | 
|  | 5910 | .list	= nfs4_xattr_list_nfs4_label, | 
|  | 5911 | .get	= nfs4_xattr_get_nfs4_label, | 
|  | 5912 | .set	= nfs4_xattr_set_nfs4_label, | 
|  | 5913 | }; | 
|  | 5914 | #endif | 
|  | 5915 |  | 
|  | 5916 |  | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5917 | /* | 
|  | 5918 | * nfs_fhget will use either the mounted_on_fileid or the fileid | 
|  | 5919 | */ | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5920 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) | 
|  | 5921 | { | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5922 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || | 
|  | 5923 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && | 
|  | 5924 | (fattr->valid & NFS_ATTR_FATTR_FSID) && | 
| Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5925 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5926 | return; | 
|  | 5927 |  | 
|  | 5928 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | | 
| Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5929 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5930 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; | 
|  | 5931 | fattr->nlink = 2; | 
|  | 5932 | } | 
|  | 5933 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5934 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, | 
|  | 5935 | const struct qstr *name, | 
|  | 5936 | struct nfs4_fs_locations *fs_locations, | 
|  | 5937 | struct page *page) | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5938 | { | 
|  | 5939 | struct nfs_server *server = NFS_SERVER(dir); | 
| David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 5940 | u32 bitmask[3] = { | 
| Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5941 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5942 | }; | 
|  | 5943 | struct nfs4_fs_locations_arg args = { | 
|  | 5944 | .dir_fh = NFS_FH(dir), | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5945 | .name = name, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5946 | .page = page, | 
|  | 5947 | .bitmask = bitmask, | 
|  | 5948 | }; | 
| Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5949 | struct nfs4_fs_locations_res res = { | 
|  | 5950 | .fs_locations = fs_locations, | 
|  | 5951 | }; | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5952 | struct rpc_message msg = { | 
|  | 5953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], | 
|  | 5954 | .rpc_argp = &args, | 
| Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5955 | .rpc_resp = &res, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5956 | }; | 
|  | 5957 | int status; | 
|  | 5958 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5959 | dprintk("%s: start\n", __func__); | 
| Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5960 |  | 
|  | 5961 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid | 
|  | 5962 | * is not supported */ | 
|  | 5963 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) | 
|  | 5964 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; | 
|  | 5965 | else | 
|  | 5966 | bitmask[0] |= FATTR4_WORD0_FILEID; | 
|  | 5967 |  | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5968 | nfs_fattr_init(&fs_locations->fattr); | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5969 | fs_locations->server = server; | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5970 | fs_locations->nlocations = 0; | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5971 | 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] | 5972 | dprintk("%s: returned status = %d\n", __func__, status); | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5973 | return status; | 
|  | 5974 | } | 
|  | 5975 |  | 
| Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5976 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, | 
|  | 5977 | const struct qstr *name, | 
|  | 5978 | struct nfs4_fs_locations *fs_locations, | 
|  | 5979 | struct page *page) | 
| Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5980 | { | 
|  | 5981 | struct nfs4_exception exception = { }; | 
|  | 5982 | int err; | 
|  | 5983 | do { | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 5984 | err = _nfs4_proc_fs_locations(client, dir, name, | 
|  | 5985 | fs_locations, page); | 
|  | 5986 | trace_nfs4_get_fs_locations(dir, name, err); | 
|  | 5987 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5988 | &exception); | 
|  | 5989 | } while (exception.retry); | 
|  | 5990 | return err; | 
|  | 5991 | } | 
|  | 5992 |  | 
| Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5993 | /** | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 5994 | * If 'use_integrity' is true and the state managment nfs_client | 
|  | 5995 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient | 
|  | 5996 | * and the machine credential as per RFC3530bis and RFC5661 Security | 
|  | 5997 | * Considerations sections. Otherwise, just use the user cred with the | 
|  | 5998 | * filesystem's rpc_client. | 
| Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 5999 | */ | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6000 | 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] | 6001 | { | 
|  | 6002 | int status; | 
|  | 6003 | struct nfs4_secinfo_arg args = { | 
|  | 6004 | .dir_fh = NFS_FH(dir), | 
|  | 6005 | .name   = name, | 
|  | 6006 | }; | 
|  | 6007 | struct nfs4_secinfo_res res = { | 
|  | 6008 | .flavors     = flavors, | 
|  | 6009 | }; | 
|  | 6010 | struct rpc_message msg = { | 
|  | 6011 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], | 
|  | 6012 | .rpc_argp = &args, | 
|  | 6013 | .rpc_resp = &res, | 
|  | 6014 | }; | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6015 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6016 | struct rpc_cred *cred = NULL; | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6017 |  | 
|  | 6018 | if (use_integrity) { | 
|  | 6019 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6020 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); | 
|  | 6021 | msg.rpc_cred = cred; | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6022 | } | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6023 |  | 
|  | 6024 | dprintk("NFS call  secinfo %s\n", name->name); | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6025 |  | 
|  | 6026 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, | 
|  | 6027 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); | 
|  | 6028 |  | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6029 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, | 
|  | 6030 | &res.seq_res, 0); | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6031 | dprintk("NFS reply  secinfo: %d\n", status); | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6032 |  | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6033 | if (cred) | 
|  | 6034 | put_rpccred(cred); | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6035 |  | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6036 | return status; | 
|  | 6037 | } | 
|  | 6038 |  | 
| Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6039 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, | 
|  | 6040 | struct nfs4_secinfo_flavors *flavors) | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6041 | { | 
|  | 6042 | struct nfs4_exception exception = { }; | 
|  | 6043 | int err; | 
|  | 6044 | do { | 
| Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6045 | err = -NFS4ERR_WRONGSEC; | 
|  | 6046 |  | 
|  | 6047 | /* try to use integrity protection with machine cred */ | 
|  | 6048 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) | 
|  | 6049 | err = _nfs4_proc_secinfo(dir, name, flavors, true); | 
|  | 6050 |  | 
|  | 6051 | /* | 
|  | 6052 | * if unable to use integrity protection, or SECINFO with | 
|  | 6053 | * integrity protection returns NFS4ERR_WRONGSEC (which is | 
|  | 6054 | * disallowed by spec, but exists in deployed servers) use | 
|  | 6055 | * the current filesystem's rpc_client and the user cred. | 
|  | 6056 | */ | 
|  | 6057 | if (err == -NFS4ERR_WRONGSEC) | 
|  | 6058 | err = _nfs4_proc_secinfo(dir, name, flavors, false); | 
|  | 6059 |  | 
| Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6060 | trace_nfs4_secinfo(dir, name, err); | 
|  | 6061 | err = nfs4_handle_exception(NFS_SERVER(dir), err, | 
| Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6062 | &exception); | 
|  | 6063 | } while (exception.retry); | 
|  | 6064 | return err; | 
|  | 6065 | } | 
|  | 6066 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6067 | #ifdef CONFIG_NFS_V4_1 | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6068 | /* | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6069 | * Check the exchange flags returned by the server for invalid flags, having | 
|  | 6070 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or | 
|  | 6071 | * DS flags set. | 
|  | 6072 | */ | 
|  | 6073 | static int nfs4_check_cl_exchange_flags(u32 flags) | 
|  | 6074 | { | 
|  | 6075 | if (flags & ~EXCHGID4_FLAG_MASK_R) | 
|  | 6076 | goto out_inval; | 
|  | 6077 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && | 
|  | 6078 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) | 
|  | 6079 | goto out_inval; | 
|  | 6080 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) | 
|  | 6081 | goto out_inval; | 
|  | 6082 | return NFS_OK; | 
|  | 6083 | out_inval: | 
|  | 6084 | return -NFS4ERR_INVAL; | 
|  | 6085 | } | 
|  | 6086 |  | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6087 | static bool | 
| Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6088 | nfs41_same_server_scope(struct nfs41_server_scope *a, | 
|  | 6089 | struct nfs41_server_scope *b) | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6090 | { | 
|  | 6091 | if (a->server_scope_sz == b->server_scope_sz && | 
|  | 6092 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) | 
|  | 6093 | return true; | 
|  | 6094 |  | 
|  | 6095 | return false; | 
|  | 6096 | } | 
|  | 6097 |  | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6098 | /* | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6099 | * nfs4_proc_bind_conn_to_session() | 
|  | 6100 | * | 
|  | 6101 | * The 4.1 client currently uses the same TCP connection for the | 
|  | 6102 | * fore and backchannel. | 
|  | 6103 | */ | 
| Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6104 | 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] | 6105 | { | 
|  | 6106 | int status; | 
|  | 6107 | struct nfs41_bind_conn_to_session_res res; | 
|  | 6108 | struct rpc_message msg = { | 
|  | 6109 | .rpc_proc = | 
|  | 6110 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], | 
|  | 6111 | .rpc_argp = clp, | 
|  | 6112 | .rpc_resp = &res, | 
| Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6113 | .rpc_cred = cred, | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6114 | }; | 
|  | 6115 |  | 
|  | 6116 | dprintk("--> %s\n", __func__); | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6117 |  | 
|  | 6118 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); | 
|  | 6119 | if (unlikely(res.session == NULL)) { | 
|  | 6120 | status = -ENOMEM; | 
|  | 6121 | goto out; | 
|  | 6122 | } | 
|  | 6123 |  | 
|  | 6124 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6125 | trace_nfs4_bind_conn_to_session(clp, status); | 
| Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6126 | if (status == 0) { | 
|  | 6127 | if (memcmp(res.session->sess_id.data, | 
|  | 6128 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { | 
|  | 6129 | dprintk("NFS: %s: Session ID mismatch\n", __func__); | 
|  | 6130 | status = -EIO; | 
|  | 6131 | goto out_session; | 
|  | 6132 | } | 
|  | 6133 | if (res.dir != NFS4_CDFS4_BOTH) { | 
|  | 6134 | dprintk("NFS: %s: Unexpected direction from server\n", | 
|  | 6135 | __func__); | 
|  | 6136 | status = -EIO; | 
|  | 6137 | goto out_session; | 
|  | 6138 | } | 
|  | 6139 | if (res.use_conn_in_rdma_mode) { | 
|  | 6140 | dprintk("NFS: %s: Server returned RDMA mode = true\n", | 
|  | 6141 | __func__); | 
|  | 6142 | status = -EIO; | 
|  | 6143 | goto out_session; | 
|  | 6144 | } | 
|  | 6145 | } | 
|  | 6146 | out_session: | 
|  | 6147 | kfree(res.session); | 
|  | 6148 | out: | 
|  | 6149 | dprintk("<-- %s status= %d\n", __func__, status); | 
|  | 6150 | return status; | 
|  | 6151 | } | 
|  | 6152 |  | 
|  | 6153 | /* | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6154 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map | 
|  | 6155 | * 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] | 6156 | */ | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6157 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { | 
|  | 6158 | .how = SP4_MACH_CRED, | 
|  | 6159 | .enforce.u.words = { | 
|  | 6160 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | | 
|  | 6161 | 1 << (OP_EXCHANGE_ID - 32) | | 
|  | 6162 | 1 << (OP_CREATE_SESSION - 32) | | 
|  | 6163 | 1 << (OP_DESTROY_SESSION - 32) | | 
|  | 6164 | 1 << (OP_DESTROY_CLIENTID - 32) | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6165 | }, | 
|  | 6166 | .allow.u.words = { | 
|  | 6167 | [0] = 1 << (OP_CLOSE) | | 
| Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6168 | 1 << (OP_LOCKU) | | 
|  | 6169 | 1 << (OP_COMMIT), | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6170 | [1] = 1 << (OP_SECINFO - 32) | | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6171 | 1 << (OP_SECINFO_NO_NAME - 32) | | 
|  | 6172 | 1 << (OP_TEST_STATEID - 32) | | 
| Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 6173 | 1 << (OP_FREE_STATEID - 32) | | 
|  | 6174 | 1 << (OP_WRITE - 32) | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6175 | } | 
|  | 6176 | }; | 
|  | 6177 |  | 
|  | 6178 | /* | 
|  | 6179 | * Select the state protection mode for client `clp' given the server results | 
|  | 6180 | * from exchange_id in `sp'. | 
|  | 6181 | * | 
|  | 6182 | * Returns 0 on success, negative errno otherwise. | 
|  | 6183 | */ | 
|  | 6184 | static int nfs4_sp4_select_mode(struct nfs_client *clp, | 
|  | 6185 | struct nfs41_state_protection *sp) | 
|  | 6186 | { | 
|  | 6187 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { | 
|  | 6188 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | | 
|  | 6189 | 1 << (OP_EXCHANGE_ID - 32) | | 
|  | 6190 | 1 << (OP_CREATE_SESSION - 32) | | 
|  | 6191 | 1 << (OP_DESTROY_SESSION - 32) | | 
|  | 6192 | 1 << (OP_DESTROY_CLIENTID - 32) | 
|  | 6193 | }; | 
|  | 6194 | unsigned int i; | 
|  | 6195 |  | 
|  | 6196 | if (sp->how == SP4_MACH_CRED) { | 
|  | 6197 | /* Print state protect result */ | 
|  | 6198 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); | 
|  | 6199 | for (i = 0; i <= LAST_NFS4_OP; i++) { | 
|  | 6200 | if (test_bit(i, sp->enforce.u.longs)) | 
|  | 6201 | dfprintk(MOUNT, "  enforce op %d\n", i); | 
|  | 6202 | if (test_bit(i, sp->allow.u.longs)) | 
|  | 6203 | dfprintk(MOUNT, "  allow op %d\n", i); | 
|  | 6204 | } | 
|  | 6205 |  | 
|  | 6206 | /* make sure nothing is on enforce list that isn't supported */ | 
|  | 6207 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { | 
|  | 6208 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { | 
|  | 6209 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); | 
|  | 6210 | return -EINVAL; | 
|  | 6211 | } | 
|  | 6212 | } | 
|  | 6213 |  | 
|  | 6214 | /* | 
|  | 6215 | * Minimal mode - state operations are allowed to use machine | 
|  | 6216 | * credential.  Note this already happens by default, so the | 
|  | 6217 | * client doesn't have to do anything more than the negotiation. | 
|  | 6218 | * | 
|  | 6219 | * NOTE: we don't care if EXCHANGE_ID is in the list - | 
|  | 6220 | *       we're already using the machine cred for exchange_id | 
|  | 6221 | *       and will never use a different cred. | 
|  | 6222 | */ | 
|  | 6223 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && | 
|  | 6224 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && | 
|  | 6225 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && | 
|  | 6226 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { | 
|  | 6227 | dfprintk(MOUNT, "sp4_mach_cred:\n"); | 
|  | 6228 | dfprintk(MOUNT, "  minimal mode enabled\n"); | 
|  | 6229 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); | 
|  | 6230 | } else { | 
|  | 6231 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); | 
|  | 6232 | return -EINVAL; | 
|  | 6233 | } | 
| Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6234 |  | 
|  | 6235 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && | 
|  | 6236 | test_bit(OP_LOCKU, sp->allow.u.longs)) { | 
|  | 6237 | dfprintk(MOUNT, "  cleanup mode enabled\n"); | 
|  | 6238 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); | 
|  | 6239 | } | 
| Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6240 |  | 
|  | 6241 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && | 
|  | 6242 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { | 
|  | 6243 | dfprintk(MOUNT, "  secinfo mode enabled\n"); | 
|  | 6244 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); | 
|  | 6245 | } | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 6246 |  | 
|  | 6247 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && | 
|  | 6248 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { | 
|  | 6249 | dfprintk(MOUNT, "  stateid mode enabled\n"); | 
|  | 6250 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); | 
|  | 6251 | } | 
| Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 6252 |  | 
|  | 6253 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { | 
|  | 6254 | dfprintk(MOUNT, "  write mode enabled\n"); | 
|  | 6255 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); | 
|  | 6256 | } | 
|  | 6257 |  | 
|  | 6258 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { | 
|  | 6259 | dfprintk(MOUNT, "  commit mode enabled\n"); | 
|  | 6260 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); | 
|  | 6261 | } | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6262 | } | 
|  | 6263 |  | 
|  | 6264 | return 0; | 
|  | 6265 | } | 
|  | 6266 |  | 
|  | 6267 | /* | 
|  | 6268 | * _nfs4_proc_exchange_id() | 
|  | 6269 | * | 
|  | 6270 | * Wrapper for EXCHANGE_ID operation. | 
|  | 6271 | */ | 
|  | 6272 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, | 
|  | 6273 | u32 sp4_how) | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6274 | { | 
|  | 6275 | nfs4_verifier verifier; | 
|  | 6276 | struct nfs41_exchange_id_args args = { | 
| Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 6277 | .verifier = &verifier, | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6278 | .client = clp, | 
| Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 6279 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | | 
|  | 6280 | EXCHGID4_FLAG_BIND_PRINC_STATEID, | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6281 | }; | 
|  | 6282 | struct nfs41_exchange_id_res res = { | 
| Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6283 | 0 | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6284 | }; | 
|  | 6285 | int status; | 
|  | 6286 | struct rpc_message msg = { | 
|  | 6287 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], | 
|  | 6288 | .rpc_argp = &args, | 
|  | 6289 | .rpc_resp = &res, | 
|  | 6290 | .rpc_cred = cred, | 
|  | 6291 | }; | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6292 |  | 
| Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 6293 | nfs4_init_boot_verifier(clp, &verifier); | 
| Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 6294 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, | 
|  | 6295 | sizeof(args.id)); | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6296 | dprintk("NFS call  exchange_id auth=%s, '%.*s'\n", | 
|  | 6297 | clp->cl_rpcclient->cl_auth->au_ops->au_name, | 
|  | 6298 | args.id_len, args.id); | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6299 |  | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6300 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), | 
| Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6301 | GFP_NOFS); | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6302 | if (unlikely(res.server_owner == NULL)) { | 
| Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6303 | status = -ENOMEM; | 
|  | 6304 | goto out; | 
|  | 6305 | } | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6306 |  | 
| Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6307 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), | 
| Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6308 | GFP_NOFS); | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6309 | if (unlikely(res.server_scope == NULL)) { | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6310 | status = -ENOMEM; | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6311 | goto out_server_owner; | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6312 | } | 
|  | 6313 |  | 
| Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 6314 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6315 | if (unlikely(res.impl_id == NULL)) { | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6316 | status = -ENOMEM; | 
|  | 6317 | goto out_server_scope; | 
|  | 6318 | } | 
|  | 6319 |  | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6320 | switch (sp4_how) { | 
|  | 6321 | case SP4_NONE: | 
|  | 6322 | args.state_protect.how = SP4_NONE; | 
|  | 6323 | break; | 
|  | 6324 |  | 
|  | 6325 | case SP4_MACH_CRED: | 
|  | 6326 | args.state_protect = nfs4_sp4_mach_cred_request; | 
|  | 6327 | break; | 
|  | 6328 |  | 
|  | 6329 | default: | 
|  | 6330 | /* unsupported! */ | 
|  | 6331 | WARN_ON_ONCE(1); | 
|  | 6332 | status = -EINVAL; | 
|  | 6333 | goto out_server_scope; | 
|  | 6334 | } | 
|  | 6335 |  | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6336 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6337 | trace_nfs4_exchange_id(clp, status); | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6338 | if (status == 0) | 
| Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6339 | status = nfs4_check_cl_exchange_flags(res.flags); | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6340 |  | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6341 | if (status == 0) | 
|  | 6342 | status = nfs4_sp4_select_mode(clp, &res.state_protect); | 
|  | 6343 |  | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6344 | if (status == 0) { | 
| Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6345 | clp->cl_clientid = res.clientid; | 
|  | 6346 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); | 
|  | 6347 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) | 
|  | 6348 | clp->cl_seqid = res.seqid; | 
|  | 6349 |  | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6350 | kfree(clp->cl_serverowner); | 
|  | 6351 | clp->cl_serverowner = res.server_owner; | 
|  | 6352 | res.server_owner = NULL; | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6353 |  | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6354 | /* use the most recent implementation id */ | 
| Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6355 | kfree(clp->cl_implid); | 
|  | 6356 | clp->cl_implid = res.impl_id; | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6357 |  | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6358 | if (clp->cl_serverscope != NULL && | 
| Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6359 | !nfs41_same_server_scope(clp->cl_serverscope, | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6360 | res.server_scope)) { | 
|  | 6361 | dprintk("%s: server_scope mismatch detected\n", | 
|  | 6362 | __func__); | 
|  | 6363 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); | 
| Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6364 | kfree(clp->cl_serverscope); | 
|  | 6365 | clp->cl_serverscope = NULL; | 
| Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6366 | } | 
|  | 6367 |  | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6368 | if (clp->cl_serverscope == NULL) { | 
| Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6369 | clp->cl_serverscope = res.server_scope; | 
| Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6370 | goto out; | 
|  | 6371 | } | 
| Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 6372 | } else | 
|  | 6373 | kfree(res.impl_id); | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6374 |  | 
| Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 6375 | out_server_owner: | 
|  | 6376 | kfree(res.server_owner); | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6377 | out_server_scope: | 
| Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 6378 | kfree(res.server_scope); | 
|  | 6379 | out: | 
| Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 6380 | if (clp->cl_implid != NULL) | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6381 | dprintk("NFS reply exchange_id: Server Implementation ID: " | 
| Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 6382 | "domain: %s, name: %s, date: %llu,%u\n", | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6383 | clp->cl_implid->domain, clp->cl_implid->name, | 
| Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 6384 | clp->cl_implid->date.seconds, | 
|  | 6385 | clp->cl_implid->date.nseconds); | 
| Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 6386 | dprintk("NFS reply exchange_id: %d\n", status); | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6387 | return status; | 
|  | 6388 | } | 
|  | 6389 |  | 
| Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 6390 | /* | 
|  | 6391 | * nfs4_proc_exchange_id() | 
|  | 6392 | * | 
|  | 6393 | * Returns zero, a negative errno, or a negative NFS4ERR status code. | 
|  | 6394 | * | 
|  | 6395 | * Since the clientid has expired, all compounds using sessions | 
|  | 6396 | * associated with the stale clientid will be returning | 
|  | 6397 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore | 
|  | 6398 | * be in some phase of session reset. | 
|  | 6399 | * | 
|  | 6400 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. | 
|  | 6401 | */ | 
|  | 6402 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) | 
|  | 6403 | { | 
|  | 6404 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; | 
|  | 6405 | int status; | 
|  | 6406 |  | 
|  | 6407 | /* try SP4_MACH_CRED if krb5i/p	*/ | 
|  | 6408 | if (authflavor == RPC_AUTH_GSS_KRB5I || | 
|  | 6409 | authflavor == RPC_AUTH_GSS_KRB5P) { | 
|  | 6410 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); | 
|  | 6411 | if (!status) | 
|  | 6412 | return 0; | 
|  | 6413 | } | 
|  | 6414 |  | 
|  | 6415 | /* try SP4_NONE */ | 
|  | 6416 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); | 
|  | 6417 | } | 
|  | 6418 |  | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6419 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, | 
|  | 6420 | struct rpc_cred *cred) | 
|  | 6421 | { | 
|  | 6422 | struct rpc_message msg = { | 
|  | 6423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], | 
|  | 6424 | .rpc_argp = clp, | 
|  | 6425 | .rpc_cred = cred, | 
|  | 6426 | }; | 
|  | 6427 | int status; | 
|  | 6428 |  | 
|  | 6429 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6430 | trace_nfs4_destroy_clientid(clp, status); | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6431 | if (status) | 
| Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 6432 | dprintk("NFS: Got error %d from the server %s on " | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6433 | "DESTROY_CLIENTID.", status, clp->cl_hostname); | 
|  | 6434 | return status; | 
|  | 6435 | } | 
|  | 6436 |  | 
|  | 6437 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, | 
|  | 6438 | struct rpc_cred *cred) | 
|  | 6439 | { | 
|  | 6440 | unsigned int loop; | 
|  | 6441 | int ret; | 
|  | 6442 |  | 
|  | 6443 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { | 
|  | 6444 | ret = _nfs4_proc_destroy_clientid(clp, cred); | 
|  | 6445 | switch (ret) { | 
|  | 6446 | case -NFS4ERR_DELAY: | 
|  | 6447 | case -NFS4ERR_CLIENTID_BUSY: | 
|  | 6448 | ssleep(1); | 
|  | 6449 | break; | 
|  | 6450 | default: | 
|  | 6451 | return ret; | 
|  | 6452 | } | 
|  | 6453 | } | 
|  | 6454 | return 0; | 
|  | 6455 | } | 
|  | 6456 |  | 
|  | 6457 | int nfs4_destroy_clientid(struct nfs_client *clp) | 
|  | 6458 | { | 
|  | 6459 | struct rpc_cred *cred; | 
|  | 6460 | int ret = 0; | 
|  | 6461 |  | 
|  | 6462 | if (clp->cl_mvops->minor_version < 1) | 
|  | 6463 | goto out; | 
|  | 6464 | if (clp->cl_exchange_flags == 0) | 
|  | 6465 | goto out; | 
| Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6466 | if (clp->cl_preserve_clid) | 
|  | 6467 | goto out; | 
| Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 6468 | cred = nfs4_get_clid_cred(clp); | 
| Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 6469 | ret = nfs4_proc_destroy_clientid(clp, cred); | 
|  | 6470 | if (cred) | 
|  | 6471 | put_rpccred(cred); | 
|  | 6472 | switch (ret) { | 
|  | 6473 | case 0: | 
|  | 6474 | case -NFS4ERR_STALE_CLIENTID: | 
|  | 6475 | clp->cl_exchange_flags = 0; | 
|  | 6476 | } | 
|  | 6477 | out: | 
|  | 6478 | return ret; | 
|  | 6479 | } | 
|  | 6480 |  | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6481 | struct nfs4_get_lease_time_data { | 
|  | 6482 | struct nfs4_get_lease_time_args *args; | 
|  | 6483 | struct nfs4_get_lease_time_res *res; | 
|  | 6484 | struct nfs_client *clp; | 
|  | 6485 | }; | 
|  | 6486 |  | 
|  | 6487 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, | 
|  | 6488 | void *calldata) | 
|  | 6489 | { | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6490 | struct nfs4_get_lease_time_data *data = | 
|  | 6491 | (struct nfs4_get_lease_time_data *)calldata; | 
|  | 6492 |  | 
|  | 6493 | dprintk("--> %s\n", __func__); | 
|  | 6494 | /* just setup sequence, do not trigger session recovery | 
|  | 6495 | since we're invoked within one */ | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6496 | nfs41_setup_sequence(data->clp->cl_session, | 
|  | 6497 | &data->args->la_seq_args, | 
|  | 6498 | &data->res->lr_seq_res, | 
|  | 6499 | task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6500 | dprintk("<-- %s\n", __func__); | 
|  | 6501 | } | 
|  | 6502 |  | 
|  | 6503 | /* | 
|  | 6504 | * Called from nfs4_state_manager thread for session setup, so don't recover | 
|  | 6505 | * from sequence operation or clientid errors. | 
|  | 6506 | */ | 
|  | 6507 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) | 
|  | 6508 | { | 
|  | 6509 | struct nfs4_get_lease_time_data *data = | 
|  | 6510 | (struct nfs4_get_lease_time_data *)calldata; | 
|  | 6511 |  | 
|  | 6512 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6513 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) | 
|  | 6514 | return; | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6515 | switch (task->tk_status) { | 
|  | 6516 | case -NFS4ERR_DELAY: | 
|  | 6517 | case -NFS4ERR_GRACE: | 
|  | 6518 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); | 
|  | 6519 | rpc_delay(task, NFS4_POLL_RETRY_MIN); | 
|  | 6520 | task->tk_status = 0; | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6521 | /* fall through */ | 
|  | 6522 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6523 | rpc_restart_call_prepare(task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6524 | return; | 
|  | 6525 | } | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6526 | dprintk("<-- %s\n", __func__); | 
|  | 6527 | } | 
|  | 6528 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6529 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6530 | .rpc_call_prepare = nfs4_get_lease_time_prepare, | 
|  | 6531 | .rpc_call_done = nfs4_get_lease_time_done, | 
|  | 6532 | }; | 
|  | 6533 |  | 
|  | 6534 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) | 
|  | 6535 | { | 
|  | 6536 | struct rpc_task *task; | 
|  | 6537 | struct nfs4_get_lease_time_args args; | 
|  | 6538 | struct nfs4_get_lease_time_res res = { | 
|  | 6539 | .lr_fsinfo = fsinfo, | 
|  | 6540 | }; | 
|  | 6541 | struct nfs4_get_lease_time_data data = { | 
|  | 6542 | .args = &args, | 
|  | 6543 | .res = &res, | 
|  | 6544 | .clp = clp, | 
|  | 6545 | }; | 
|  | 6546 | struct rpc_message msg = { | 
|  | 6547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], | 
|  | 6548 | .rpc_argp = &args, | 
|  | 6549 | .rpc_resp = &res, | 
|  | 6550 | }; | 
|  | 6551 | struct rpc_task_setup task_setup = { | 
|  | 6552 | .rpc_client = clp->cl_rpcclient, | 
|  | 6553 | .rpc_message = &msg, | 
|  | 6554 | .callback_ops = &nfs4_get_lease_time_ops, | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6555 | .callback_data = &data, | 
|  | 6556 | .flags = RPC_TASK_TIMEOUT, | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6557 | }; | 
|  | 6558 | int status; | 
|  | 6559 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6560 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6561 | nfs4_set_sequence_privileged(&args.la_seq_args); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 6562 | dprintk("--> %s\n", __func__); | 
|  | 6563 | task = rpc_run_task(&task_setup); | 
|  | 6564 |  | 
|  | 6565 | if (IS_ERR(task)) | 
|  | 6566 | status = PTR_ERR(task); | 
|  | 6567 | else { | 
|  | 6568 | status = task->tk_status; | 
|  | 6569 | rpc_put_task(task); | 
|  | 6570 | } | 
|  | 6571 | dprintk("<-- %s return %d\n", __func__, status); | 
|  | 6572 |  | 
|  | 6573 | return status; | 
|  | 6574 | } | 
|  | 6575 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6576 | /* | 
|  | 6577 | * Initialize the values to be used by the client in CREATE_SESSION | 
|  | 6578 | * If nfs4_init_session set the fore channel request and response sizes, | 
|  | 6579 | * use them. | 
|  | 6580 | * | 
|  | 6581 | * Set the back channel max_resp_sz_cached to zero to force the client to | 
|  | 6582 | * always set csa_cachethis to FALSE because the current implementation | 
|  | 6583 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. | 
|  | 6584 | */ | 
|  | 6585 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) | 
|  | 6586 | { | 
| Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6587 | unsigned int max_rqst_sz, max_resp_sz; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6588 |  | 
| Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6589 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; | 
|  | 6590 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; | 
|  | 6591 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6592 | /* Fore channel attributes */ | 
| Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 6593 | args->fc_attrs.max_rqst_sz = max_rqst_sz; | 
|  | 6594 | args->fc_attrs.max_resp_sz = max_resp_sz; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6595 | args->fc_attrs.max_ops = NFS4_MAX_OPS; | 
| Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6596 | args->fc_attrs.max_reqs = max_session_slots; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6597 |  | 
|  | 6598 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " | 
| Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6599 | "max_ops=%u max_reqs=%u\n", | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6600 | __func__, | 
|  | 6601 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, | 
| Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 6602 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6603 |  | 
|  | 6604 | /* Back channel attributes */ | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6605 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; | 
|  | 6606 | args->bc_attrs.max_resp_sz = PAGE_SIZE; | 
|  | 6607 | args->bc_attrs.max_resp_sz_cached = 0; | 
|  | 6608 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; | 
|  | 6609 | args->bc_attrs.max_reqs = 1; | 
|  | 6610 |  | 
|  | 6611 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " | 
|  | 6612 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", | 
|  | 6613 | __func__, | 
|  | 6614 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, | 
|  | 6615 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, | 
|  | 6616 | args->bc_attrs.max_reqs); | 
|  | 6617 | } | 
|  | 6618 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6619 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6620 | { | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6621 | struct nfs4_channel_attrs *sent = &args->fc_attrs; | 
|  | 6622 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; | 
|  | 6623 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6624 | if (rcvd->max_resp_sz > sent->max_resp_sz) | 
|  | 6625 | return -EINVAL; | 
|  | 6626 | /* | 
|  | 6627 | * Our requested max_ops is the minimum we need; we're not | 
|  | 6628 | * prepared to break up compounds into smaller pieces than that. | 
|  | 6629 | * So, no point even trying to continue if the server won't | 
|  | 6630 | * cooperate: | 
|  | 6631 | */ | 
|  | 6632 | if (rcvd->max_ops < sent->max_ops) | 
|  | 6633 | return -EINVAL; | 
|  | 6634 | if (rcvd->max_reqs == 0) | 
|  | 6635 | return -EINVAL; | 
| Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6636 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) | 
|  | 6637 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6638 | return 0; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6639 | } | 
|  | 6640 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6641 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) | 
|  | 6642 | { | 
|  | 6643 | struct nfs4_channel_attrs *sent = &args->bc_attrs; | 
|  | 6644 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6645 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6646 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) | 
|  | 6647 | return -EINVAL; | 
|  | 6648 | if (rcvd->max_resp_sz < sent->max_resp_sz) | 
|  | 6649 | return -EINVAL; | 
|  | 6650 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) | 
|  | 6651 | return -EINVAL; | 
|  | 6652 | /* These would render the backchannel useless: */ | 
| Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6653 | if (rcvd->max_ops != sent->max_ops) | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6654 | return -EINVAL; | 
| Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 6655 | if (rcvd->max_reqs != sent->max_reqs) | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6656 | return -EINVAL; | 
|  | 6657 | return 0; | 
|  | 6658 | } | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6659 |  | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6660 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, | 
|  | 6661 | struct nfs4_session *session) | 
|  | 6662 | { | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6663 | int ret; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6664 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 6665 | ret = nfs4_verify_fore_channel_attrs(args, session); | 
|  | 6666 | if (ret) | 
|  | 6667 | return ret; | 
|  | 6668 | return nfs4_verify_back_channel_attrs(args, session); | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6669 | } | 
|  | 6670 |  | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6671 | static int _nfs4_proc_create_session(struct nfs_client *clp, | 
|  | 6672 | struct rpc_cred *cred) | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6673 | { | 
|  | 6674 | struct nfs4_session *session = clp->cl_session; | 
|  | 6675 | struct nfs41_create_session_args args = { | 
|  | 6676 | .client = clp, | 
|  | 6677 | .cb_program = NFS4_CALLBACK, | 
|  | 6678 | }; | 
|  | 6679 | struct nfs41_create_session_res res = { | 
|  | 6680 | .client = clp, | 
|  | 6681 | }; | 
|  | 6682 | struct rpc_message msg = { | 
|  | 6683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], | 
|  | 6684 | .rpc_argp = &args, | 
|  | 6685 | .rpc_resp = &res, | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6686 | .rpc_cred = cred, | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6687 | }; | 
|  | 6688 | int status; | 
|  | 6689 |  | 
|  | 6690 | nfs4_init_channel_attrs(&args); | 
| Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 6691 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6692 |  | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6693 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6694 | trace_nfs4_create_session(clp, status); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6695 |  | 
| Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 6696 | if (!status) { | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 6697 | /* Verify the session's negotiated channel_attrs values */ | 
|  | 6698 | status = nfs4_verify_channel_attrs(&args, session); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6699 | /* Increment the clientid slot sequence id */ | 
|  | 6700 | clp->cl_seqid++; | 
|  | 6701 | } | 
|  | 6702 |  | 
|  | 6703 | return status; | 
|  | 6704 | } | 
|  | 6705 |  | 
|  | 6706 | /* | 
|  | 6707 | * Issues a CREATE_SESSION operation to the server. | 
|  | 6708 | * It is the responsibility of the caller to verify the session is | 
|  | 6709 | * expired before calling this routine. | 
|  | 6710 | */ | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6711 | 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] | 6712 | { | 
|  | 6713 | int status; | 
|  | 6714 | unsigned *ptr; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6715 | struct nfs4_session *session = clp->cl_session; | 
|  | 6716 |  | 
|  | 6717 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); | 
|  | 6718 |  | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6719 | status = _nfs4_proc_create_session(clp, cred); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6720 | if (status) | 
|  | 6721 | goto out; | 
|  | 6722 |  | 
| Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 6723 | /* Init or reset the session slot tables */ | 
|  | 6724 | status = nfs4_setup_session_slot_tables(session); | 
|  | 6725 | dprintk("slot table setup returned %d\n", status); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6726 | if (status) | 
|  | 6727 | goto out; | 
|  | 6728 |  | 
|  | 6729 | ptr = (unsigned *)&session->sess_id.data[0]; | 
|  | 6730 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, | 
|  | 6731 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 6732 | out: | 
|  | 6733 | dprintk("<-- %s\n", __func__); | 
|  | 6734 | return status; | 
|  | 6735 | } | 
|  | 6736 |  | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6737 | /* | 
|  | 6738 | * Issue the over-the-wire RPC DESTROY_SESSION. | 
|  | 6739 | * The caller must serialize access to this routine. | 
|  | 6740 | */ | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6741 | int nfs4_proc_destroy_session(struct nfs4_session *session, | 
|  | 6742 | struct rpc_cred *cred) | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6743 | { | 
| Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 6744 | struct rpc_message msg = { | 
|  | 6745 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], | 
|  | 6746 | .rpc_argp = session, | 
|  | 6747 | .rpc_cred = cred, | 
|  | 6748 | }; | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6749 | int status = 0; | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6750 |  | 
|  | 6751 | dprintk("--> nfs4_proc_destroy_session\n"); | 
|  | 6752 |  | 
|  | 6753 | /* session is still being setup */ | 
|  | 6754 | if (session->clp->cl_cons_state != NFS_CS_READY) | 
|  | 6755 | return status; | 
|  | 6756 |  | 
| Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 6757 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6758 | trace_nfs4_destroy_session(session->clp, status); | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6759 |  | 
|  | 6760 | if (status) | 
| Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 6761 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 6762 | "Session has been destroyed regardless...\n", status); | 
|  | 6763 |  | 
|  | 6764 | dprintk("<-- nfs4_proc_destroy_session\n"); | 
|  | 6765 | return status; | 
|  | 6766 | } | 
|  | 6767 |  | 
| Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6768 | /* | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6769 | * Renew the cl_session lease. | 
|  | 6770 | */ | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6771 | struct nfs4_sequence_data { | 
|  | 6772 | struct nfs_client *clp; | 
|  | 6773 | struct nfs4_sequence_args args; | 
|  | 6774 | struct nfs4_sequence_res res; | 
|  | 6775 | }; | 
|  | 6776 |  | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6777 | static void nfs41_sequence_release(void *data) | 
|  | 6778 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6779 | struct nfs4_sequence_data *calldata = data; | 
|  | 6780 | struct nfs_client *clp = calldata->clp; | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6781 |  | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6782 | if (atomic_read(&clp->cl_count) > 1) | 
|  | 6783 | nfs4_schedule_state_renewal(clp); | 
|  | 6784 | nfs_put_client(clp); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6785 | kfree(calldata); | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6786 | } | 
|  | 6787 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6788 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) | 
|  | 6789 | { | 
|  | 6790 | switch(task->tk_status) { | 
|  | 6791 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6792 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
|  | 6793 | return -EAGAIN; | 
|  | 6794 | default: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6795 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6796 | } | 
|  | 6797 | return 0; | 
|  | 6798 | } | 
|  | 6799 |  | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6800 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6801 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6802 | struct nfs4_sequence_data *calldata = data; | 
|  | 6803 | struct nfs_client *clp = calldata->clp; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6804 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6805 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) | 
|  | 6806 | return; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6807 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6808 | trace_nfs4_sequence(clp, task->tk_status); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6809 | if (task->tk_status < 0) { | 
|  | 6810 | dprintk("%s ERROR %d\n", __func__, task->tk_status); | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6811 | if (atomic_read(&clp->cl_count) == 1) | 
|  | 6812 | goto out; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6813 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6814 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { | 
|  | 6815 | rpc_restart_call_prepare(task); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6816 | return; | 
|  | 6817 | } | 
|  | 6818 | } | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6819 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6820 | out: | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6821 | dprintk("<-- %s\n", __func__); | 
|  | 6822 | } | 
|  | 6823 |  | 
|  | 6824 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) | 
|  | 6825 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6826 | struct nfs4_sequence_data *calldata = data; | 
|  | 6827 | struct nfs_client *clp = calldata->clp; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6828 | struct nfs4_sequence_args *args; | 
|  | 6829 | struct nfs4_sequence_res *res; | 
|  | 6830 |  | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6831 | args = task->tk_msg.rpc_argp; | 
|  | 6832 | res = task->tk_msg.rpc_resp; | 
|  | 6833 |  | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6834 | nfs41_setup_sequence(clp->cl_session, args, res, task); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6835 | } | 
|  | 6836 |  | 
|  | 6837 | static const struct rpc_call_ops nfs41_sequence_ops = { | 
|  | 6838 | .rpc_call_done = nfs41_sequence_call_done, | 
|  | 6839 | .rpc_call_prepare = nfs41_sequence_prepare, | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6840 | .rpc_release = nfs41_sequence_release, | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6841 | }; | 
|  | 6842 |  | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6843 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, | 
|  | 6844 | struct rpc_cred *cred, | 
|  | 6845 | bool is_privileged) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6846 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6847 | struct nfs4_sequence_data *calldata; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6848 | struct rpc_message msg = { | 
|  | 6849 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], | 
|  | 6850 | .rpc_cred = cred, | 
|  | 6851 | }; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6852 | struct rpc_task_setup task_setup_data = { | 
|  | 6853 | .rpc_client = clp->cl_rpcclient, | 
|  | 6854 | .rpc_message = &msg, | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6855 | .callback_ops = &nfs41_sequence_ops, | 
| Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6856 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6857 | }; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6858 |  | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6859 | if (!atomic_inc_not_zero(&clp->cl_count)) | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6860 | return ERR_PTR(-EIO); | 
| Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6861 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6862 | if (calldata == NULL) { | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6863 | nfs_put_client(clp); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6864 | return ERR_PTR(-ENOMEM); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6865 | } | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6866 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6867 | if (is_privileged) | 
|  | 6868 | nfs4_set_sequence_privileged(&calldata->args); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6869 | msg.rpc_argp = &calldata->args; | 
|  | 6870 | msg.rpc_resp = &calldata->res; | 
|  | 6871 | calldata->clp = clp; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6872 | task_setup_data.callback_data = calldata; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6873 |  | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6874 | return rpc_run_task(&task_setup_data); | 
|  | 6875 | } | 
|  | 6876 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6877 | 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] | 6878 | { | 
|  | 6879 | struct rpc_task *task; | 
|  | 6880 | int ret = 0; | 
|  | 6881 |  | 
| Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6882 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) | 
|  | 6883 | return 0; | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6884 | task = _nfs41_proc_sequence(clp, cred, false); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6885 | if (IS_ERR(task)) | 
|  | 6886 | ret = PTR_ERR(task); | 
|  | 6887 | else | 
| Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6888 | rpc_put_task_async(task); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6889 | dprintk("<-- %s status=%d\n", __func__, ret); | 
|  | 6890 | return ret; | 
|  | 6891 | } | 
|  | 6892 |  | 
|  | 6893 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) | 
|  | 6894 | { | 
|  | 6895 | struct rpc_task *task; | 
|  | 6896 | int ret; | 
|  | 6897 |  | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6898 | task = _nfs41_proc_sequence(clp, cred, true); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6899 | if (IS_ERR(task)) { | 
|  | 6900 | ret = PTR_ERR(task); | 
|  | 6901 | goto out; | 
|  | 6902 | } | 
|  | 6903 | ret = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6904 | if (!ret) { | 
|  | 6905 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; | 
|  | 6906 |  | 
|  | 6907 | if (task->tk_status == 0) | 
|  | 6908 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6909 | ret = task->tk_status; | 
| Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6910 | } | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6911 | rpc_put_task(task); | 
|  | 6912 | out: | 
|  | 6913 | dprintk("<-- %s status=%d\n", __func__, ret); | 
|  | 6914 | return ret; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6915 | } | 
|  | 6916 |  | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6917 | struct nfs4_reclaim_complete_data { | 
|  | 6918 | struct nfs_client *clp; | 
|  | 6919 | struct nfs41_reclaim_complete_args arg; | 
|  | 6920 | struct nfs41_reclaim_complete_res res; | 
|  | 6921 | }; | 
|  | 6922 |  | 
|  | 6923 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) | 
|  | 6924 | { | 
|  | 6925 | struct nfs4_reclaim_complete_data *calldata = data; | 
|  | 6926 |  | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6927 | nfs41_setup_sequence(calldata->clp->cl_session, | 
|  | 6928 | &calldata->arg.seq_args, | 
|  | 6929 | &calldata->res.seq_res, | 
|  | 6930 | task); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6931 | } | 
|  | 6932 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6933 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) | 
|  | 6934 | { | 
|  | 6935 | switch(task->tk_status) { | 
|  | 6936 | case 0: | 
|  | 6937 | case -NFS4ERR_COMPLETE_ALREADY: | 
|  | 6938 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ | 
|  | 6939 | break; | 
|  | 6940 | case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6941 | rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
| Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6942 | /* fall through */ | 
|  | 6943 | case -NFS4ERR_RETRY_UNCACHED_REP: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6944 | return -EAGAIN; | 
|  | 6945 | default: | 
| Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6946 | nfs4_schedule_lease_recovery(clp); | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6947 | } | 
|  | 6948 | return 0; | 
|  | 6949 | } | 
|  | 6950 |  | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6951 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) | 
|  | 6952 | { | 
|  | 6953 | struct nfs4_reclaim_complete_data *calldata = data; | 
|  | 6954 | struct nfs_client *clp = calldata->clp; | 
|  | 6955 | struct nfs4_sequence_res *res = &calldata->res.seq_res; | 
|  | 6956 |  | 
|  | 6957 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6958 | if (!nfs41_sequence_done(task, res)) | 
|  | 6959 | return; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6960 |  | 
| Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 6961 | trace_nfs4_reclaim_complete(clp, task->tk_status); | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6962 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { | 
|  | 6963 | rpc_restart_call_prepare(task); | 
|  | 6964 | return; | 
|  | 6965 | } | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6966 | dprintk("<-- %s\n", __func__); | 
|  | 6967 | } | 
|  | 6968 |  | 
|  | 6969 | static void nfs4_free_reclaim_complete_data(void *data) | 
|  | 6970 | { | 
|  | 6971 | struct nfs4_reclaim_complete_data *calldata = data; | 
|  | 6972 |  | 
|  | 6973 | kfree(calldata); | 
|  | 6974 | } | 
|  | 6975 |  | 
|  | 6976 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { | 
|  | 6977 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, | 
|  | 6978 | .rpc_call_done = nfs4_reclaim_complete_done, | 
|  | 6979 | .rpc_release = nfs4_free_reclaim_complete_data, | 
|  | 6980 | }; | 
|  | 6981 |  | 
|  | 6982 | /* | 
|  | 6983 | * Issue a global reclaim complete. | 
|  | 6984 | */ | 
| Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6985 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, | 
|  | 6986 | struct rpc_cred *cred) | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6987 | { | 
|  | 6988 | struct nfs4_reclaim_complete_data *calldata; | 
|  | 6989 | struct rpc_task *task; | 
|  | 6990 | struct rpc_message msg = { | 
|  | 6991 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], | 
| Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6992 | .rpc_cred = cred, | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6993 | }; | 
|  | 6994 | struct rpc_task_setup task_setup_data = { | 
|  | 6995 | .rpc_client = clp->cl_rpcclient, | 
|  | 6996 | .rpc_message = &msg, | 
|  | 6997 | .callback_ops = &nfs4_reclaim_complete_call_ops, | 
|  | 6998 | .flags = RPC_TASK_ASYNC, | 
|  | 6999 | }; | 
|  | 7000 | int status = -ENOMEM; | 
|  | 7001 |  | 
|  | 7002 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 7003 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7004 | if (calldata == NULL) | 
|  | 7005 | goto out; | 
|  | 7006 | calldata->clp = clp; | 
|  | 7007 | calldata->arg.one_fs = 0; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7008 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7009 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7010 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7011 | msg.rpc_argp = &calldata->arg; | 
|  | 7012 | msg.rpc_resp = &calldata->res; | 
|  | 7013 | task_setup_data.callback_data = calldata; | 
|  | 7014 | task = rpc_run_task(&task_setup_data); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7015 | if (IS_ERR(task)) { | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7016 | status = PTR_ERR(task); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7017 | goto out; | 
|  | 7018 | } | 
| Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 7019 | status = nfs4_wait_for_completion_rpc_task(task); | 
|  | 7020 | if (status == 0) | 
|  | 7021 | status = task->tk_status; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7022 | rpc_put_task(task); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 7023 | return 0; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7024 | out: | 
|  | 7025 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 7026 | return status; | 
|  | 7027 | } | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7028 |  | 
|  | 7029 | static void | 
|  | 7030 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) | 
|  | 7031 | { | 
|  | 7032 | struct nfs4_layoutget *lgp = calldata; | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7033 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7034 | struct nfs4_session *session = nfs4_get_session(server); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7035 |  | 
|  | 7036 | dprintk("--> %s\n", __func__); | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7037 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in | 
|  | 7038 | * right now covering the LAYOUTGET we are about to send. | 
|  | 7039 | * However, that is not so catastrophic, and there seems | 
|  | 7040 | * to be no way to prevent it completely. | 
|  | 7041 | */ | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7042 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, | 
| Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 7043 | &lgp->res.seq_res, task)) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7044 | return; | 
| Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7045 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, | 
|  | 7046 | NFS_I(lgp->args.inode)->layout, | 
|  | 7047 | lgp->args.ctx->state)) { | 
|  | 7048 | rpc_exit(task, NFS4_OK); | 
| Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 7049 | } | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7050 | } | 
|  | 7051 |  | 
|  | 7052 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) | 
|  | 7053 | { | 
|  | 7054 | struct nfs4_layoutget *lgp = calldata; | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7055 | struct inode *inode = lgp->args.inode; | 
|  | 7056 | struct nfs_server *server = NFS_SERVER(inode); | 
|  | 7057 | struct pnfs_layout_hdr *lo; | 
|  | 7058 | struct nfs4_state *state = NULL; | 
| Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7059 | unsigned long timeo, giveup; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7060 |  | 
|  | 7061 | dprintk("--> %s\n", __func__); | 
|  | 7062 |  | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7063 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7064 | goto out; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7065 |  | 
|  | 7066 | switch (task->tk_status) { | 
|  | 7067 | case 0: | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7068 | goto out; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7069 | case -NFS4ERR_LAYOUTTRYLATER: | 
|  | 7070 | case -NFS4ERR_RECALLCONFLICT: | 
| Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7071 | timeo = rpc_get_timeout(task->tk_client); | 
|  | 7072 | giveup = lgp->args.timestamp + timeo; | 
|  | 7073 | if (time_after(giveup, jiffies)) | 
|  | 7074 | task->tk_status = -NFS4ERR_DELAY; | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7075 | break; | 
|  | 7076 | case -NFS4ERR_EXPIRED: | 
|  | 7077 | case -NFS4ERR_BAD_STATEID: | 
|  | 7078 | spin_lock(&inode->i_lock); | 
|  | 7079 | lo = NFS_I(inode)->layout; | 
|  | 7080 | if (!lo || list_empty(&lo->plh_segs)) { | 
|  | 7081 | spin_unlock(&inode->i_lock); | 
|  | 7082 | /* If the open stateid was bad, then recover it. */ | 
|  | 7083 | state = lgp->args.ctx->state; | 
|  | 7084 | } else { | 
|  | 7085 | LIST_HEAD(head); | 
|  | 7086 |  | 
|  | 7087 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); | 
|  | 7088 | spin_unlock(&inode->i_lock); | 
|  | 7089 | /* Mark the bad layout state as invalid, then | 
|  | 7090 | * retry using the open stateid. */ | 
|  | 7091 | pnfs_free_lseg_list(&head); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7092 | } | 
|  | 7093 | } | 
| Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 7094 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) | 
|  | 7095 | rpc_restart_call_prepare(task); | 
|  | 7096 | out: | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7097 | dprintk("<-- %s\n", __func__); | 
|  | 7098 | } | 
|  | 7099 |  | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7100 | static size_t max_response_pages(struct nfs_server *server) | 
|  | 7101 | { | 
|  | 7102 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; | 
|  | 7103 | return nfs_page_array_len(0, max_resp_sz); | 
|  | 7104 | } | 
|  | 7105 |  | 
|  | 7106 | static void nfs4_free_pages(struct page **pages, size_t size) | 
|  | 7107 | { | 
|  | 7108 | int i; | 
|  | 7109 |  | 
|  | 7110 | if (!pages) | 
|  | 7111 | return; | 
|  | 7112 |  | 
|  | 7113 | for (i = 0; i < size; i++) { | 
|  | 7114 | if (!pages[i]) | 
|  | 7115 | break; | 
|  | 7116 | __free_page(pages[i]); | 
|  | 7117 | } | 
|  | 7118 | kfree(pages); | 
|  | 7119 | } | 
|  | 7120 |  | 
|  | 7121 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) | 
|  | 7122 | { | 
|  | 7123 | struct page **pages; | 
|  | 7124 | int i; | 
|  | 7125 |  | 
|  | 7126 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); | 
|  | 7127 | if (!pages) { | 
|  | 7128 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); | 
|  | 7129 | return NULL; | 
|  | 7130 | } | 
|  | 7131 |  | 
|  | 7132 | for (i = 0; i < size; i++) { | 
|  | 7133 | pages[i] = alloc_page(gfp_flags); | 
|  | 7134 | if (!pages[i]) { | 
|  | 7135 | dprintk("%s: failed to allocate page\n", __func__); | 
|  | 7136 | nfs4_free_pages(pages, size); | 
|  | 7137 | return NULL; | 
|  | 7138 | } | 
|  | 7139 | } | 
|  | 7140 |  | 
|  | 7141 | return pages; | 
|  | 7142 | } | 
|  | 7143 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7144 | static void nfs4_layoutget_release(void *calldata) | 
|  | 7145 | { | 
|  | 7146 | struct nfs4_layoutget *lgp = calldata; | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7147 | struct inode *inode = lgp->args.inode; | 
|  | 7148 | struct nfs_server *server = NFS_SERVER(inode); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7149 | size_t max_pages = max_response_pages(server); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7150 |  | 
|  | 7151 | dprintk("--> %s\n", __func__); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7152 | nfs4_free_pages(lgp->args.layout.pages, max_pages); | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7153 | pnfs_put_layout_hdr(NFS_I(inode)->layout); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7154 | put_nfs_open_context(lgp->args.ctx); | 
|  | 7155 | kfree(calldata); | 
|  | 7156 | dprintk("<-- %s\n", __func__); | 
|  | 7157 | } | 
|  | 7158 |  | 
|  | 7159 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { | 
|  | 7160 | .rpc_call_prepare = nfs4_layoutget_prepare, | 
|  | 7161 | .rpc_call_done = nfs4_layoutget_done, | 
|  | 7162 | .rpc_release = nfs4_layoutget_release, | 
|  | 7163 | }; | 
|  | 7164 |  | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7165 | struct pnfs_layout_segment * | 
|  | 7166 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7167 | { | 
| Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 7168 | struct inode *inode = lgp->args.inode; | 
|  | 7169 | struct nfs_server *server = NFS_SERVER(inode); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7170 | size_t max_pages = max_response_pages(server); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7171 | struct rpc_task *task; | 
|  | 7172 | struct rpc_message msg = { | 
|  | 7173 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], | 
|  | 7174 | .rpc_argp = &lgp->args, | 
|  | 7175 | .rpc_resp = &lgp->res, | 
| Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 7176 | .rpc_cred = lgp->cred, | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7177 | }; | 
|  | 7178 | struct rpc_task_setup task_setup_data = { | 
|  | 7179 | .rpc_client = server->client, | 
|  | 7180 | .rpc_message = &msg, | 
|  | 7181 | .callback_ops = &nfs4_layoutget_call_ops, | 
|  | 7182 | .callback_data = lgp, | 
|  | 7183 | .flags = RPC_TASK_ASYNC, | 
|  | 7184 | }; | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7185 | struct pnfs_layout_segment *lseg = NULL; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7186 | int status = 0; | 
|  | 7187 |  | 
|  | 7188 | dprintk("--> %s\n", __func__); | 
|  | 7189 |  | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7190 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); | 
|  | 7191 | if (!lgp->args.layout.pages) { | 
|  | 7192 | nfs4_layoutget_release(lgp); | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7193 | return ERR_PTR(-ENOMEM); | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7194 | } | 
|  | 7195 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; | 
| Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 7196 | lgp->args.timestamp = jiffies; | 
| Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 7197 |  | 
| Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 7198 | lgp->res.layoutp = &lgp->args.layout; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7199 | lgp->res.seq_res.sr_slot = NULL; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7200 | 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] | 7201 |  | 
|  | 7202 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ | 
|  | 7203 | pnfs_get_layout_hdr(NFS_I(inode)->layout); | 
|  | 7204 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7205 | task = rpc_run_task(&task_setup_data); | 
|  | 7206 | if (IS_ERR(task)) | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7207 | return ERR_CAST(task); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7208 | status = nfs4_wait_for_completion_rpc_task(task); | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 7209 | if (status == 0) | 
|  | 7210 | status = task->tk_status; | 
| Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7211 | trace_nfs4_layoutget(lgp->args.ctx, | 
|  | 7212 | &lgp->args.range, | 
|  | 7213 | &lgp->res.range, | 
|  | 7214 | status); | 
| Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 7215 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ | 
|  | 7216 | if (status == 0 && lgp->res.layoutp->len) | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7217 | lseg = pnfs_layout_process(lgp); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7218 | rpc_put_task(task); | 
|  | 7219 | dprintk("<-- %s status=%d\n", __func__, status); | 
| Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 7220 | if (status) | 
|  | 7221 | return ERR_PTR(status); | 
|  | 7222 | return lseg; | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7223 | } | 
|  | 7224 |  | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7225 | static void | 
|  | 7226 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) | 
|  | 7227 | { | 
|  | 7228 | struct nfs4_layoutreturn *lrp = calldata; | 
|  | 7229 |  | 
|  | 7230 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7231 | nfs41_setup_sequence(lrp->clp->cl_session, | 
|  | 7232 | &lrp->args.seq_args, | 
|  | 7233 | &lrp->res.seq_res, | 
|  | 7234 | task); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7235 | } | 
|  | 7236 |  | 
|  | 7237 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) | 
|  | 7238 | { | 
|  | 7239 | struct nfs4_layoutreturn *lrp = calldata; | 
|  | 7240 | struct nfs_server *server; | 
|  | 7241 |  | 
|  | 7242 | dprintk("--> %s\n", __func__); | 
|  | 7243 |  | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7244 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7245 | return; | 
|  | 7246 |  | 
|  | 7247 | server = NFS_SERVER(lrp->args.inode); | 
|  | 7248 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { | 
| Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7249 | rpc_restart_call_prepare(task); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7250 | return; | 
|  | 7251 | } | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7252 | dprintk("<-- %s\n", __func__); | 
|  | 7253 | } | 
|  | 7254 |  | 
|  | 7255 | static void nfs4_layoutreturn_release(void *calldata) | 
|  | 7256 | { | 
|  | 7257 | struct nfs4_layoutreturn *lrp = calldata; | 
| Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7258 | struct pnfs_layout_hdr *lo = lrp->args.layout; | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7259 |  | 
|  | 7260 | dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 7261 | spin_lock(&lo->plh_inode->i_lock); | 
|  | 7262 | if (lrp->res.lrs_present) | 
|  | 7263 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); | 
|  | 7264 | lo->plh_block_lgets--; | 
|  | 7265 | spin_unlock(&lo->plh_inode->i_lock); | 
| Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 7266 | pnfs_put_layout_hdr(lrp->args.layout); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7267 | kfree(calldata); | 
|  | 7268 | dprintk("<-- %s\n", __func__); | 
|  | 7269 | } | 
|  | 7270 |  | 
|  | 7271 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { | 
|  | 7272 | .rpc_call_prepare = nfs4_layoutreturn_prepare, | 
|  | 7273 | .rpc_call_done = nfs4_layoutreturn_done, | 
|  | 7274 | .rpc_release = nfs4_layoutreturn_release, | 
|  | 7275 | }; | 
|  | 7276 |  | 
|  | 7277 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) | 
|  | 7278 | { | 
|  | 7279 | struct rpc_task *task; | 
|  | 7280 | struct rpc_message msg = { | 
|  | 7281 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], | 
|  | 7282 | .rpc_argp = &lrp->args, | 
|  | 7283 | .rpc_resp = &lrp->res, | 
| Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 7284 | .rpc_cred = lrp->cred, | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7285 | }; | 
|  | 7286 | struct rpc_task_setup task_setup_data = { | 
| Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 7287 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7288 | .rpc_message = &msg, | 
|  | 7289 | .callback_ops = &nfs4_layoutreturn_call_ops, | 
|  | 7290 | .callback_data = lrp, | 
|  | 7291 | }; | 
|  | 7292 | int status; | 
|  | 7293 |  | 
|  | 7294 | dprintk("--> %s\n", __func__); | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7295 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7296 | task = rpc_run_task(&task_setup_data); | 
|  | 7297 | if (IS_ERR(task)) | 
|  | 7298 | return PTR_ERR(task); | 
|  | 7299 | status = task->tk_status; | 
| Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7300 | trace_nfs4_layoutreturn(lrp->args.inode, status); | 
| Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 7301 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 7302 | rpc_put_task(task); | 
|  | 7303 | return status; | 
|  | 7304 | } | 
|  | 7305 |  | 
| Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 7306 | /* | 
|  | 7307 | * Retrieve the list of Data Server devices from the MDS. | 
|  | 7308 | */ | 
|  | 7309 | static int _nfs4_getdevicelist(struct nfs_server *server, | 
|  | 7310 | const struct nfs_fh *fh, | 
|  | 7311 | struct pnfs_devicelist *devlist) | 
|  | 7312 | { | 
|  | 7313 | struct nfs4_getdevicelist_args args = { | 
|  | 7314 | .fh = fh, | 
|  | 7315 | .layoutclass = server->pnfs_curr_ld->id, | 
|  | 7316 | }; | 
|  | 7317 | struct nfs4_getdevicelist_res res = { | 
|  | 7318 | .devlist = devlist, | 
|  | 7319 | }; | 
|  | 7320 | struct rpc_message msg = { | 
|  | 7321 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], | 
|  | 7322 | .rpc_argp = &args, | 
|  | 7323 | .rpc_resp = &res, | 
|  | 7324 | }; | 
|  | 7325 | int status; | 
|  | 7326 |  | 
|  | 7327 | dprintk("--> %s\n", __func__); | 
|  | 7328 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, | 
|  | 7329 | &res.seq_res, 0); | 
|  | 7330 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 7331 | return status; | 
|  | 7332 | } | 
|  | 7333 |  | 
|  | 7334 | int nfs4_proc_getdevicelist(struct nfs_server *server, | 
|  | 7335 | const struct nfs_fh *fh, | 
|  | 7336 | struct pnfs_devicelist *devlist) | 
|  | 7337 | { | 
|  | 7338 | struct nfs4_exception exception = { }; | 
|  | 7339 | int err; | 
|  | 7340 |  | 
|  | 7341 | do { | 
|  | 7342 | err = nfs4_handle_exception(server, | 
|  | 7343 | _nfs4_getdevicelist(server, fh, devlist), | 
|  | 7344 | &exception); | 
|  | 7345 | } while (exception.retry); | 
|  | 7346 |  | 
|  | 7347 | dprintk("%s: err=%d, num_devs=%u\n", __func__, | 
|  | 7348 | err, devlist->num_devs); | 
|  | 7349 |  | 
|  | 7350 | return err; | 
|  | 7351 | } | 
|  | 7352 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); | 
|  | 7353 |  | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7354 | static int | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7355 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, | 
|  | 7356 | struct pnfs_device *pdev, | 
|  | 7357 | struct rpc_cred *cred) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7358 | { | 
|  | 7359 | struct nfs4_getdeviceinfo_args args = { | 
|  | 7360 | .pdev = pdev, | 
|  | 7361 | }; | 
|  | 7362 | struct nfs4_getdeviceinfo_res res = { | 
|  | 7363 | .pdev = pdev, | 
|  | 7364 | }; | 
|  | 7365 | struct rpc_message msg = { | 
|  | 7366 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], | 
|  | 7367 | .rpc_argp = &args, | 
|  | 7368 | .rpc_resp = &res, | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7369 | .rpc_cred = cred, | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7370 | }; | 
|  | 7371 | int status; | 
|  | 7372 |  | 
|  | 7373 | dprintk("--> %s\n", __func__); | 
| Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 7374 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7375 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 7376 |  | 
|  | 7377 | return status; | 
|  | 7378 | } | 
|  | 7379 |  | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7380 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, | 
|  | 7381 | struct pnfs_device *pdev, | 
|  | 7382 | struct rpc_cred *cred) | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7383 | { | 
|  | 7384 | struct nfs4_exception exception = { }; | 
|  | 7385 | int err; | 
|  | 7386 |  | 
|  | 7387 | do { | 
|  | 7388 | err = nfs4_handle_exception(server, | 
| Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 7389 | _nfs4_proc_getdeviceinfo(server, pdev, cred), | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 7390 | &exception); | 
|  | 7391 | } while (exception.retry); | 
|  | 7392 | return err; | 
|  | 7393 | } | 
|  | 7394 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); | 
|  | 7395 |  | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7396 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) | 
|  | 7397 | { | 
|  | 7398 | struct nfs4_layoutcommit_data *data = calldata; | 
|  | 7399 | struct nfs_server *server = NFS_SERVER(data->args.inode); | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7400 | struct nfs4_session *session = nfs4_get_session(server); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7401 |  | 
| Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7402 | nfs41_setup_sequence(session, | 
|  | 7403 | &data->args.seq_args, | 
|  | 7404 | &data->res.seq_res, | 
|  | 7405 | task); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7406 | } | 
|  | 7407 |  | 
|  | 7408 | static void | 
|  | 7409 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) | 
|  | 7410 | { | 
|  | 7411 | struct nfs4_layoutcommit_data *data = calldata; | 
|  | 7412 | struct nfs_server *server = NFS_SERVER(data->args.inode); | 
|  | 7413 |  | 
| Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 7414 | if (!nfs41_sequence_done(task, &data->res.seq_res)) | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7415 | return; | 
|  | 7416 |  | 
|  | 7417 | switch (task->tk_status) { /* Just ignore these failures */ | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7418 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ | 
|  | 7419 | case -NFS4ERR_BADIOMODE:     /* no IOMODE_RW layout for range */ | 
|  | 7420 | case -NFS4ERR_BADLAYOUT:     /* no layout */ | 
|  | 7421 | case -NFS4ERR_GRACE:	    /* loca_recalim always false */ | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7422 | task->tk_status = 0; | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7423 | break; | 
|  | 7424 | case 0: | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7425 | nfs_post_op_update_inode_force_wcc(data->args.inode, | 
|  | 7426 | data->res.fattr); | 
| Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 7427 | break; | 
|  | 7428 | default: | 
|  | 7429 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { | 
|  | 7430 | rpc_restart_call_prepare(task); | 
|  | 7431 | return; | 
|  | 7432 | } | 
|  | 7433 | } | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7434 | } | 
|  | 7435 |  | 
|  | 7436 | static void nfs4_layoutcommit_release(void *calldata) | 
|  | 7437 | { | 
|  | 7438 | struct nfs4_layoutcommit_data *data = calldata; | 
|  | 7439 |  | 
| Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 7440 | pnfs_cleanup_layoutcommit(data); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7441 | put_rpccred(data->cred); | 
|  | 7442 | kfree(data); | 
|  | 7443 | } | 
|  | 7444 |  | 
|  | 7445 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { | 
|  | 7446 | .rpc_call_prepare = nfs4_layoutcommit_prepare, | 
|  | 7447 | .rpc_call_done = nfs4_layoutcommit_done, | 
|  | 7448 | .rpc_release = nfs4_layoutcommit_release, | 
|  | 7449 | }; | 
|  | 7450 |  | 
|  | 7451 | int | 
| Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7452 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7453 | { | 
|  | 7454 | struct rpc_message msg = { | 
|  | 7455 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], | 
|  | 7456 | .rpc_argp = &data->args, | 
|  | 7457 | .rpc_resp = &data->res, | 
|  | 7458 | .rpc_cred = data->cred, | 
|  | 7459 | }; | 
|  | 7460 | struct rpc_task_setup task_setup_data = { | 
|  | 7461 | .task = &data->task, | 
|  | 7462 | .rpc_client = NFS_CLIENT(data->args.inode), | 
|  | 7463 | .rpc_message = &msg, | 
|  | 7464 | .callback_ops = &nfs4_layoutcommit_ops, | 
|  | 7465 | .callback_data = data, | 
|  | 7466 | .flags = RPC_TASK_ASYNC, | 
|  | 7467 | }; | 
|  | 7468 | struct rpc_task *task; | 
|  | 7469 | int status = 0; | 
|  | 7470 |  | 
|  | 7471 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " | 
|  | 7472 | "lbw: %llu inode %lu\n", | 
|  | 7473 | data->task.tk_pid, sync, | 
|  | 7474 | data->args.lastbytewritten, | 
|  | 7475 | data->args.inode->i_ino); | 
|  | 7476 |  | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7477 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7478 | task = rpc_run_task(&task_setup_data); | 
|  | 7479 | if (IS_ERR(task)) | 
|  | 7480 | return PTR_ERR(task); | 
| Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 7481 | if (sync == false) | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7482 | goto out; | 
|  | 7483 | status = nfs4_wait_for_completion_rpc_task(task); | 
|  | 7484 | if (status != 0) | 
|  | 7485 | goto out; | 
|  | 7486 | status = task->tk_status; | 
| Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 7487 | trace_nfs4_layoutcommit(data->args.inode, status); | 
| Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 7488 | out: | 
|  | 7489 | dprintk("%s: status %d\n", __func__, status); | 
|  | 7490 | rpc_put_task(task); | 
|  | 7491 | return status; | 
|  | 7492 | } | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7493 |  | 
| Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 7494 | /** | 
|  | 7495 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if | 
|  | 7496 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections | 
|  | 7497 | */ | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7498 | static int | 
|  | 7499 | _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] | 7500 | struct nfs_fsinfo *info, | 
|  | 7501 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7502 | { | 
|  | 7503 | struct nfs41_secinfo_no_name_args args = { | 
|  | 7504 | .style = SECINFO_STYLE_CURRENT_FH, | 
|  | 7505 | }; | 
|  | 7506 | struct nfs4_secinfo_res res = { | 
|  | 7507 | .flavors = flavors, | 
|  | 7508 | }; | 
|  | 7509 | struct rpc_message msg = { | 
|  | 7510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], | 
|  | 7511 | .rpc_argp = &args, | 
|  | 7512 | .rpc_resp = &res, | 
|  | 7513 | }; | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7514 | struct rpc_clnt *clnt = server->client; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7515 | struct rpc_cred *cred = NULL; | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7516 | int status; | 
|  | 7517 |  | 
|  | 7518 | if (use_integrity) { | 
|  | 7519 | clnt = server->nfs_client->cl_rpcclient; | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7520 | cred = nfs4_get_clid_cred(server->nfs_client); | 
|  | 7521 | msg.rpc_cred = cred; | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7522 | } | 
|  | 7523 |  | 
|  | 7524 | dprintk("--> %s\n", __func__); | 
|  | 7525 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, | 
|  | 7526 | &res.seq_res, 0); | 
|  | 7527 | dprintk("<-- %s status=%d\n", __func__, status); | 
|  | 7528 |  | 
| Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7529 | if (cred) | 
|  | 7530 | put_rpccred(cred); | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7531 |  | 
|  | 7532 | return status; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7533 | } | 
|  | 7534 |  | 
|  | 7535 | static int | 
|  | 7536 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 7537 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) | 
|  | 7538 | { | 
|  | 7539 | struct nfs4_exception exception = { }; | 
|  | 7540 | int err; | 
|  | 7541 | do { | 
| Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 7542 | /* first try using integrity protection */ | 
|  | 7543 | err = -NFS4ERR_WRONGSEC; | 
|  | 7544 |  | 
|  | 7545 | /* try to use integrity protection with machine cred */ | 
|  | 7546 | if (_nfs4_is_integrity_protected(server->nfs_client)) | 
|  | 7547 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, | 
|  | 7548 | flavors, true); | 
|  | 7549 |  | 
|  | 7550 | /* | 
|  | 7551 | * if unable to use integrity protection, or SECINFO with | 
|  | 7552 | * integrity protection returns NFS4ERR_WRONGSEC (which is | 
|  | 7553 | * disallowed by spec, but exists in deployed servers) use | 
|  | 7554 | * the current filesystem's rpc_client and the user cred. | 
|  | 7555 | */ | 
|  | 7556 | if (err == -NFS4ERR_WRONGSEC) | 
|  | 7557 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, | 
|  | 7558 | flavors, false); | 
|  | 7559 |  | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7560 | switch (err) { | 
|  | 7561 | case 0: | 
|  | 7562 | case -NFS4ERR_WRONGSEC: | 
|  | 7563 | case -NFS4ERR_NOTSUPP: | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7564 | goto out; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7565 | default: | 
|  | 7566 | err = nfs4_handle_exception(server, err, &exception); | 
|  | 7567 | } | 
|  | 7568 | } while (exception.retry); | 
| Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 7569 | out: | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7570 | return err; | 
|  | 7571 | } | 
|  | 7572 |  | 
|  | 7573 | static int | 
|  | 7574 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 7575 | struct nfs_fsinfo *info) | 
|  | 7576 | { | 
|  | 7577 | int err; | 
|  | 7578 | struct page *page; | 
| Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 7579 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7580 | struct nfs4_secinfo_flavors *flavors; | 
| Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 7581 | struct nfs4_secinfo4 *secinfo; | 
|  | 7582 | int i; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7583 |  | 
|  | 7584 | page = alloc_page(GFP_KERNEL); | 
|  | 7585 | if (!page) { | 
|  | 7586 | err = -ENOMEM; | 
|  | 7587 | goto out; | 
|  | 7588 | } | 
|  | 7589 |  | 
|  | 7590 | flavors = page_address(page); | 
|  | 7591 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); | 
|  | 7592 |  | 
|  | 7593 | /* | 
|  | 7594 | * Fall back on "guess and check" method if | 
|  | 7595 | * the server doesn't support SECINFO_NO_NAME | 
|  | 7596 | */ | 
|  | 7597 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { | 
|  | 7598 | err = nfs4_find_root_sec(server, fhandle, info); | 
|  | 7599 | goto out_freepage; | 
|  | 7600 | } | 
|  | 7601 | if (err) | 
|  | 7602 | goto out_freepage; | 
|  | 7603 |  | 
| Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 7604 | for (i = 0; i < flavors->num_flavors; i++) { | 
|  | 7605 | secinfo = &flavors->flavors[i]; | 
|  | 7606 |  | 
|  | 7607 | switch (secinfo->flavor) { | 
|  | 7608 | case RPC_AUTH_NULL: | 
|  | 7609 | case RPC_AUTH_UNIX: | 
|  | 7610 | case RPC_AUTH_GSS: | 
|  | 7611 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, | 
|  | 7612 | &secinfo->flavor_info); | 
|  | 7613 | break; | 
|  | 7614 | default: | 
|  | 7615 | flavor = RPC_AUTH_MAXFLAVOR; | 
|  | 7616 | break; | 
|  | 7617 | } | 
|  | 7618 |  | 
|  | 7619 | if (flavor != RPC_AUTH_MAXFLAVOR) { | 
|  | 7620 | err = nfs4_lookup_root_sec(server, fhandle, | 
|  | 7621 | info, flavor); | 
|  | 7622 | if (!err) | 
|  | 7623 | break; | 
|  | 7624 | } | 
|  | 7625 | } | 
|  | 7626 |  | 
|  | 7627 | if (flavor == RPC_AUTH_MAXFLAVOR) | 
|  | 7628 | err = -EPERM; | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7629 |  | 
|  | 7630 | out_freepage: | 
|  | 7631 | put_page(page); | 
|  | 7632 | if (err == -EACCES) | 
|  | 7633 | return -EPERM; | 
|  | 7634 | out: | 
|  | 7635 | return err; | 
|  | 7636 | } | 
| Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7637 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7638 | static int _nfs41_test_stateid(struct nfs_server *server, | 
|  | 7639 | nfs4_stateid *stateid, | 
|  | 7640 | struct rpc_cred *cred) | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7641 | { | 
|  | 7642 | int status; | 
|  | 7643 | struct nfs41_test_stateid_args args = { | 
| Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7644 | .stateid = stateid, | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7645 | }; | 
|  | 7646 | struct nfs41_test_stateid_res res; | 
|  | 7647 | struct rpc_message msg = { | 
|  | 7648 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], | 
|  | 7649 | .rpc_argp = &args, | 
|  | 7650 | .rpc_resp = &res, | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7651 | .rpc_cred = cred, | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7652 | }; | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7653 | struct rpc_clnt *rpc_client = server->client; | 
|  | 7654 |  | 
|  | 7655 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, | 
|  | 7656 | &rpc_client, &msg); | 
| Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 7657 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7658 | dprintk("NFS call  test_stateid %p\n", stateid); | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7659 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7660 | nfs4_set_sequence_privileged(&args.seq_args); | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7661 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, | 
| Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7662 | &args.seq_args, &res.seq_res); | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7663 | if (status != NFS_OK) { | 
|  | 7664 | dprintk("NFS reply test_stateid: failed, %d\n", status); | 
| Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7665 | return status; | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7666 | } | 
|  | 7667 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); | 
| Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7668 | return -res.status; | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7669 | } | 
|  | 7670 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7671 | /** | 
|  | 7672 | * nfs41_test_stateid - perform a TEST_STATEID operation | 
|  | 7673 | * | 
|  | 7674 | * @server: server / transport on which to perform the operation | 
|  | 7675 | * @stateid: state ID to test | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7676 | * @cred: credential | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7677 | * | 
|  | 7678 | * Returns NFS_OK if the server recognizes that "stateid" is valid. | 
|  | 7679 | * Otherwise a negative NFS4ERR value is returned if the operation | 
|  | 7680 | * failed or the state ID is not currently valid. | 
|  | 7681 | */ | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7682 | static int nfs41_test_stateid(struct nfs_server *server, | 
|  | 7683 | nfs4_stateid *stateid, | 
|  | 7684 | struct rpc_cred *cred) | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7685 | { | 
|  | 7686 | struct nfs4_exception exception = { }; | 
|  | 7687 | int err; | 
|  | 7688 | do { | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7689 | err = _nfs41_test_stateid(server, stateid, cred); | 
| Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 7690 | if (err != -NFS4ERR_DELAY) | 
|  | 7691 | break; | 
|  | 7692 | nfs4_handle_exception(server, err, &exception); | 
| Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 7693 | } while (exception.retry); | 
|  | 7694 | return err; | 
|  | 7695 | } | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7696 |  | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7697 | struct nfs_free_stateid_data { | 
|  | 7698 | struct nfs_server *server; | 
|  | 7699 | struct nfs41_free_stateid_args args; | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7700 | struct nfs41_free_stateid_res res; | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7701 | }; | 
|  | 7702 |  | 
|  | 7703 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) | 
|  | 7704 | { | 
|  | 7705 | struct nfs_free_stateid_data *data = calldata; | 
|  | 7706 | nfs41_setup_sequence(nfs4_get_session(data->server), | 
|  | 7707 | &data->args.seq_args, | 
|  | 7708 | &data->res.seq_res, | 
|  | 7709 | task); | 
|  | 7710 | } | 
|  | 7711 |  | 
|  | 7712 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) | 
|  | 7713 | { | 
|  | 7714 | struct nfs_free_stateid_data *data = calldata; | 
|  | 7715 |  | 
|  | 7716 | nfs41_sequence_done(task, &data->res.seq_res); | 
|  | 7717 |  | 
|  | 7718 | switch (task->tk_status) { | 
|  | 7719 | case -NFS4ERR_DELAY: | 
|  | 7720 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) | 
|  | 7721 | rpc_restart_call_prepare(task); | 
|  | 7722 | } | 
|  | 7723 | } | 
|  | 7724 |  | 
|  | 7725 | static void nfs41_free_stateid_release(void *calldata) | 
|  | 7726 | { | 
|  | 7727 | kfree(calldata); | 
|  | 7728 | } | 
|  | 7729 |  | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7730 | static const struct rpc_call_ops nfs41_free_stateid_ops = { | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7731 | .rpc_call_prepare = nfs41_free_stateid_prepare, | 
|  | 7732 | .rpc_call_done = nfs41_free_stateid_done, | 
|  | 7733 | .rpc_release = nfs41_free_stateid_release, | 
|  | 7734 | }; | 
|  | 7735 |  | 
|  | 7736 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, | 
|  | 7737 | nfs4_stateid *stateid, | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7738 | struct rpc_cred *cred, | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7739 | bool privileged) | 
|  | 7740 | { | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7741 | struct rpc_message msg = { | 
|  | 7742 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7743 | .rpc_cred = cred, | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7744 | }; | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7745 | struct rpc_task_setup task_setup = { | 
|  | 7746 | .rpc_client = server->client, | 
|  | 7747 | .rpc_message = &msg, | 
|  | 7748 | .callback_ops = &nfs41_free_stateid_ops, | 
|  | 7749 | .flags = RPC_TASK_ASYNC, | 
|  | 7750 | }; | 
|  | 7751 | struct nfs_free_stateid_data *data; | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7752 |  | 
| Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7753 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, | 
|  | 7754 | &task_setup.rpc_client, &msg); | 
|  | 7755 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7756 | dprintk("NFS call  free_stateid %p\n", stateid); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7757 | data = kmalloc(sizeof(*data), GFP_NOFS); | 
|  | 7758 | if (!data) | 
|  | 7759 | return ERR_PTR(-ENOMEM); | 
|  | 7760 | data->server = server; | 
|  | 7761 | nfs4_stateid_copy(&data->args.stateid, stateid); | 
|  | 7762 |  | 
|  | 7763 | task_setup.callback_data = data; | 
|  | 7764 |  | 
|  | 7765 | msg.rpc_argp = &data->args; | 
|  | 7766 | msg.rpc_resp = &data->res; | 
| Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7767 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7768 | if (privileged) | 
|  | 7769 | nfs4_set_sequence_privileged(&data->args.seq_args); | 
|  | 7770 |  | 
|  | 7771 | return rpc_run_task(&task_setup); | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7772 | } | 
|  | 7773 |  | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7774 | /** | 
|  | 7775 | * nfs41_free_stateid - perform a FREE_STATEID operation | 
|  | 7776 | * | 
|  | 7777 | * @server: server / transport on which to perform the operation | 
|  | 7778 | * @stateid: state ID to release | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7779 | * @cred: credential | 
| Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 7780 | * | 
|  | 7781 | * Returns NFS_OK if the server freed "stateid".  Otherwise a | 
|  | 7782 | * negative NFS4ERR value is returned. | 
|  | 7783 | */ | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7784 | static int nfs41_free_stateid(struct nfs_server *server, | 
|  | 7785 | nfs4_stateid *stateid, | 
|  | 7786 | struct rpc_cred *cred) | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7787 | { | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7788 | struct rpc_task *task; | 
|  | 7789 | int ret; | 
|  | 7790 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7791 | task = _nfs41_free_stateid(server, stateid, cred, true); | 
| Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 7792 | if (IS_ERR(task)) | 
|  | 7793 | return PTR_ERR(task); | 
|  | 7794 | ret = rpc_wait_for_completion_task(task); | 
|  | 7795 | if (!ret) | 
|  | 7796 | ret = task->tk_status; | 
|  | 7797 | rpc_put_task(task); | 
|  | 7798 | return ret; | 
| Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 7799 | } | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7800 |  | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7801 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) | 
|  | 7802 | { | 
|  | 7803 | struct rpc_task *task; | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7804 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7805 |  | 
| Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 7806 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7807 | nfs4_free_lock_state(server, lsp); | 
|  | 7808 | if (IS_ERR(task)) | 
|  | 7809 | return PTR_ERR(task); | 
|  | 7810 | rpc_put_task(task); | 
|  | 7811 | return 0; | 
|  | 7812 | } | 
|  | 7813 |  | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7814 | static bool nfs41_match_stateid(const nfs4_stateid *s1, | 
|  | 7815 | const nfs4_stateid *s2) | 
|  | 7816 | { | 
| Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7817 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7818 | return false; | 
|  | 7819 |  | 
| Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7820 | if (s1->seqid == s2->seqid) | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7821 | return true; | 
| Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 7822 | if (s1->seqid == 0 || s2->seqid == 0) | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7823 | return true; | 
|  | 7824 |  | 
|  | 7825 | return false; | 
|  | 7826 | } | 
|  | 7827 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7828 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 7829 |  | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7830 | static bool nfs4_match_stateid(const nfs4_stateid *s1, | 
|  | 7831 | const nfs4_stateid *s2) | 
|  | 7832 | { | 
| Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7833 | return nfs4_stateid_match(s1, s2); | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7834 | } | 
|  | 7835 |  | 
|  | 7836 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7837 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { | 
| Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7838 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, | 
| Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7839 | .state_flag_bit	= NFS_STATE_RECLAIM_REBOOT, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7840 | .recover_open	= nfs4_open_reclaim, | 
|  | 7841 | .recover_lock	= nfs4_lock_reclaim, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7842 | .establish_clid = nfs4_init_clientid, | 
| Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7843 | .detect_trunking = nfs40_discover_server_trunking, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7844 | }; | 
|  | 7845 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7846 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7847 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7848 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, | 
|  | 7849 | .state_flag_bit	= NFS_STATE_RECLAIM_REBOOT, | 
|  | 7850 | .recover_open	= nfs4_open_reclaim, | 
|  | 7851 | .recover_lock	= nfs4_lock_reclaim, | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7852 | .establish_clid = nfs41_init_clientid, | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 7853 | .reclaim_complete = nfs41_proc_reclaim_complete, | 
| Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7854 | .detect_trunking = nfs41_discover_server_trunking, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7855 | }; | 
|  | 7856 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 7857 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7858 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { | 
| Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 7859 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, | 
| Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 7860 | .state_flag_bit	= NFS_STATE_RECLAIM_NOGRACE, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7861 | .recover_open	= nfs4_open_expired, | 
|  | 7862 | .recover_lock	= nfs4_lock_expired, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7863 | .establish_clid = nfs4_init_clientid, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7864 | }; | 
|  | 7865 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7866 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7867 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7868 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, | 
|  | 7869 | .state_flag_bit	= NFS_STATE_RECLAIM_NOGRACE, | 
| Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7870 | .recover_open	= nfs41_open_expired, | 
|  | 7871 | .recover_lock	= nfs41_lock_expired, | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7872 | .establish_clid = nfs41_init_clientid, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7873 | }; | 
|  | 7874 | #endif /* CONFIG_NFS_V4_1 */ | 
|  | 7875 |  | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7876 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7877 | .sched_state_renewal = nfs4_proc_async_renew, | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7878 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, | 
| Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7879 | .renew_lease = nfs4_proc_renew, | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7880 | }; | 
|  | 7881 |  | 
|  | 7882 | #if defined(CONFIG_NFS_V4_1) | 
| Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7883 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7884 | .sched_state_renewal = nfs41_proc_async_sequence, | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7885 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, | 
| Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7886 | .renew_lease = nfs4_proc_sequence, | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7887 | }; | 
|  | 7888 | #endif | 
|  | 7889 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7890 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { | 
|  | 7891 | .minor_version = 0, | 
| Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7892 | .init_caps = NFS_CAP_READDIRPLUS | 
|  | 7893 | | NFS_CAP_ATOMIC_OPEN | 
|  | 7894 | | NFS_CAP_CHANGE_ATTR | 
|  | 7895 | | NFS_CAP_POSIX_LOCK, | 
| Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 7896 | .init_client = nfs40_init_client, | 
|  | 7897 | .shutdown_client = nfs40_shutdown_client, | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7898 | .match_stateid = nfs4_match_stateid, | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7899 | .find_root_sec = nfs4_find_root_sec, | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7900 | .free_lock_state = nfs4_release_lockowner, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 7901 | .call_sync_ops = &nfs40_call_sync_ops, | 
| Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7902 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, | 
|  | 7903 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, | 
|  | 7904 | .state_renewal_ops = &nfs40_state_renewal_ops, | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7905 | }; | 
|  | 7906 |  | 
|  | 7907 | #if defined(CONFIG_NFS_V4_1) | 
|  | 7908 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { | 
|  | 7909 | .minor_version = 1, | 
| Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7910 | .init_caps = NFS_CAP_READDIRPLUS | 
|  | 7911 | | NFS_CAP_ATOMIC_OPEN | 
|  | 7912 | | NFS_CAP_CHANGE_ATTR | 
| Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7913 | | NFS_CAP_POSIX_LOCK | 
| Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7914 | | NFS_CAP_STATEID_NFSV41 | 
|  | 7915 | | NFS_CAP_ATOMIC_OPEN_V1, | 
| Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 7916 | .init_client = nfs41_init_client, | 
|  | 7917 | .shutdown_client = nfs41_shutdown_client, | 
| Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7918 | .match_stateid = nfs41_match_stateid, | 
| Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7919 | .find_root_sec = nfs41_find_root_sec, | 
| Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7920 | .free_lock_state = nfs41_free_lock_state, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 7921 | .call_sync_ops = &nfs41_call_sync_ops, | 
| Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7922 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 
|  | 7923 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 
|  | 7924 | .state_renewal_ops = &nfs41_state_renewal_ops, | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7925 | }; | 
|  | 7926 | #endif | 
|  | 7927 |  | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7928 | #if defined(CONFIG_NFS_V4_2) | 
|  | 7929 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { | 
|  | 7930 | .minor_version = 2, | 
| Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7931 | .init_caps = NFS_CAP_READDIRPLUS | 
|  | 7932 | | NFS_CAP_ATOMIC_OPEN | 
|  | 7933 | | NFS_CAP_CHANGE_ATTR | 
|  | 7934 | | NFS_CAP_POSIX_LOCK | 
|  | 7935 | | NFS_CAP_STATEID_NFSV41 | 
|  | 7936 | | NFS_CAP_ATOMIC_OPEN_V1, | 
| Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 7937 | .init_client = nfs41_init_client, | 
|  | 7938 | .shutdown_client = nfs41_shutdown_client, | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7939 | .match_stateid = nfs41_match_stateid, | 
|  | 7940 | .find_root_sec = nfs41_find_root_sec, | 
| Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 7941 | .free_lock_state = nfs41_free_lock_state, | 
| Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 7942 | .call_sync_ops = &nfs41_call_sync_ops, | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7943 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 
|  | 7944 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 
|  | 7945 | .state_renewal_ops = &nfs41_state_renewal_ops, | 
|  | 7946 | }; | 
|  | 7947 | #endif | 
|  | 7948 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7949 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { | 
|  | 7950 | [0] = &nfs_v4_0_minor_ops, | 
|  | 7951 | #if defined(CONFIG_NFS_V4_1) | 
|  | 7952 | [1] = &nfs_v4_1_minor_ops, | 
|  | 7953 | #endif | 
| Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 7954 | #if defined(CONFIG_NFS_V4_2) | 
|  | 7955 | [2] = &nfs_v4_2_minor_ops, | 
|  | 7956 | #endif | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7957 | }; | 
|  | 7958 |  | 
| Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 7959 | static const struct inode_operations nfs4_dir_inode_operations = { | 
| Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7960 | .create		= nfs_create, | 
|  | 7961 | .lookup		= nfs_lookup, | 
|  | 7962 | .atomic_open	= nfs_atomic_open, | 
|  | 7963 | .link		= nfs_link, | 
|  | 7964 | .unlink		= nfs_unlink, | 
|  | 7965 | .symlink	= nfs_symlink, | 
|  | 7966 | .mkdir		= nfs_mkdir, | 
|  | 7967 | .rmdir		= nfs_rmdir, | 
|  | 7968 | .mknod		= nfs_mknod, | 
|  | 7969 | .rename		= nfs_rename, | 
|  | 7970 | .permission	= nfs_permission, | 
|  | 7971 | .getattr	= nfs_getattr, | 
|  | 7972 | .setattr	= nfs_setattr, | 
|  | 7973 | .getxattr	= generic_getxattr, | 
|  | 7974 | .setxattr	= generic_setxattr, | 
|  | 7975 | .listxattr	= generic_listxattr, | 
|  | 7976 | .removexattr	= generic_removexattr, | 
|  | 7977 | }; | 
|  | 7978 |  | 
| Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7979 | static const struct inode_operations nfs4_file_inode_operations = { | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7980 | .permission	= nfs_permission, | 
|  | 7981 | .getattr	= nfs_getattr, | 
|  | 7982 | .setattr	= nfs_setattr, | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7983 | .getxattr	= generic_getxattr, | 
|  | 7984 | .setxattr	= generic_setxattr, | 
|  | 7985 | .listxattr	= generic_listxattr, | 
|  | 7986 | .removexattr	= generic_removexattr, | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7987 | }; | 
|  | 7988 |  | 
| David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7989 | const struct nfs_rpc_ops nfs_v4_clientops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7990 | .version	= 4,			/* protocol version */ | 
|  | 7991 | .dentry_ops	= &nfs4_dentry_operations, | 
|  | 7992 | .dir_inode_ops	= &nfs4_dir_inode_operations, | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7993 | .file_inode_ops	= &nfs4_file_inode_operations, | 
| Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7994 | .file_ops	= &nfs4_file_operations, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7995 | .getroot	= nfs4_proc_get_root, | 
| Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7996 | .submount	= nfs4_submount, | 
| Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7997 | .try_mount	= nfs4_try_mount, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7998 | .getattr	= nfs4_proc_getattr, | 
|  | 7999 | .setattr	= nfs4_proc_setattr, | 
|  | 8000 | .lookup		= nfs4_proc_lookup, | 
|  | 8001 | .access		= nfs4_proc_access, | 
|  | 8002 | .readlink	= nfs4_proc_readlink, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8003 | .create		= nfs4_proc_create, | 
|  | 8004 | .remove		= nfs4_proc_remove, | 
|  | 8005 | .unlink_setup	= nfs4_proc_unlink_setup, | 
| Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 8006 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8007 | .unlink_done	= nfs4_proc_unlink_done, | 
|  | 8008 | .rename		= nfs4_proc_rename, | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8009 | .rename_setup	= nfs4_proc_rename_setup, | 
| Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 8010 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 8011 | .rename_done	= nfs4_proc_rename_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8012 | .link		= nfs4_proc_link, | 
|  | 8013 | .symlink	= nfs4_proc_symlink, | 
|  | 8014 | .mkdir		= nfs4_proc_mkdir, | 
|  | 8015 | .rmdir		= nfs4_proc_remove, | 
|  | 8016 | .readdir	= nfs4_proc_readdir, | 
|  | 8017 | .mknod		= nfs4_proc_mknod, | 
|  | 8018 | .statfs		= nfs4_proc_statfs, | 
|  | 8019 | .fsinfo		= nfs4_proc_fsinfo, | 
|  | 8020 | .pathconf	= nfs4_proc_pathconf, | 
| David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 8021 | .set_capabilities = nfs4_server_capabilities, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8022 | .decode_dirent	= nfs4_decode_dirent, | 
|  | 8023 | .read_setup	= nfs4_proc_read_setup, | 
| Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 8024 | .read_pageio_init = pnfs_pageio_init_read, | 
| Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 8025 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8026 | .read_done	= nfs4_read_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8027 | .write_setup	= nfs4_proc_write_setup, | 
| Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 8028 | .write_pageio_init = pnfs_pageio_init_write, | 
| Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 8029 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8030 | .write_done	= nfs4_write_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8031 | .commit_setup	= nfs4_proc_commit_setup, | 
| Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 8032 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 8033 | .commit_done	= nfs4_commit_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8034 | .lock		= nfs4_proc_lock, | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 8035 | .clear_acl_cache = nfs4_zap_acl_attr, | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 8036 | .close_context  = nfs4_close_context, | 
| Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 8037 | .open_context	= nfs4_atomic_open, | 
| Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 8038 | .have_delegation = nfs4_have_delegation, | 
| Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 8039 | .return_delegation = nfs4_inode_return_delegation, | 
| Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 8040 | .alloc_client	= nfs4_alloc_client, | 
| Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 8041 | .init_client	= nfs4_init_client, | 
| Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 8042 | .free_client	= nfs4_free_client, | 
| Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 8043 | .create_server	= nfs4_create_server, | 
|  | 8044 | .clone_server	= nfs_clone_server, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8045 | }; | 
|  | 8046 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8047 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { | 
|  | 8048 | .prefix	= XATTR_NAME_NFSV4_ACL, | 
|  | 8049 | .list	= nfs4_xattr_list_nfs4_acl, | 
|  | 8050 | .get	= nfs4_xattr_get_nfs4_acl, | 
|  | 8051 | .set	= nfs4_xattr_set_nfs4_acl, | 
|  | 8052 | }; | 
|  | 8053 |  | 
|  | 8054 | const struct xattr_handler *nfs4_xattr_handlers[] = { | 
|  | 8055 | &nfs4_xattr_nfs4_acl_handler, | 
| David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 8056 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL | 
|  | 8057 | &nfs4_xattr_nfs4_label_handler, | 
|  | 8058 | #endif | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 8059 | NULL | 
|  | 8060 | }; | 
|  | 8061 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8062 | /* | 
|  | 8063 | * Local variables: | 
|  | 8064 | *  c-basic-offset: 8 | 
|  | 8065 | * End: | 
|  | 8066 | */ |