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 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 74 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 75 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 76 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | 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] | 78 | 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] | 79 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 80 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 81 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 82 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 83 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 84 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 85 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 86 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 87 | struct rpc_cred *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 89 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 90 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 92 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 94 | if (err >= -1000) |
| 95 | return err; |
| 96 | switch (err) { |
| 97 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 98 | case -NFS4ERR_LAYOUTTRYLATER: |
| 99 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 101 | case -NFS4ERR_WRONGSEC: |
| 102 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 103 | case -NFS4ERR_BADOWNER: |
| 104 | case -NFS4ERR_BADNAME: |
| 105 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 106 | case -NFS4ERR_SHARE_DENIED: |
| 107 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 108 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 109 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 110 | case -NFS4ERR_ACCESS: |
| 111 | return -EACCES; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 112 | case -NFS4ERR_FILE_OPEN: |
| 113 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 114 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 116 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 117 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 119 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * This is our standard bitmap for GETATTR requests. |
| 124 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 125 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | FATTR4_WORD0_TYPE |
| 127 | | FATTR4_WORD0_CHANGE |
| 128 | | FATTR4_WORD0_SIZE |
| 129 | | FATTR4_WORD0_FSID |
| 130 | | FATTR4_WORD0_FILEID, |
| 131 | FATTR4_WORD1_MODE |
| 132 | | FATTR4_WORD1_NUMLINKS |
| 133 | | FATTR4_WORD1_OWNER |
| 134 | | FATTR4_WORD1_OWNER_GROUP |
| 135 | | FATTR4_WORD1_RAWDEV |
| 136 | | FATTR4_WORD1_SPACE_USED |
| 137 | | FATTR4_WORD1_TIME_ACCESS |
| 138 | | FATTR4_WORD1_TIME_METADATA |
| 139 | | FATTR4_WORD1_TIME_MODIFY |
| 140 | }; |
| 141 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 142 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 143 | FATTR4_WORD0_TYPE |
| 144 | | FATTR4_WORD0_CHANGE |
| 145 | | FATTR4_WORD0_SIZE |
| 146 | | FATTR4_WORD0_FSID |
| 147 | | FATTR4_WORD0_FILEID, |
| 148 | FATTR4_WORD1_MODE |
| 149 | | FATTR4_WORD1_NUMLINKS |
| 150 | | FATTR4_WORD1_OWNER |
| 151 | | FATTR4_WORD1_OWNER_GROUP |
| 152 | | FATTR4_WORD1_RAWDEV |
| 153 | | FATTR4_WORD1_SPACE_USED |
| 154 | | FATTR4_WORD1_TIME_ACCESS |
| 155 | | FATTR4_WORD1_TIME_METADATA |
| 156 | | FATTR4_WORD1_TIME_MODIFY, |
| 157 | FATTR4_WORD2_MDSTHRESHOLD |
| 158 | }; |
| 159 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 160 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 161 | FATTR4_WORD0_TYPE |
| 162 | | FATTR4_WORD0_CHANGE |
| 163 | | FATTR4_WORD0_FILEID, |
| 164 | }; |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | const u32 nfs4_statfs_bitmap[2] = { |
| 167 | FATTR4_WORD0_FILES_AVAIL |
| 168 | | FATTR4_WORD0_FILES_FREE |
| 169 | | FATTR4_WORD0_FILES_TOTAL, |
| 170 | FATTR4_WORD1_SPACE_AVAIL |
| 171 | | FATTR4_WORD1_SPACE_FREE |
| 172 | | FATTR4_WORD1_SPACE_TOTAL |
| 173 | }; |
| 174 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 175 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | FATTR4_WORD0_MAXLINK |
| 177 | | FATTR4_WORD0_MAXNAME, |
| 178 | 0 |
| 179 | }; |
| 180 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 181 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | | FATTR4_WORD0_MAXREAD |
| 183 | | FATTR4_WORD0_MAXWRITE |
| 184 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 185 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 186 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 187 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 190 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 191 | FATTR4_WORD0_TYPE |
| 192 | | FATTR4_WORD0_CHANGE |
| 193 | | FATTR4_WORD0_SIZE |
| 194 | | FATTR4_WORD0_FSID |
| 195 | | FATTR4_WORD0_FILEID |
| 196 | | FATTR4_WORD0_FS_LOCATIONS, |
| 197 | FATTR4_WORD1_MODE |
| 198 | | FATTR4_WORD1_NUMLINKS |
| 199 | | FATTR4_WORD1_OWNER |
| 200 | | FATTR4_WORD1_OWNER_GROUP |
| 201 | | FATTR4_WORD1_RAWDEV |
| 202 | | FATTR4_WORD1_SPACE_USED |
| 203 | | FATTR4_WORD1_TIME_ACCESS |
| 204 | | FATTR4_WORD1_TIME_METADATA |
| 205 | | FATTR4_WORD1_TIME_MODIFY |
| 206 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 207 | }; |
| 208 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 209 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | struct nfs4_readdir_arg *readdir) |
| 211 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 212 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 215 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | readdir->cookie = 0; |
| 221 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 222 | if (cookie == 2) |
| 223 | return; |
| 224 | |
| 225 | /* |
| 226 | * NFSv4 servers do not return entries for '.' and '..' |
| 227 | * Therefore, we fake these entries here. We let '.' |
| 228 | * have cookie 0 and '..' have cookie 1. Note that |
| 229 | * when talking to the server, we always send cookie 0 |
| 230 | * instead of 1 or 2. |
| 231 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 232 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | if (cookie == 0) { |
| 235 | *p++ = xdr_one; /* next */ |
| 236 | *p++ = xdr_zero; /* cookie, first word */ |
| 237 | *p++ = xdr_one; /* cookie, second word */ |
| 238 | *p++ = xdr_one; /* entry len */ |
| 239 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 240 | p++; |
| 241 | *p++ = xdr_one; /* bitmap length */ |
| 242 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 243 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 244 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | *p++ = xdr_one; /* next */ |
| 248 | *p++ = xdr_zero; /* cookie, first word */ |
| 249 | *p++ = xdr_two; /* cookie, second word */ |
| 250 | *p++ = xdr_two; /* entry len */ |
| 251 | memcpy(p, "..\0\0", 4); /* entry */ |
| 252 | p++; |
| 253 | *p++ = xdr_one; /* bitmap length */ |
| 254 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 255 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 256 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | readdir->pgbase = (char *)p - (char *)start; |
| 259 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 260 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 263 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 264 | { |
| 265 | int res = 0; |
| 266 | |
| 267 | might_sleep(); |
| 268 | |
| 269 | if (*timeout <= 0) |
| 270 | *timeout = NFS4_POLL_RETRY_MIN; |
| 271 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 272 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 273 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 274 | if (fatal_signal_pending(current)) |
| 275 | res = -ERESTARTSYS; |
| 276 | *timeout <<= 1; |
| 277 | return res; |
| 278 | } |
| 279 | |
| 280 | /* This is the error handling routine for processes that are allowed |
| 281 | * to sleep. |
| 282 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 283 | 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] | 284 | { |
| 285 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 286 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 287 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 288 | int ret = errorcode; |
| 289 | |
| 290 | exception->retry = 0; |
| 291 | switch(errorcode) { |
| 292 | case 0: |
| 293 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 294 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 295 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 296 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 297 | exception->retry = 1; |
| 298 | return 0; |
| 299 | } |
| 300 | if (state == NULL) |
| 301 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 302 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 303 | if (ret < 0) |
| 304 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 305 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 306 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 307 | case -NFS4ERR_ADMIN_REVOKED: |
| 308 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | b570a97 | 2013-04-12 15:04:51 -0400 | [diff] [blame] | 309 | if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) { |
| 310 | nfs_remove_bad_delegation(inode); |
| 311 | exception->retry = 1; |
| 312 | break; |
| 313 | } |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 314 | if (state == NULL) |
| 315 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 316 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 317 | if (ret < 0) |
| 318 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 319 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 320 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 321 | if (state != NULL) { |
| 322 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 323 | if (ret < 0) |
| 324 | break; |
| 325 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 327 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 328 | nfs4_schedule_lease_recovery(clp); |
| 329 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 330 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 331 | case -NFS4ERR_BADSESSION: |
| 332 | case -NFS4ERR_BADSLOT: |
| 333 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 334 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 335 | case -NFS4ERR_DEADSESSION: |
| 336 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 337 | case -NFS4ERR_SEQ_MISORDERED: |
| 338 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 339 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 340 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 341 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 342 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 344 | if (exception->timeout > HZ) { |
| 345 | /* We have retried a decent amount, time to |
| 346 | * fail |
| 347 | */ |
| 348 | ret = -EBUSY; |
| 349 | break; |
| 350 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 351 | case -NFS4ERR_GRACE: |
| 352 | case -NFS4ERR_DELAY: |
| 353 | ret = nfs4_delay(server->client, &exception->timeout); |
| 354 | if (ret != 0) |
| 355 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 356 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 357 | case -NFS4ERR_OLD_STATEID: |
| 358 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 359 | break; |
| 360 | case -NFS4ERR_BADOWNER: |
| 361 | /* The following works around a Linux server bug! */ |
| 362 | case -NFS4ERR_BADNAME: |
| 363 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 364 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 365 | exception->retry = 1; |
| 366 | printk(KERN_WARNING "NFS: v4 server %s " |
| 367 | "does not accept raw " |
| 368 | "uid/gids. " |
| 369 | "Reenabling the idmapper.\n", |
| 370 | server->nfs_client->cl_hostname); |
| 371 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | } |
| 373 | /* We failed to handle the error */ |
| 374 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 375 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 376 | ret = nfs4_wait_clnt_recover(clp); |
| 377 | if (ret == 0) |
| 378 | exception->retry = 1; |
| 379 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 383 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | spin_lock(&clp->cl_lock); |
| 386 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 387 | clp->cl_last_renewal = timestamp; |
| 388 | spin_unlock(&clp->cl_lock); |
| 389 | } |
| 390 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 391 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 392 | { |
| 393 | do_renew_lease(server->nfs_client, timestamp); |
| 394 | } |
| 395 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 396 | #if defined(CONFIG_NFS_V4_1) |
| 397 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 398 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 399 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 400 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 401 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 402 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 403 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 404 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 405 | /* just wake up the next guy waiting since |
| 406 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 407 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 408 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 409 | } |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 410 | tbl = res->sr_slot->table; |
| 411 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 412 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 413 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 414 | /* Be nice to the server: try to ensure that the last transmitted |
| 415 | * value for highest_user_slotid <= target_highest_slotid |
| 416 | */ |
| 417 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 418 | send_new_highest_used_slotid = true; |
| 419 | |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 420 | if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { |
| 421 | send_new_highest_used_slotid = false; |
| 422 | goto out_unlock; |
| 423 | } |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 424 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 425 | |
| 426 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 427 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 428 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 429 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 430 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 431 | if (send_new_highest_used_slotid) |
| 432 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 435 | 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] | 436 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 437 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 438 | struct nfs4_slot *slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 440 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 441 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 442 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 443 | /* don't increment the sequence number if the task wasn't sent */ |
| 444 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 445 | goto out; |
| 446 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 447 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 448 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 449 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 450 | if (slot->interrupted) { |
| 451 | slot->interrupted = 0; |
| 452 | interrupted = true; |
| 453 | } |
| 454 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 455 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | switch (res->sr_status) { |
| 457 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 458 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 459 | ++slot->seq_nr; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 460 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 461 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 462 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 463 | if (res->sr_status_flags != 0) |
| 464 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 465 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 466 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 467 | case 1: |
| 468 | /* |
| 469 | * sr_status remains 1 if an RPC level error occurred. |
| 470 | * The server may or may not have processed the sequence |
| 471 | * operation.. |
| 472 | * Mark the slot as having hosted an interrupted RPC call. |
| 473 | */ |
| 474 | slot->interrupted = 1; |
| 475 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 476 | case -NFS4ERR_DELAY: |
| 477 | /* The server detected a resend of the RPC call and |
| 478 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 479 | * of RFC5661. |
| 480 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 481 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 482 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 483 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 484 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 485 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 486 | case -NFS4ERR_BADSLOT: |
| 487 | /* |
| 488 | * The slot id we used was probably retired. Try again |
| 489 | * using a different slot id. |
| 490 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 491 | goto retry_nowait; |
| 492 | case -NFS4ERR_SEQ_MISORDERED: |
| 493 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 494 | * Was the last operation on this sequence interrupted? |
| 495 | * If so, retry after bumping the sequence number. |
| 496 | */ |
| 497 | if (interrupted) { |
| 498 | ++slot->seq_nr; |
| 499 | goto retry_nowait; |
| 500 | } |
| 501 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 502 | * Could this slot have been previously retired? |
| 503 | * If so, then the server may be expecting seq_nr = 1! |
| 504 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 505 | if (slot->seq_nr != 1) { |
| 506 | slot->seq_nr = 1; |
| 507 | goto retry_nowait; |
| 508 | } |
| 509 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 510 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 511 | ++slot->seq_nr; |
| 512 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | default: |
| 514 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 515 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 516 | } |
| 517 | out: |
| 518 | /* The session may be reset by one of the error handlers. */ |
| 519 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 520 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 521 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 522 | retry_nowait: |
| 523 | if (rpc_restart_call_prepare(task)) { |
| 524 | task->tk_status = 0; |
| 525 | ret = 0; |
| 526 | } |
| 527 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 528 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 529 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 530 | goto out; |
| 531 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 532 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 535 | static int nfs4_sequence_done(struct rpc_task *task, |
| 536 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 537 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 538 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 539 | return 1; |
| 540 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 541 | } |
| 542 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 543 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 544 | struct nfs4_sequence_res *res, int cache_reply) |
| 545 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 546 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 547 | args->sa_cache_this = 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 548 | args->sa_privileged = 0; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 549 | if (cache_reply) |
| 550 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 551 | res->sr_slot = NULL; |
| 552 | } |
| 553 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 554 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 555 | { |
| 556 | args->sa_privileged = 1; |
| 557 | } |
| 558 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 559 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 560 | struct nfs4_sequence_args *args, |
| 561 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 562 | struct rpc_task *task) |
| 563 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | struct nfs4_slot *slot; |
| 565 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 566 | |
| 567 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 568 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 569 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 570 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 571 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 572 | tbl = &session->fc_slot_table; |
| 573 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 574 | task->tk_timeout = 0; |
| 575 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 576 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 577 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 578 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 579 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 580 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 581 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 582 | } |
| 583 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 584 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 585 | if (IS_ERR(slot)) { |
| 586 | /* If out of memory, try again in 1/4 second */ |
| 587 | if (slot == ERR_PTR(-ENOMEM)) |
| 588 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 589 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 590 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 591 | } |
| 592 | spin_unlock(&tbl->slot_tbl_lock); |
| 593 | |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 594 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 595 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 596 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 597 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 598 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 599 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 600 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 601 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 602 | /* |
| 603 | * sr_status is only set in decode_sequence, and so will remain |
| 604 | * set to 1 if an rpc level failure occurs. |
| 605 | */ |
| 606 | res->sr_status = 1; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 607 | out_success: |
| 608 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 609 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 610 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 611 | /* Privileged tasks are queued with top priority */ |
| 612 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 613 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 614 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 615 | else |
| 616 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 617 | spin_unlock(&tbl->slot_tbl_lock); |
| 618 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 620 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 621 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 622 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | struct nfs4_sequence_args *args, |
| 624 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | struct rpc_task *task) |
| 626 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 627 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 628 | int ret = 0; |
| 629 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 630 | if (session == NULL) { |
| 631 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | goto out; |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 633 | } |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 634 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 635 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 636 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 637 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 638 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 639 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 640 | out: |
| 641 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 646 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | struct nfs4_sequence_args *seq_args; |
| 648 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 649 | }; |
| 650 | |
| 651 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 652 | { |
| 653 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 654 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 655 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 656 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 657 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 658 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 659 | } |
| 660 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 661 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 662 | { |
| 663 | struct nfs41_call_sync_data *data = calldata; |
| 664 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 665 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 668 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 670 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | }; |
| 672 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 673 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 674 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 675 | struct rpc_message *msg, |
| 676 | struct nfs4_sequence_args *args, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 677 | struct nfs4_sequence_res *res) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 678 | { |
| 679 | int ret; |
| 680 | struct rpc_task *task; |
| 681 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 682 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | .seq_args = args, |
| 684 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 685 | }; |
| 686 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 687 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 688 | .rpc_message = msg, |
| 689 | .callback_ops = &nfs41_call_sync_ops, |
| 690 | .callback_data = &data |
| 691 | }; |
| 692 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 693 | task = rpc_run_task(&task_setup); |
| 694 | if (IS_ERR(task)) |
| 695 | ret = PTR_ERR(task); |
| 696 | else { |
| 697 | ret = task->tk_status; |
| 698 | rpc_put_task(task); |
| 699 | } |
| 700 | return ret; |
| 701 | } |
| 702 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 703 | #else |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 704 | static |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 705 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 706 | struct nfs4_sequence_res *res, int cache_reply) |
| 707 | { |
| 708 | } |
| 709 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 710 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 711 | { |
| 712 | } |
| 713 | |
| 714 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 715 | static int nfs4_sequence_done(struct rpc_task *task, |
| 716 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 717 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 718 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 719 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 720 | #endif /* CONFIG_NFS_V4_1 */ |
| 721 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 722 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 723 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 724 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | struct rpc_message *msg, |
| 726 | struct nfs4_sequence_args *args, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 727 | struct nfs4_sequence_res *res) |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 728 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 729 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 732 | static |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 733 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 734 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 735 | struct rpc_message *msg, |
| 736 | struct nfs4_sequence_args *args, |
| 737 | struct nfs4_sequence_res *res, |
| 738 | int cache_reply) |
| 739 | { |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 740 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 741 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
Trond Myklebust | fd0c095 | 2012-11-01 14:43:38 -0400 | [diff] [blame] | 742 | args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 743 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 744 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 745 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 749 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 750 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 751 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 752 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 753 | dir->i_version = cinfo->after; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 754 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 755 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 759 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 760 | struct nfs_openargs o_arg; |
| 761 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 762 | struct nfs_open_confirmargs c_arg; |
| 763 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 764 | struct nfs4_string owner_name; |
| 765 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 766 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 768 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 770 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 772 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 773 | unsigned int rpc_done : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 774 | unsigned int is_recover : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 775 | int rpc_status; |
| 776 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 777 | }; |
| 778 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 779 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 780 | int err, struct nfs4_exception *exception) |
| 781 | { |
| 782 | if (err != -EINVAL) |
| 783 | return false; |
| 784 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 785 | return false; |
| 786 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 787 | exception->retry = 1; |
| 788 | return true; |
| 789 | } |
| 790 | |
| 791 | static enum open_claim_type4 |
| 792 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 793 | enum open_claim_type4 claim) |
| 794 | { |
| 795 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 796 | return claim; |
| 797 | switch (claim) { |
| 798 | default: |
| 799 | return claim; |
| 800 | case NFS4_OPEN_CLAIM_FH: |
| 801 | return NFS4_OPEN_CLAIM_NULL; |
| 802 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 803 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 804 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 805 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 806 | } |
| 807 | } |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 808 | |
| 809 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 810 | { |
| 811 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 812 | p->o_res.seqid = p->o_arg.seqid; |
| 813 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 814 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 815 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 816 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 817 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 818 | } |
| 819 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 820 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 821 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 822 | const struct iattr *attrs, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 823 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 824 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 826 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | struct inode *dir = parent->d_inode; |
| 828 | struct nfs_server *server = NFS_SERVER(dir); |
| 829 | struct nfs4_opendata *p; |
| 830 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 831 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | if (p == NULL) |
| 833 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 834 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 835 | if (p->o_arg.seqid == NULL) |
| 836 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 837 | nfs_sb_active(dentry->d_sb); |
| 838 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 839 | p->dir = parent; |
| 840 | p->owner = sp; |
| 841 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 842 | p->o_arg.open_flags = flags; |
| 843 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 844 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 845 | * will return permission denied for all bits until close */ |
| 846 | if (!(flags & O_EXCL)) { |
| 847 | /* ask server to check for all possible rights as results |
| 848 | * are cached */ |
| 849 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 850 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 851 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 852 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 853 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 854 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 855 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 856 | p->o_arg.server = server; |
| 857 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 858 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 859 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 860 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 861 | case NFS4_OPEN_CLAIM_NULL: |
| 862 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 863 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 864 | p->o_arg.fh = NFS_FH(dir); |
| 865 | break; |
| 866 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 867 | case NFS4_OPEN_CLAIM_FH: |
| 868 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 869 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 870 | p->o_arg.fh = NFS_FH(dentry->d_inode); |
| 871 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 872 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 873 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 874 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 875 | p->o_arg.u.attrs = &p->attrs; |
| 876 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 877 | |
| 878 | verf[0] = jiffies; |
| 879 | verf[1] = current->pid; |
| 880 | memcpy(p->o_arg.u.verifier.data, verf, |
| 881 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 882 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 883 | p->c_arg.fh = &p->o_res.fh; |
| 884 | p->c_arg.stateid = &p->o_res.stateid; |
| 885 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 886 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 887 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 888 | return p; |
| 889 | err_free: |
| 890 | kfree(p); |
| 891 | err: |
| 892 | dput(parent); |
| 893 | return NULL; |
| 894 | } |
| 895 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 896 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 897 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 898 | struct nfs4_opendata *p = container_of(kref, |
| 899 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 900 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 901 | |
| 902 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 903 | if (p->state != NULL) |
| 904 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 905 | nfs4_put_state_owner(p->owner); |
| 906 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 907 | dput(p->dentry); |
| 908 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 909 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 910 | kfree(p); |
| 911 | } |
| 912 | |
| 913 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 914 | { |
| 915 | if (p != NULL) |
| 916 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 917 | } |
| 918 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 919 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 920 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 921 | int ret; |
| 922 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 923 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 924 | return ret; |
| 925 | } |
| 926 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | 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] | 928 | { |
| 929 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 931 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 932 | goto out; |
| 933 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 934 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 935 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 936 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 937 | break; |
| 938 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 939 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 940 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 941 | break; |
| 942 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 943 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 944 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 945 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 947 | return ret; |
| 948 | } |
| 949 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 950 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 951 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 952 | if (delegation == NULL) |
| 953 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 954 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 955 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 956 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 957 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 958 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 959 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 960 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 961 | return 1; |
| 962 | } |
| 963 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 964 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 965 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 966 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 967 | case FMODE_WRITE: |
| 968 | state->n_wronly++; |
| 969 | break; |
| 970 | case FMODE_READ: |
| 971 | state->n_rdonly++; |
| 972 | break; |
| 973 | case FMODE_READ|FMODE_WRITE: |
| 974 | state->n_rdwr++; |
| 975 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 977 | } |
| 978 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 979 | 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] | 980 | { |
| 981 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 982 | nfs4_stateid_copy(&state->stateid, stateid); |
| 983 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 92b40e9 | 2013-04-20 01:25:45 -0400 | [diff] [blame] | 984 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 985 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 986 | case FMODE_READ: |
| 987 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 988 | break; |
| 989 | case FMODE_WRITE: |
| 990 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 991 | break; |
| 992 | case FMODE_READ|FMODE_WRITE: |
| 993 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 994 | } |
| 995 | } |
| 996 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 997 | 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] | 998 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 999 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1001 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1004 | 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] | 1005 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1006 | /* |
| 1007 | * Protect the call to nfs4_state_set_mode_locked and |
| 1008 | * serialise the stateid update |
| 1009 | */ |
| 1010 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1011 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1012 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1013 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1014 | } |
| 1015 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1016 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1017 | write_sequnlock(&state->seqlock); |
| 1018 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1020 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1023 | 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] | 1024 | { |
| 1025 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1026 | struct nfs_delegation *deleg_cur; |
| 1027 | int ret = 0; |
| 1028 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1029 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1030 | |
| 1031 | rcu_read_lock(); |
| 1032 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1033 | if (deleg_cur == NULL) |
| 1034 | goto no_delegation; |
| 1035 | |
| 1036 | spin_lock(&deleg_cur->lock); |
| 1037 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1038 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1039 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1040 | goto no_delegation_unlock; |
| 1041 | |
| 1042 | if (delegation == NULL) |
| 1043 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1044 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1045 | goto no_delegation_unlock; |
| 1046 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1047 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1048 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1049 | ret = 1; |
| 1050 | no_delegation_unlock: |
| 1051 | spin_unlock(&deleg_cur->lock); |
| 1052 | no_delegation: |
| 1053 | rcu_read_unlock(); |
| 1054 | |
| 1055 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1057 | ret = 1; |
| 1058 | } |
| 1059 | |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
| 1063 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1064 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1065 | { |
| 1066 | struct nfs_delegation *delegation; |
| 1067 | |
| 1068 | rcu_read_lock(); |
| 1069 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1070 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1071 | rcu_read_unlock(); |
| 1072 | return; |
| 1073 | } |
| 1074 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1075 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1078 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1079 | { |
| 1080 | struct nfs4_state *state = opendata->state; |
| 1081 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1082 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1083 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1084 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | nfs4_stateid stateid; |
| 1086 | int ret = -EAGAIN; |
| 1087 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1088 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1089 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1091 | if (can_open_cached(state, fmode, open_mode)) { |
| 1092 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1093 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1094 | goto out_return_state; |
| 1095 | } |
| 1096 | spin_unlock(&state->owner->so_lock); |
| 1097 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1098 | rcu_read_lock(); |
| 1099 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1100 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1101 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1102 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1103 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1105 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1106 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1107 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1108 | if (!opendata->is_recover) { |
| 1109 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1110 | if (ret != 0) |
| 1111 | goto out; |
| 1112 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1113 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1114 | |
| 1115 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1116 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1117 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1118 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1119 | out: |
| 1120 | return ERR_PTR(ret); |
| 1121 | out_return_state: |
| 1122 | atomic_inc(&state->count); |
| 1123 | return state; |
| 1124 | } |
| 1125 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1126 | static void |
| 1127 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1128 | { |
| 1129 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1130 | struct nfs_delegation *delegation; |
| 1131 | int delegation_flags = 0; |
| 1132 | |
| 1133 | rcu_read_lock(); |
| 1134 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1135 | if (delegation) |
| 1136 | delegation_flags = delegation->flags; |
| 1137 | rcu_read_unlock(); |
| 1138 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1139 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1140 | "returning a delegation for " |
| 1141 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1142 | clp->cl_hostname); |
| 1143 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1144 | nfs_inode_set_delegation(state->inode, |
| 1145 | data->owner->so_cred, |
| 1146 | &data->o_res); |
| 1147 | else |
| 1148 | nfs_inode_reclaim_delegation(state->inode, |
| 1149 | data->owner->so_cred, |
| 1150 | &data->o_res); |
| 1151 | } |
| 1152 | |
| 1153 | /* |
| 1154 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1155 | * and update the nfs4_state. |
| 1156 | */ |
| 1157 | static struct nfs4_state * |
| 1158 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1159 | { |
| 1160 | struct inode *inode = data->state->inode; |
| 1161 | struct nfs4_state *state = data->state; |
| 1162 | int ret; |
| 1163 | |
| 1164 | if (!data->rpc_done) { |
| 1165 | ret = data->rpc_status; |
| 1166 | goto err; |
| 1167 | } |
| 1168 | |
| 1169 | ret = -ESTALE; |
| 1170 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1171 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1172 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1173 | goto err; |
| 1174 | |
| 1175 | ret = -ENOMEM; |
| 1176 | state = nfs4_get_open_state(inode, data->owner); |
| 1177 | if (state == NULL) |
| 1178 | goto err; |
| 1179 | |
| 1180 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1181 | if (ret) |
| 1182 | goto err; |
| 1183 | |
| 1184 | if (data->o_res.delegation_type != 0) |
| 1185 | nfs4_opendata_check_deleg(data, state); |
| 1186 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1187 | data->o_arg.fmode); |
| 1188 | |
| 1189 | return state; |
| 1190 | err: |
| 1191 | return ERR_PTR(ret); |
| 1192 | |
| 1193 | } |
| 1194 | |
| 1195 | static struct nfs4_state * |
| 1196 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1197 | { |
| 1198 | struct inode *inode; |
| 1199 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1200 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1201 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1202 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1203 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1204 | goto out; |
| 1205 | } |
| 1206 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1207 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1208 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1209 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1210 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1211 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1212 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1213 | goto err; |
| 1214 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1215 | state = nfs4_get_open_state(inode, data->owner); |
| 1216 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1217 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1218 | if (data->o_res.delegation_type != 0) |
| 1219 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1220 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1221 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1222 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1223 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1224 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1225 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1226 | err_put_inode: |
| 1227 | iput(inode); |
| 1228 | err: |
| 1229 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1232 | static struct nfs4_state * |
| 1233 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1234 | { |
| 1235 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1236 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1237 | return _nfs4_opendata_to_nfs4_state(data); |
| 1238 | } |
| 1239 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1240 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1241 | { |
| 1242 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1243 | struct nfs_open_context *ctx; |
| 1244 | |
| 1245 | spin_lock(&state->inode->i_lock); |
| 1246 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1247 | if (ctx->state != state) |
| 1248 | continue; |
| 1249 | get_nfs_open_context(ctx); |
| 1250 | spin_unlock(&state->inode->i_lock); |
| 1251 | return ctx; |
| 1252 | } |
| 1253 | spin_unlock(&state->inode->i_lock); |
| 1254 | return ERR_PTR(-ENOENT); |
| 1255 | } |
| 1256 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1257 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1258 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1259 | { |
| 1260 | struct nfs4_opendata *opendata; |
| 1261 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1262 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
| 1263 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1264 | if (opendata == NULL) |
| 1265 | return ERR_PTR(-ENOMEM); |
| 1266 | opendata->state = state; |
| 1267 | atomic_inc(&state->count); |
| 1268 | return opendata; |
| 1269 | } |
| 1270 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1271 | 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] | 1272 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1273 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1274 | int ret; |
| 1275 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1276 | opendata->o_arg.open_flags = 0; |
| 1277 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1278 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1279 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1280 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1281 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1282 | if (ret != 0) |
| 1283 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1284 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1285 | if (IS_ERR(newstate)) |
| 1286 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1287 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1288 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1293 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1294 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1295 | int ret; |
| 1296 | |
| 1297 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1298 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1299 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1300 | smp_rmb(); |
| 1301 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1302 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1303 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | if (ret != 0) |
| 1305 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1306 | if (newstate != state) |
| 1307 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1308 | } |
| 1309 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1310 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1311 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1312 | if (ret != 0) |
| 1313 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1314 | if (newstate != state) |
| 1315 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1316 | } |
| 1317 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1318 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1319 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1320 | if (ret != 0) |
| 1321 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1322 | if (newstate != state) |
| 1323 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1324 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1325 | /* |
| 1326 | * We may have performed cached opens for all three recoveries. |
| 1327 | * Check if we need to update the current stateid. |
| 1328 | */ |
| 1329 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1330 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1331 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1332 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1333 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1334 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1335 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1336 | return 0; |
| 1337 | } |
| 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | /* |
| 1340 | * OPEN_RECLAIM: |
| 1341 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1343 | 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] | 1344 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1345 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1346 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1347 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | int status; |
| 1349 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1350 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1351 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1352 | if (IS_ERR(opendata)) |
| 1353 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1354 | rcu_read_lock(); |
| 1355 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1356 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1357 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1358 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1359 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1360 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1361 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | return status; |
| 1363 | } |
| 1364 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1365 | 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] | 1366 | { |
| 1367 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1368 | struct nfs4_exception exception = { }; |
| 1369 | int err; |
| 1370 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1371 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1372 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1373 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1374 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1375 | break; |
| 1376 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } while (exception.retry); |
| 1378 | return err; |
| 1379 | } |
| 1380 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1381 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1382 | { |
| 1383 | struct nfs_open_context *ctx; |
| 1384 | int ret; |
| 1385 | |
| 1386 | ctx = nfs4_state_find_open_context(state); |
| 1387 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1388 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1389 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1390 | put_nfs_open_context(ctx); |
| 1391 | return ret; |
| 1392 | } |
| 1393 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1394 | 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] | 1395 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1396 | switch (err) { |
| 1397 | default: |
| 1398 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1399 | "%d.\n", __func__, err); |
| 1400 | case 0: |
| 1401 | case -ENOENT: |
| 1402 | case -ESTALE: |
| 1403 | break; |
| 1404 | case -NFS4ERR_BADSESSION: |
| 1405 | case -NFS4ERR_BADSLOT: |
| 1406 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1407 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1408 | case -NFS4ERR_DEADSESSION: |
| 1409 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1410 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1411 | return -EAGAIN; |
| 1412 | case -NFS4ERR_STALE_CLIENTID: |
| 1413 | case -NFS4ERR_STALE_STATEID: |
| 1414 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1415 | case -NFS4ERR_EXPIRED: |
| 1416 | /* Don't recall a delegation if it was lost */ |
| 1417 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1418 | return -EAGAIN; |
| 1419 | case -NFS4ERR_DELEG_REVOKED: |
| 1420 | case -NFS4ERR_ADMIN_REVOKED: |
| 1421 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1422 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1423 | nfs_inode_find_state_and_recover(state->inode, |
| 1424 | stateid); |
| 1425 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1426 | return 0; |
| 1427 | case -NFS4ERR_DELAY: |
| 1428 | case -NFS4ERR_GRACE: |
| 1429 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1430 | ssleep(1); |
| 1431 | return -EAGAIN; |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1432 | case -ENOMEM: |
| 1433 | case -NFS4ERR_DENIED: |
| 1434 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1435 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | return err; |
| 1438 | } |
| 1439 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1440 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
| 1441 | { |
| 1442 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1443 | struct nfs4_opendata *opendata; |
| 1444 | int err; |
| 1445 | |
| 1446 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1447 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1448 | if (IS_ERR(opendata)) |
| 1449 | return PTR_ERR(opendata); |
| 1450 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
| 1451 | err = nfs4_open_recover(opendata, state); |
| 1452 | nfs4_opendata_put(opendata); |
| 1453 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1454 | } |
| 1455 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1456 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1457 | { |
| 1458 | struct nfs4_opendata *data = calldata; |
| 1459 | |
| 1460 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1461 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1462 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1463 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1464 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1465 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1466 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static void nfs4_open_confirm_release(void *calldata) |
| 1470 | { |
| 1471 | struct nfs4_opendata *data = calldata; |
| 1472 | struct nfs4_state *state = NULL; |
| 1473 | |
| 1474 | /* If this request hasn't been cancelled, do nothing */ |
| 1475 | if (data->cancelled == 0) |
| 1476 | goto out_free; |
| 1477 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1478 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1479 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1480 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1481 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1482 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1483 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1484 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1488 | .rpc_call_done = nfs4_open_confirm_done, |
| 1489 | .rpc_release = nfs4_open_confirm_release, |
| 1490 | }; |
| 1491 | |
| 1492 | /* |
| 1493 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1494 | */ |
| 1495 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1496 | { |
| 1497 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1498 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1499 | struct rpc_message msg = { |
| 1500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1501 | .rpc_argp = &data->c_arg, |
| 1502 | .rpc_resp = &data->c_res, |
| 1503 | .rpc_cred = data->owner->so_cred, |
| 1504 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1505 | struct rpc_task_setup task_setup_data = { |
| 1506 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1507 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1508 | .callback_ops = &nfs4_open_confirm_ops, |
| 1509 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1510 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1511 | .flags = RPC_TASK_ASYNC, |
| 1512 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | int status; |
| 1514 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1515 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1516 | data->rpc_done = 0; |
| 1517 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1518 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1519 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1520 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1521 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1522 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1523 | if (status != 0) { |
| 1524 | data->cancelled = 1; |
| 1525 | smp_wmb(); |
| 1526 | } else |
| 1527 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1528 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | return status; |
| 1530 | } |
| 1531 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1532 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1534 | struct nfs4_opendata *data = calldata; |
| 1535 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1536 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1537 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1538 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1539 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1540 | /* |
| 1541 | * Check if we still need to send an OPEN call, or if we can use |
| 1542 | * a delegation instead. |
| 1543 | */ |
| 1544 | if (data->state != NULL) { |
| 1545 | struct nfs_delegation *delegation; |
| 1546 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1547 | 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] | 1548 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1549 | rcu_read_lock(); |
| 1550 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1551 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
Trond Myklebust | cd4c9be | 2013-04-23 14:46:25 -0400 | [diff] [blame] | 1552 | data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH && |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1553 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1554 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1555 | rcu_read_unlock(); |
| 1556 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1557 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1558 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1559 | switch (data->o_arg.claim) { |
| 1560 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1561 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1562 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1563 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 1564 | case NFS4_OPEN_CLAIM_FH: |
| 1565 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1566 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1567 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1568 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1569 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1570 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1571 | &data->o_res.seq_res, |
| 1572 | task) != 0) |
| 1573 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 1574 | |
| 1575 | /* Set the create mode (note dependency on the session type) */ |
| 1576 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 1577 | if (data->o_arg.open_flags & O_EXCL) { |
| 1578 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 1579 | if (nfs4_has_persistent_session(clp)) |
| 1580 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 1581 | else if (clp->cl_mvops->minor_version > 0) |
| 1582 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 1583 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1584 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1585 | unlock_no_action: |
| 1586 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1587 | out_no_action: |
| 1588 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 1589 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 1590 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1593 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1594 | { |
| 1595 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1597 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1598 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1599 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1600 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1601 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1602 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1603 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1604 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1605 | case S_IFREG: |
| 1606 | break; |
| 1607 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1608 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1609 | break; |
| 1610 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1611 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1612 | break; |
| 1613 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1614 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1615 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1616 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1617 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1618 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1619 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1620 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1621 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1622 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1623 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1624 | static void nfs4_open_release(void *calldata) |
| 1625 | { |
| 1626 | struct nfs4_opendata *data = calldata; |
| 1627 | struct nfs4_state *state = NULL; |
| 1628 | |
| 1629 | /* If this request hasn't been cancelled, do nothing */ |
| 1630 | if (data->cancelled == 0) |
| 1631 | goto out_free; |
| 1632 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1633 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1634 | goto out_free; |
| 1635 | /* In case we need an open_confirm, no cleanup! */ |
| 1636 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1637 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1638 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1639 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1640 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1641 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1642 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1646 | .rpc_call_prepare = nfs4_open_prepare, |
| 1647 | .rpc_call_done = nfs4_open_done, |
| 1648 | .rpc_release = nfs4_open_release, |
| 1649 | }; |
| 1650 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1651 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1652 | { |
| 1653 | struct inode *dir = data->dir->d_inode; |
| 1654 | struct nfs_server *server = NFS_SERVER(dir); |
| 1655 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1656 | struct nfs_openres *o_res = &data->o_res; |
| 1657 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1658 | struct rpc_message msg = { |
| 1659 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1660 | .rpc_argp = o_arg, |
| 1661 | .rpc_resp = o_res, |
| 1662 | .rpc_cred = data->owner->so_cred, |
| 1663 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1664 | struct rpc_task_setup task_setup_data = { |
| 1665 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1666 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1667 | .callback_ops = &nfs4_open_ops, |
| 1668 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1669 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1670 | .flags = RPC_TASK_ASYNC, |
| 1671 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1672 | int status; |
| 1673 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1674 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1675 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1676 | data->rpc_done = 0; |
| 1677 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1678 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1679 | data->is_recover = 0; |
| 1680 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1681 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1682 | data->is_recover = 1; |
| 1683 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1684 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1685 | if (IS_ERR(task)) |
| 1686 | return PTR_ERR(task); |
| 1687 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1688 | if (status != 0) { |
| 1689 | data->cancelled = 1; |
| 1690 | smp_wmb(); |
| 1691 | } else |
| 1692 | status = data->rpc_status; |
| 1693 | rpc_put_task(task); |
| 1694 | |
| 1695 | return status; |
| 1696 | } |
| 1697 | |
| 1698 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1699 | { |
| 1700 | struct inode *dir = data->dir->d_inode; |
| 1701 | struct nfs_openres *o_res = &data->o_res; |
| 1702 | int status; |
| 1703 | |
| 1704 | status = nfs4_run_open_task(data, 1); |
| 1705 | if (status != 0 || !data->rpc_done) |
| 1706 | return status; |
| 1707 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1708 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1709 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1710 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1711 | status = _nfs4_proc_open_confirm(data); |
| 1712 | if (status != 0) |
| 1713 | return status; |
| 1714 | } |
| 1715 | |
| 1716 | return status; |
| 1717 | } |
| 1718 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1719 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1720 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 1721 | struct nfs4_state *state, fmode_t fmode, |
| 1722 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1723 | { |
| 1724 | struct nfs_access_entry cache; |
| 1725 | u32 mask; |
| 1726 | |
| 1727 | /* access call failed or for some reason the server doesn't |
| 1728 | * support any access modes -- defer access call until later */ |
| 1729 | if (opendata->o_res.access_supported == 0) |
| 1730 | return 0; |
| 1731 | |
| 1732 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1733 | /* 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] | 1734 | * write mode bits, but POSIX allows the creating process to write. |
| 1735 | * use openflags to check for exec, because fmode won't |
| 1736 | * always have FMODE_EXEC set when file open for exec. */ |
| 1737 | if (openflags & __FMODE_EXEC) { |
| 1738 | /* ONLY check for exec rights */ |
| 1739 | mask = MAY_EXEC; |
| 1740 | } else if (fmode & FMODE_READ) |
| 1741 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1742 | |
| 1743 | cache.cred = cred; |
| 1744 | cache.jiffies = jiffies; |
| 1745 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1746 | nfs_access_add_cache(state->inode, &cache); |
| 1747 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1748 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1749 | return 0; |
| 1750 | |
| 1751 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1752 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1753 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1756 | /* |
| 1757 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1758 | */ |
| 1759 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1760 | { |
| 1761 | struct inode *dir = data->dir->d_inode; |
| 1762 | struct nfs_server *server = NFS_SERVER(dir); |
| 1763 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1764 | struct nfs_openres *o_res = &data->o_res; |
| 1765 | int status; |
| 1766 | |
| 1767 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1768 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1769 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1770 | if (status != 0) { |
| 1771 | if (status == -NFS4ERR_BADNAME && |
| 1772 | !(o_arg->open_flags & O_CREAT)) |
| 1773 | return -ENOENT; |
| 1774 | return status; |
| 1775 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1776 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1777 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1778 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1779 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1780 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1781 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1782 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1784 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1786 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | } |
| 1788 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1789 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1790 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1793 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1794 | { |
| 1795 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1796 | } |
| 1797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | /* |
| 1799 | * OPEN_EXPIRED: |
| 1800 | * reclaim state on the server after a network partition. |
| 1801 | * Assumes caller holds the appropriate lock |
| 1802 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1803 | 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] | 1804 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1805 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1806 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1808 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1809 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1810 | if (IS_ERR(opendata)) |
| 1811 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1812 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1813 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1814 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1815 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1816 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1819 | 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] | 1820 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1821 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1822 | struct nfs4_exception exception = { }; |
| 1823 | int err; |
| 1824 | |
| 1825 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1826 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1827 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1828 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1829 | switch (err) { |
| 1830 | default: |
| 1831 | goto out; |
| 1832 | case -NFS4ERR_GRACE: |
| 1833 | case -NFS4ERR_DELAY: |
| 1834 | nfs4_handle_exception(server, err, &exception); |
| 1835 | err = 0; |
| 1836 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1837 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1838 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1839 | return err; |
| 1840 | } |
| 1841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1843 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1845 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1847 | ctx = nfs4_state_find_open_context(state); |
| 1848 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1849 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1850 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1851 | put_nfs_open_context(ctx); |
| 1852 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1855 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1856 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1857 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1858 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1859 | nfs4_stateid *stateid = &state->stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1860 | struct nfs_delegation *delegation; |
| 1861 | struct rpc_cred *cred = NULL; |
| 1862 | int status = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1863 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1864 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1865 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1866 | return; |
| 1867 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1868 | /* Get the delegation credential for use by test/free_stateid */ |
| 1869 | rcu_read_lock(); |
| 1870 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1871 | if (delegation != NULL && |
| 1872 | nfs4_stateid_match(&delegation->stateid, stateid)) { |
| 1873 | cred = get_rpccred(delegation->cred); |
| 1874 | rcu_read_unlock(); |
| 1875 | status = nfs41_test_stateid(server, stateid, cred); |
| 1876 | } else |
| 1877 | rcu_read_unlock(); |
| 1878 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1879 | if (status != NFS_OK) { |
| 1880 | /* Free the stateid unless the server explicitly |
| 1881 | * informs us the stateid is unrecognized. */ |
| 1882 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1883 | nfs41_free_stateid(server, stateid, cred); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1884 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1885 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1886 | write_seqlock(&state->seqlock); |
| 1887 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1888 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1889 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1890 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1891 | |
| 1892 | if (cred != NULL) |
| 1893 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /** |
| 1897 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1898 | * |
| 1899 | * @state: NFSv4 state for an inode |
| 1900 | * |
| 1901 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1902 | * Otherwise a negative NFS4ERR value is returned. |
| 1903 | */ |
| 1904 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1905 | { |
| 1906 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1907 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1908 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1909 | int status; |
| 1910 | |
| 1911 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1912 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1913 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1914 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1915 | return -NFS4ERR_BAD_STATEID; |
| 1916 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1917 | status = nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1918 | if (status != NFS_OK) { |
| 1919 | /* Free the stateid unless the server explicitly |
| 1920 | * informs us the stateid is unrecognized. */ |
| 1921 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 1922 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1923 | |
| 1924 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1925 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1926 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1927 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1928 | } |
| 1929 | return status; |
| 1930 | } |
| 1931 | |
| 1932 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1933 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1934 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1935 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1936 | nfs41_clear_delegation_stateid(state); |
| 1937 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1938 | if (status != NFS_OK) |
| 1939 | status = nfs4_open_expired(sp, state); |
| 1940 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1941 | } |
| 1942 | #endif |
| 1943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1945 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1946 | * fields corresponding to attributes that were used to store the verifier. |
| 1947 | * Make sure we clobber those fields in the later setattr call |
| 1948 | */ |
| 1949 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1950 | { |
| 1951 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1952 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1953 | sattr->ia_valid |= ATTR_ATIME; |
| 1954 | |
| 1955 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1956 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1957 | sattr->ia_valid |= ATTR_MTIME; |
| 1958 | } |
| 1959 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1960 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 1961 | fmode_t fmode, |
| 1962 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 1963 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1964 | { |
| 1965 | struct nfs4_state_owner *sp = opendata->owner; |
| 1966 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 1967 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 1968 | struct nfs4_state *state; |
| 1969 | unsigned int seq; |
| 1970 | int ret; |
| 1971 | |
| 1972 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 1973 | |
| 1974 | ret = _nfs4_proc_open(opendata); |
| 1975 | if (ret != 0) |
| 1976 | goto out; |
| 1977 | |
| 1978 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 1979 | ret = PTR_ERR(state); |
| 1980 | if (IS_ERR(state)) |
| 1981 | goto out; |
| 1982 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 1983 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
| 1984 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 1985 | dentry = opendata->dentry; |
| 1986 | if (dentry->d_inode == NULL) { |
| 1987 | /* FIXME: Is this d_drop() ever needed? */ |
| 1988 | d_drop(dentry); |
| 1989 | dentry = d_add_unique(dentry, igrab(state->inode)); |
| 1990 | if (dentry == NULL) { |
| 1991 | dentry = opendata->dentry; |
| 1992 | } else if (dentry != ctx->dentry) { |
| 1993 | dput(ctx->dentry); |
| 1994 | ctx->dentry = dget(dentry); |
| 1995 | } |
| 1996 | nfs_set_verifier(dentry, |
| 1997 | nfs_save_change_attribute(opendata->dir->d_inode)); |
| 1998 | } |
| 1999 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2000 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2001 | if (ret != 0) |
| 2002 | goto out; |
| 2003 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2004 | ctx->state = state; |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame^] | 2005 | if (dentry->d_inode == state->inode) { |
| 2006 | nfs_inode_attach_open_context(ctx); |
| 2007 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2008 | nfs4_schedule_stateid_recovery(server, state); |
| 2009 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2010 | out: |
| 2011 | return ret; |
| 2012 | } |
| 2013 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2014 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2015 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2017 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2018 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2019 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2020 | struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | { |
| 2022 | struct nfs4_state_owner *sp; |
| 2023 | struct nfs4_state *state = NULL; |
| 2024 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2025 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2026 | struct dentry *dentry = ctx->dentry; |
| 2027 | struct rpc_cred *cred = ctx->cred; |
| 2028 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2029 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2030 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2031 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | |
| 2033 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2035 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2036 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2038 | goto out_err; |
| 2039 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2040 | status = nfs4_recover_expired_lease(server); |
| 2041 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2042 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2043 | if (dentry->d_inode != NULL) |
| 2044 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2045 | status = -ENOMEM; |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2046 | if (dentry->d_inode) |
| 2047 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2048 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2049 | claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2050 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2051 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2053 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2054 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2055 | if (!opendata->f_attr.mdsthreshold) |
| 2056 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2057 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2058 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2059 | if (dentry->d_inode != NULL) |
| 2060 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2061 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2062 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2063 | if (status != 0) |
| 2064 | goto err_opendata_put; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2065 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2066 | |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2067 | if ((opendata->o_arg.open_flags & O_EXCL) && |
| 2068 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2069 | nfs4_exclusive_attrset(opendata, sattr); |
| 2070 | |
| 2071 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2072 | status = nfs4_do_setattr(state->inode, cred, |
| 2073 | opendata->o_res.f_attr, sattr, |
| 2074 | state); |
| 2075 | if (status == 0) |
| 2076 | nfs_setattr_update_inode(state->inode, sattr); |
| 2077 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2078 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2079 | |
| 2080 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2081 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2082 | else |
| 2083 | kfree(opendata->f_attr.mdsthreshold); |
| 2084 | opendata->f_attr.mdsthreshold = NULL; |
| 2085 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2086 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2089 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2090 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2091 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2092 | err_put_state_owner: |
| 2093 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | return status; |
| 2096 | } |
| 2097 | |
| 2098 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2099 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2100 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2101 | int flags, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2102 | struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2104 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | struct nfs4_exception exception = { }; |
| 2106 | struct nfs4_state *res; |
| 2107 | int status; |
| 2108 | |
| 2109 | do { |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2110 | status = _nfs4_do_open(dir, ctx, flags, sattr); |
| 2111 | res = ctx->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | if (status == 0) |
| 2113 | break; |
| 2114 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2115 | * book-keeping w.r.t. state-changing operations |
| 2116 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2117 | * It is actually a sign of a bug on the client or on the server. |
| 2118 | * |
| 2119 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2120 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | * have unhashed the old state_owner for us, and that we can |
| 2122 | * therefore safely retry using a new one. We should still warn |
| 2123 | * the user though... |
| 2124 | */ |
| 2125 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2126 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2127 | " returned a bad sequence-id error!\n", |
| 2128 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | exception.retry = 1; |
| 2130 | continue; |
| 2131 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2132 | /* |
| 2133 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2134 | * state before it received the OPEN_CONFIRM. |
| 2135 | * Recover by retrying the request as per the discussion |
| 2136 | * on Page 181 of RFC3530. |
| 2137 | */ |
| 2138 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2139 | exception.retry = 1; |
| 2140 | continue; |
| 2141 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2142 | if (status == -EAGAIN) { |
| 2143 | /* We must have found a delegation */ |
| 2144 | exception.retry = 1; |
| 2145 | continue; |
| 2146 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2147 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2148 | continue; |
| 2149 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | status, &exception)); |
| 2151 | } while (exception.retry); |
| 2152 | return res; |
| 2153 | } |
| 2154 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2155 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2156 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2157 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2159 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2161 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | .iap = sattr, |
| 2163 | .server = server, |
| 2164 | .bitmask = server->attr_bitmask, |
| 2165 | }; |
| 2166 | struct nfs_setattrres res = { |
| 2167 | .fattr = fattr, |
| 2168 | .server = server, |
| 2169 | }; |
| 2170 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2172 | .rpc_argp = &arg, |
| 2173 | .rpc_resp = &res, |
| 2174 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2176 | unsigned long timestamp = jiffies; |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2177 | fmode_t fmode; |
| 2178 | bool truncate; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2179 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2181 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
Trond Myklebust | ee3ae84 | 2013-04-29 10:35:36 -0400 | [diff] [blame] | 2183 | /* Servers should only apply open mode checks for file size changes */ |
| 2184 | truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false; |
| 2185 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2186 | |
| 2187 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { |
| 2188 | /* Use that stateid */ |
| 2189 | } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2190 | struct nfs_lockowner lockowner = { |
| 2191 | .l_owner = current->files, |
| 2192 | .l_pid = current->tgid, |
| 2193 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2194 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2195 | &lockowner); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2196 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2197 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2199 | 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] | 2200 | if (status == 0 && state != NULL) |
| 2201 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2202 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2205 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2206 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2207 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2209 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2210 | struct nfs4_exception exception = { |
| 2211 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2212 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2213 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | int err; |
| 2215 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2216 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2217 | switch (err) { |
| 2218 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2219 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2220 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2221 | "applying open mode checks to " |
| 2222 | "a SETATTR that is not " |
| 2223 | "changing file size.\n", |
| 2224 | server->nfs_client->cl_hostname); |
| 2225 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2226 | if (state && !(state->state & FMODE_WRITE)) { |
| 2227 | err = -EBADF; |
| 2228 | if (sattr->ia_valid & ATTR_OPEN) |
| 2229 | err = -EACCES; |
| 2230 | goto out; |
| 2231 | } |
| 2232 | } |
| 2233 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2235 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | return err; |
| 2237 | } |
| 2238 | |
| 2239 | struct nfs4_closedata { |
| 2240 | struct inode *inode; |
| 2241 | struct nfs4_state *state; |
| 2242 | struct nfs_closeargs arg; |
| 2243 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2244 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2245 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2246 | bool roc; |
| 2247 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | }; |
| 2249 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2250 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2251 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2252 | struct nfs4_closedata *calldata = data; |
| 2253 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2254 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2255 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2256 | if (calldata->roc) |
| 2257 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2258 | nfs4_put_open_state(calldata->state); |
| 2259 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2260 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2261 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2262 | kfree(calldata); |
| 2263 | } |
| 2264 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2265 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2266 | fmode_t fmode) |
| 2267 | { |
| 2268 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2269 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2270 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 2271 | case FMODE_WRITE: |
| 2272 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2273 | break; |
| 2274 | case FMODE_READ: |
| 2275 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2276 | break; |
| 2277 | case 0: |
| 2278 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2279 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2280 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 2281 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2282 | spin_unlock(&state->owner->so_lock); |
| 2283 | } |
| 2284 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2285 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2287 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2290 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2291 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2292 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2293 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | /* hmm. we are done with the inode, and in the process of freeing |
| 2295 | * the state_owner. we keep this around to process errors |
| 2296 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | switch (task->tk_status) { |
| 2298 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2299 | if (calldata->roc) |
| 2300 | pnfs_roc_set_barrier(state->inode, |
| 2301 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2302 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2303 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2304 | nfs4_close_clear_stateid_flags(state, |
| 2305 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | break; |
| 2307 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2308 | case -NFS4ERR_OLD_STATEID: |
| 2309 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2311 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2312 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2314 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2315 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2317 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2318 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2319 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2322 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2324 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2325 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2326 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2327 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2328 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2329 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2330 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2331 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2332 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2333 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2334 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2335 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2336 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2337 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2338 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2339 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2340 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2341 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2342 | } |
| 2343 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2344 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2345 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2346 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2347 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2348 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2349 | if (!nfs4_valid_open_stateid(state)) |
| 2350 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2351 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2352 | |
| 2353 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2354 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2355 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2356 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2357 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2358 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2359 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2360 | if (calldata->roc && |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2361 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) { |
| 2362 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2363 | goto out_wait; |
Andy Adamson | b9536ad | 2013-04-11 09:28:45 -0400 | [diff] [blame] | 2364 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2365 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2366 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2367 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2368 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2369 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2370 | &calldata->arg.seq_args, |
| 2371 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2372 | task) != 0) |
| 2373 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2374 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2375 | return; |
| 2376 | out_no_action: |
| 2377 | task->tk_action = NULL; |
| 2378 | out_wait: |
| 2379 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2382 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2383 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2384 | .rpc_call_done = nfs4_close_done, |
| 2385 | .rpc_release = nfs4_free_closedata, |
| 2386 | }; |
| 2387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | /* |
| 2389 | * It is possible for data to be read/written from a mem-mapped file |
| 2390 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2391 | * This means that we can't safely call nfsv4 close on a file until |
| 2392 | * the inode is cleared. This in turn means that we are not good |
| 2393 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2394 | * share state even when we are done with one of the three share |
| 2395 | * stateid's in the inode. |
| 2396 | * |
| 2397 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2398 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2399 | 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] | 2400 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2401 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2403 | struct nfs4_state_owner *sp = state->owner; |
| 2404 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2405 | struct rpc_message msg = { |
| 2406 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2407 | .rpc_cred = state->owner->so_cred, |
| 2408 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2409 | struct rpc_task_setup task_setup_data = { |
| 2410 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2411 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2412 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2413 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2414 | .flags = RPC_TASK_ASYNC, |
| 2415 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2416 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2418 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2420 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2421 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2422 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2424 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2425 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2427 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2428 | if (calldata->arg.seqid == NULL) |
| 2429 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2430 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2431 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2432 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2433 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2434 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2435 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2436 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2437 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2438 | msg.rpc_argp = &calldata->arg; |
| 2439 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2440 | task_setup_data.callback_data = calldata; |
| 2441 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2442 | if (IS_ERR(task)) |
| 2443 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2444 | status = 0; |
| 2445 | if (wait) |
| 2446 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2447 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2448 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2449 | out_free_calldata: |
| 2450 | kfree(calldata); |
| 2451 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2452 | nfs4_put_open_state(state); |
| 2453 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2454 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2457 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2458 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | struct nfs4_state *state; |
| 2461 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2462 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2463 | state = nfs4_do_open(dir, ctx, open_flags, attr); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2464 | if (IS_ERR(state)) |
| 2465 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2466 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2469 | 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] | 2470 | { |
| 2471 | if (ctx->state == NULL) |
| 2472 | return; |
| 2473 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2474 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2475 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2476 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | |
| 2479 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2480 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2481 | struct nfs4_server_caps_arg args = { |
| 2482 | .fhandle = fhandle, |
| 2483 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | struct nfs4_server_caps_res res = {}; |
| 2485 | struct rpc_message msg = { |
| 2486 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2487 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | .rpc_resp = &res, |
| 2489 | }; |
| 2490 | int status; |
| 2491 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2492 | 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] | 2493 | if (status == 0) { |
| 2494 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2495 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2496 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2497 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2498 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2499 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2501 | server->caps |= NFS_CAP_ACLS; |
| 2502 | if (res.has_links != 0) |
| 2503 | server->caps |= NFS_CAP_HARDLINKS; |
| 2504 | if (res.has_symlinks != 0) |
| 2505 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2506 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2507 | server->caps |= NFS_CAP_FILEID; |
| 2508 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2509 | server->caps |= NFS_CAP_MODE; |
| 2510 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2511 | server->caps |= NFS_CAP_NLINK; |
| 2512 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2513 | server->caps |= NFS_CAP_OWNER; |
| 2514 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2515 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2516 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2517 | server->caps |= NFS_CAP_ATIME; |
| 2518 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2519 | server->caps |= NFS_CAP_CTIME; |
| 2520 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2521 | server->caps |= NFS_CAP_MTIME; |
| 2522 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2523 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2524 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2525 | 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] | 2526 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2527 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | return status; |
| 2531 | } |
| 2532 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2533 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | { |
| 2535 | struct nfs4_exception exception = { }; |
| 2536 | int err; |
| 2537 | do { |
| 2538 | err = nfs4_handle_exception(server, |
| 2539 | _nfs4_server_capabilities(server, fhandle), |
| 2540 | &exception); |
| 2541 | } while (exception.retry); |
| 2542 | return err; |
| 2543 | } |
| 2544 | |
| 2545 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2546 | struct nfs_fsinfo *info) |
| 2547 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | struct nfs4_lookup_root_arg args = { |
| 2549 | .bitmask = nfs4_fattr_bitmap, |
| 2550 | }; |
| 2551 | struct nfs4_lookup_res res = { |
| 2552 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2553 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | .fh = fhandle, |
| 2555 | }; |
| 2556 | struct rpc_message msg = { |
| 2557 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2558 | .rpc_argp = &args, |
| 2559 | .rpc_resp = &res, |
| 2560 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2561 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2562 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2563 | 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] | 2564 | } |
| 2565 | |
| 2566 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2567 | struct nfs_fsinfo *info) |
| 2568 | { |
| 2569 | struct nfs4_exception exception = { }; |
| 2570 | int err; |
| 2571 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2572 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2573 | switch (err) { |
| 2574 | case 0: |
| 2575 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2576 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2577 | default: |
| 2578 | err = nfs4_handle_exception(server, err, &exception); |
| 2579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2581 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | return err; |
| 2583 | } |
| 2584 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2585 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2586 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2587 | { |
| 2588 | struct rpc_auth *auth; |
| 2589 | int ret; |
| 2590 | |
| 2591 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2592 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 2593 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2594 | goto out; |
| 2595 | } |
| 2596 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2597 | out: |
| 2598 | return ret; |
| 2599 | } |
| 2600 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2601 | /* |
| 2602 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 2603 | * |
| 2604 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 2605 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 2606 | * |
| 2607 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 2608 | * negative errno value. |
| 2609 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2610 | 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] | 2611 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2613 | /* Per 3530bis 15.33.5 */ |
| 2614 | static const rpc_authflavor_t flav_array[] = { |
| 2615 | RPC_AUTH_GSS_KRB5P, |
| 2616 | RPC_AUTH_GSS_KRB5I, |
| 2617 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 2618 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2619 | RPC_AUTH_NULL, |
| 2620 | }; |
| 2621 | int status = -EPERM; |
| 2622 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2624 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2625 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2626 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2627 | continue; |
| 2628 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2629 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 2630 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2631 | /* |
| 2632 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2633 | * to access the mount. It could also mean that we tried to mount |
| 2634 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2635 | * existing mount programs don't handle -EACCES very well so it should |
| 2636 | * be mapped to -EPERM instead. |
| 2637 | */ |
| 2638 | if (status == -EACCES) |
| 2639 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2640 | return status; |
| 2641 | } |
| 2642 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2643 | static int nfs4_do_find_root_sec(struct nfs_server *server, |
| 2644 | struct nfs_fh *fhandle, struct nfs_fsinfo *info) |
| 2645 | { |
| 2646 | int mv = server->nfs_client->cl_minorversion; |
| 2647 | return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info); |
| 2648 | } |
| 2649 | |
| 2650 | /** |
| 2651 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 2652 | * @server: initialized nfs_server handle |
| 2653 | * @fhandle: we fill in the pseudo-fs root file handle |
| 2654 | * @info: we fill in an FSINFO struct |
| 2655 | * |
| 2656 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2657 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2658 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2659 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2660 | { |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2661 | int status; |
| 2662 | |
| 2663 | status = nfs4_lookup_root(server, fhandle, info); |
| 2664 | if ((status == -NFS4ERR_WRONGSEC) && |
| 2665 | !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2666 | status = nfs4_do_find_root_sec(server, fhandle, info); |
| 2667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | if (status == 0) |
| 2669 | status = nfs4_server_capabilities(server, fhandle); |
| 2670 | if (status == 0) |
| 2671 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 2672 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2673 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2676 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2677 | struct nfs_fsinfo *info) |
| 2678 | { |
| 2679 | int error; |
| 2680 | struct nfs_fattr *fattr = info->fattr; |
| 2681 | |
| 2682 | error = nfs4_server_capabilities(server, mntfh); |
| 2683 | if (error < 0) { |
| 2684 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2685 | return error; |
| 2686 | } |
| 2687 | |
| 2688 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2689 | if (error < 0) { |
| 2690 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2691 | return error; |
| 2692 | } |
| 2693 | |
| 2694 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2695 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2696 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2697 | |
| 2698 | return error; |
| 2699 | } |
| 2700 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2701 | /* |
| 2702 | * Get locations and (maybe) other attributes of a referral. |
| 2703 | * Note that we'll actually follow the referral later when |
| 2704 | * we detect fsid mismatch in inode revalidation |
| 2705 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2706 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2707 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2708 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2709 | { |
| 2710 | int status = -ENOMEM; |
| 2711 | struct page *page = NULL; |
| 2712 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2713 | |
| 2714 | page = alloc_page(GFP_KERNEL); |
| 2715 | if (page == NULL) |
| 2716 | goto out; |
| 2717 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2718 | if (locations == NULL) |
| 2719 | goto out; |
| 2720 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2721 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2722 | if (status != 0) |
| 2723 | goto out; |
| 2724 | /* Make sure server returned a different fsid for the referral */ |
| 2725 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2726 | dprintk("%s: server did not return a different fsid for" |
| 2727 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2728 | status = -EIO; |
| 2729 | goto out; |
| 2730 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2731 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2732 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2733 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2734 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2735 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2736 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2737 | out: |
| 2738 | if (page) |
| 2739 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2740 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2741 | return status; |
| 2742 | } |
| 2743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2745 | { |
| 2746 | struct nfs4_getattr_arg args = { |
| 2747 | .fh = fhandle, |
| 2748 | .bitmask = server->attr_bitmask, |
| 2749 | }; |
| 2750 | struct nfs4_getattr_res res = { |
| 2751 | .fattr = fattr, |
| 2752 | .server = server, |
| 2753 | }; |
| 2754 | struct rpc_message msg = { |
| 2755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2756 | .rpc_argp = &args, |
| 2757 | .rpc_resp = &res, |
| 2758 | }; |
| 2759 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2760 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2761 | 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] | 2762 | } |
| 2763 | |
| 2764 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2765 | { |
| 2766 | struct nfs4_exception exception = { }; |
| 2767 | int err; |
| 2768 | do { |
| 2769 | err = nfs4_handle_exception(server, |
| 2770 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2771 | &exception); |
| 2772 | } while (exception.retry); |
| 2773 | return err; |
| 2774 | } |
| 2775 | |
| 2776 | /* |
| 2777 | * The file is not closed if it is opened due to the a request to change |
| 2778 | * the size of the file. The open call will not be needed once the |
| 2779 | * VFS layer lookup-intents are implemented. |
| 2780 | * |
| 2781 | * Close is called when the inode is destroyed. |
| 2782 | * If we haven't opened the file for O_WRONLY, we |
| 2783 | * need to in the size_change case to obtain a stateid. |
| 2784 | * |
| 2785 | * Got race? |
| 2786 | * Because OPEN is always done by name in nfsv4, it is |
| 2787 | * possible that we opened a different file by the same |
| 2788 | * name. We can recognize this race condition, but we |
| 2789 | * can't do anything about it besides returning an error. |
| 2790 | * |
| 2791 | * This will be fixed with VFS changes (lookup-intent). |
| 2792 | */ |
| 2793 | static int |
| 2794 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2795 | struct iattr *sattr) |
| 2796 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2797 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2798 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2799 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | int status; |
| 2801 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2802 | if (pnfs_ld_layoutret_on_setattr(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 2803 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2804 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2805 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2807 | /* Deal with open(O_TRUNC) */ |
| 2808 | if (sattr->ia_valid & ATTR_OPEN) |
| 2809 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2810 | |
| 2811 | /* Optimization: if the end result is no change, don't RPC */ |
| 2812 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2813 | return 0; |
| 2814 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2815 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2816 | if (sattr->ia_valid & ATTR_FILE) { |
| 2817 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2818 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2819 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2820 | if (ctx) { |
| 2821 | cred = ctx->cred; |
| 2822 | state = ctx->state; |
| 2823 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2827 | if (status == 0) |
| 2828 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | return status; |
| 2830 | } |
| 2831 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2832 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2833 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2834 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2835 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2836 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2837 | int status; |
| 2838 | struct nfs4_lookup_arg args = { |
| 2839 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2840 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2841 | .name = name, |
| 2842 | }; |
| 2843 | struct nfs4_lookup_res res = { |
| 2844 | .server = server, |
| 2845 | .fattr = fattr, |
| 2846 | .fh = fhandle, |
| 2847 | }; |
| 2848 | struct rpc_message msg = { |
| 2849 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2850 | .rpc_argp = &args, |
| 2851 | .rpc_resp = &res, |
| 2852 | }; |
| 2853 | |
| 2854 | nfs_fattr_init(fattr); |
| 2855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2857 | 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] | 2858 | dprintk("NFS reply lookup: %d\n", status); |
| 2859 | return status; |
| 2860 | } |
| 2861 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2862 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2863 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2864 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2865 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2866 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2867 | fattr->nlink = 2; |
| 2868 | } |
| 2869 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2870 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2871 | struct qstr *name, struct nfs_fh *fhandle, |
| 2872 | struct nfs_fattr *fattr) |
| 2873 | { |
| 2874 | struct nfs4_exception exception = { }; |
| 2875 | struct rpc_clnt *client = *clnt; |
| 2876 | int err; |
| 2877 | do { |
| 2878 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2879 | switch (err) { |
| 2880 | case -NFS4ERR_BADNAME: |
| 2881 | err = -ENOENT; |
| 2882 | goto out; |
| 2883 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2884 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2885 | goto out; |
| 2886 | case -NFS4ERR_WRONGSEC: |
| 2887 | err = -EPERM; |
| 2888 | if (client != *clnt) |
| 2889 | goto out; |
| 2890 | |
| 2891 | client = nfs4_create_sec_client(client, dir, name); |
| 2892 | if (IS_ERR(client)) |
| 2893 | return PTR_ERR(client); |
| 2894 | |
| 2895 | exception.retry = 1; |
| 2896 | break; |
| 2897 | default: |
| 2898 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2899 | } |
| 2900 | } while (exception.retry); |
| 2901 | |
| 2902 | out: |
| 2903 | if (err == 0) |
| 2904 | *clnt = client; |
| 2905 | else if (client != *clnt) |
| 2906 | rpc_shutdown_client(client); |
| 2907 | |
| 2908 | return err; |
| 2909 | } |
| 2910 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2911 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2912 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2914 | int status; |
| 2915 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2916 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2917 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2918 | if (client != NFS_CLIENT(dir)) { |
| 2919 | rpc_shutdown_client(client); |
| 2920 | nfs_fixup_secinfo_attributes(fattr); |
| 2921 | } |
| 2922 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2925 | struct rpc_clnt * |
| 2926 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2927 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2928 | { |
| 2929 | int status; |
| 2930 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2931 | |
| 2932 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2933 | if (status < 0) { |
| 2934 | rpc_shutdown_client(client); |
| 2935 | return ERR_PTR(status); |
| 2936 | } |
| 2937 | return client; |
| 2938 | } |
| 2939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2941 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2942 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | struct nfs4_accessargs args = { |
| 2944 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2945 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2947 | struct nfs4_accessres res = { |
| 2948 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2949 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | struct rpc_message msg = { |
| 2951 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2952 | .rpc_argp = &args, |
| 2953 | .rpc_resp = &res, |
| 2954 | .rpc_cred = entry->cred, |
| 2955 | }; |
| 2956 | int mode = entry->mask; |
| 2957 | int status; |
| 2958 | |
| 2959 | /* |
| 2960 | * Determine which access bits we want to ask for... |
| 2961 | */ |
| 2962 | if (mode & MAY_READ) |
| 2963 | args.access |= NFS4_ACCESS_READ; |
| 2964 | if (S_ISDIR(inode->i_mode)) { |
| 2965 | if (mode & MAY_WRITE) |
| 2966 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2967 | if (mode & MAY_EXEC) |
| 2968 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2969 | } else { |
| 2970 | if (mode & MAY_WRITE) |
| 2971 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2972 | if (mode & MAY_EXEC) |
| 2973 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2974 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2975 | |
| 2976 | res.fattr = nfs_alloc_fattr(); |
| 2977 | if (res.fattr == NULL) |
| 2978 | return -ENOMEM; |
| 2979 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2980 | 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] | 2981 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2982 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2983 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2985 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | return status; |
| 2987 | } |
| 2988 | |
| 2989 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2990 | { |
| 2991 | struct nfs4_exception exception = { }; |
| 2992 | int err; |
| 2993 | do { |
| 2994 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2995 | _nfs4_proc_access(inode, entry), |
| 2996 | &exception); |
| 2997 | } while (exception.retry); |
| 2998 | return err; |
| 2999 | } |
| 3000 | |
| 3001 | /* |
| 3002 | * TODO: For the time being, we don't try to get any attributes |
| 3003 | * along with any of the zero-copy operations READ, READDIR, |
| 3004 | * READLINK, WRITE. |
| 3005 | * |
| 3006 | * In the case of the first three, we want to put the GETATTR |
| 3007 | * after the read-type operation -- this is because it is hard |
| 3008 | * to predict the length of a GETATTR response in v4, and thus |
| 3009 | * align the READ data correctly. This means that the GETATTR |
| 3010 | * may end up partially falling into the page cache, and we should |
| 3011 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3012 | * To do this efficiently, we need to know the total length |
| 3013 | * of data received, which doesn't seem to be available outside |
| 3014 | * of the RPC layer. |
| 3015 | * |
| 3016 | * In the case of WRITE, we also want to put the GETATTR after |
| 3017 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3018 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | * |
| 3020 | * Both of these changes to the XDR layer would in fact be quite |
| 3021 | * minor, but I decided to leave them for a subsequent patch. |
| 3022 | */ |
| 3023 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3024 | unsigned int pgbase, unsigned int pglen) |
| 3025 | { |
| 3026 | struct nfs4_readlink args = { |
| 3027 | .fh = NFS_FH(inode), |
| 3028 | .pgbase = pgbase, |
| 3029 | .pglen = pglen, |
| 3030 | .pages = &page, |
| 3031 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3032 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | struct rpc_message msg = { |
| 3034 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3035 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3036 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | }; |
| 3038 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3039 | 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] | 3040 | } |
| 3041 | |
| 3042 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3043 | unsigned int pgbase, unsigned int pglen) |
| 3044 | { |
| 3045 | struct nfs4_exception exception = { }; |
| 3046 | int err; |
| 3047 | do { |
| 3048 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3049 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 3050 | &exception); |
| 3051 | } while (exception.retry); |
| 3052 | return err; |
| 3053 | } |
| 3054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3056 | * 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] | 3057 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | static int |
| 3059 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3060 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3062 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | int status = 0; |
| 3065 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3066 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3067 | if (IS_ERR(ctx)) |
| 3068 | return PTR_ERR(ctx); |
| 3069 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3070 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3071 | state = nfs4_do_open(dir, ctx, flags, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | if (IS_ERR(state)) { |
| 3073 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3074 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3077 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | return status; |
| 3079 | } |
| 3080 | |
| 3081 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3082 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3083 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3084 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3086 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3088 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3089 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3090 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3093 | .rpc_argp = &args, |
| 3094 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3096 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3097 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3098 | 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] | 3099 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3100 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | return status; |
| 3102 | } |
| 3103 | |
| 3104 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3105 | { |
| 3106 | struct nfs4_exception exception = { }; |
| 3107 | int err; |
| 3108 | do { |
| 3109 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3110 | _nfs4_proc_remove(dir, name), |
| 3111 | &exception); |
| 3112 | } while (exception.retry); |
| 3113 | return err; |
| 3114 | } |
| 3115 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3116 | 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] | 3117 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3118 | struct nfs_server *server = NFS_SERVER(dir); |
| 3119 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3120 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3122 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3124 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3127 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3128 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3129 | nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3130 | &data->args.seq_args, |
| 3131 | &data->res.seq_res, |
| 3132 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3135 | 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] | 3136 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3137 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3138 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3139 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3140 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3141 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3142 | return 0; |
| 3143 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3144 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3147 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3148 | { |
| 3149 | struct nfs_server *server = NFS_SERVER(dir); |
| 3150 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3151 | struct nfs_renameres *res = msg->rpc_resp; |
| 3152 | |
| 3153 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3154 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3155 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3156 | } |
| 3157 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3158 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3159 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3160 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3161 | &data->args.seq_args, |
| 3162 | &data->res.seq_res, |
| 3163 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3167 | struct inode *new_dir) |
| 3168 | { |
| 3169 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3170 | |
| 3171 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3172 | return 0; |
| 3173 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3174 | return 0; |
| 3175 | |
| 3176 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3177 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3178 | return 1; |
| 3179 | } |
| 3180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3182 | struct inode *new_dir, struct qstr *new_name) |
| 3183 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3184 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3185 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | .old_dir = NFS_FH(old_dir), |
| 3187 | .new_dir = NFS_FH(new_dir), |
| 3188 | .old_name = old_name, |
| 3189 | .new_name = new_name, |
| 3190 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3191 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3192 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3193 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | struct rpc_message msg = { |
| 3195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3196 | .rpc_argp = &arg, |
| 3197 | .rpc_resp = &res, |
| 3198 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3199 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3201 | 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] | 3202 | if (!status) { |
| 3203 | update_changeattr(old_dir, &res.old_cinfo); |
| 3204 | update_changeattr(new_dir, &res.new_cinfo); |
| 3205 | } |
| 3206 | return status; |
| 3207 | } |
| 3208 | |
| 3209 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3210 | struct inode *new_dir, struct qstr *new_name) |
| 3211 | { |
| 3212 | struct nfs4_exception exception = { }; |
| 3213 | int err; |
| 3214 | do { |
| 3215 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3216 | _nfs4_proc_rename(old_dir, old_name, |
| 3217 | new_dir, new_name), |
| 3218 | &exception); |
| 3219 | } while (exception.retry); |
| 3220 | return err; |
| 3221 | } |
| 3222 | |
| 3223 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3224 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3225 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | struct nfs4_link_arg arg = { |
| 3227 | .fh = NFS_FH(inode), |
| 3228 | .dir_fh = NFS_FH(dir), |
| 3229 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3230 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3232 | struct nfs4_link_res res = { |
| 3233 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3234 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | struct rpc_message msg = { |
| 3236 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3237 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3238 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3240 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3242 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3243 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3244 | goto out; |
| 3245 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3246 | 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] | 3247 | if (!status) { |
| 3248 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3249 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3250 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3251 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3252 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | return status; |
| 3254 | } |
| 3255 | |
| 3256 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3257 | { |
| 3258 | struct nfs4_exception exception = { }; |
| 3259 | int err; |
| 3260 | do { |
| 3261 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3262 | _nfs4_proc_link(inode, dir, name), |
| 3263 | &exception); |
| 3264 | } while (exception.retry); |
| 3265 | return err; |
| 3266 | } |
| 3267 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3268 | struct nfs4_createdata { |
| 3269 | struct rpc_message msg; |
| 3270 | struct nfs4_create_arg arg; |
| 3271 | struct nfs4_create_res res; |
| 3272 | struct nfs_fh fh; |
| 3273 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3274 | }; |
| 3275 | |
| 3276 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3277 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3278 | { |
| 3279 | struct nfs4_createdata *data; |
| 3280 | |
| 3281 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3282 | if (data != NULL) { |
| 3283 | struct nfs_server *server = NFS_SERVER(dir); |
| 3284 | |
| 3285 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3286 | data->msg.rpc_argp = &data->arg; |
| 3287 | data->msg.rpc_resp = &data->res; |
| 3288 | data->arg.dir_fh = NFS_FH(dir); |
| 3289 | data->arg.server = server; |
| 3290 | data->arg.name = name; |
| 3291 | data->arg.attrs = sattr; |
| 3292 | data->arg.ftype = ftype; |
| 3293 | data->arg.bitmask = server->attr_bitmask; |
| 3294 | data->res.server = server; |
| 3295 | data->res.fh = &data->fh; |
| 3296 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3297 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3298 | } |
| 3299 | return data; |
| 3300 | } |
| 3301 | |
| 3302 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3303 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3304 | 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] | 3305 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3306 | if (status == 0) { |
| 3307 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3308 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3309 | } |
| 3310 | return status; |
| 3311 | } |
| 3312 | |
| 3313 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3314 | { |
| 3315 | kfree(data); |
| 3316 | } |
| 3317 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3318 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3319 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3321 | struct nfs4_createdata *data; |
| 3322 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3324 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3325 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3326 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3327 | status = -ENOMEM; |
| 3328 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3329 | if (data == NULL) |
| 3330 | goto out; |
| 3331 | |
| 3332 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3333 | data->arg.u.symlink.pages = &page; |
| 3334 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3336 | status = nfs4_do_create(dir, dentry, data); |
| 3337 | |
| 3338 | nfs4_free_createdata(data); |
| 3339 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | return status; |
| 3341 | } |
| 3342 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3343 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3344 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | { |
| 3346 | struct nfs4_exception exception = { }; |
| 3347 | int err; |
| 3348 | do { |
| 3349 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3350 | _nfs4_proc_symlink(dir, dentry, page, |
| 3351 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | &exception); |
| 3353 | } while (exception.retry); |
| 3354 | return err; |
| 3355 | } |
| 3356 | |
| 3357 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3358 | struct iattr *sattr) |
| 3359 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3360 | struct nfs4_createdata *data; |
| 3361 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3363 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3364 | if (data == NULL) |
| 3365 | goto out; |
| 3366 | |
| 3367 | status = nfs4_do_create(dir, dentry, data); |
| 3368 | |
| 3369 | nfs4_free_createdata(data); |
| 3370 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | return status; |
| 3372 | } |
| 3373 | |
| 3374 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3375 | struct iattr *sattr) |
| 3376 | { |
| 3377 | struct nfs4_exception exception = { }; |
| 3378 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3379 | |
| 3380 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | do { |
| 3382 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3383 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3384 | &exception); |
| 3385 | } while (exception.retry); |
| 3386 | return err; |
| 3387 | } |
| 3388 | |
| 3389 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3390 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | { |
| 3392 | struct inode *dir = dentry->d_inode; |
| 3393 | struct nfs4_readdir_arg args = { |
| 3394 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3395 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | .pgbase = 0, |
| 3397 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3398 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3399 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | }; |
| 3401 | struct nfs4_readdir_res res; |
| 3402 | struct rpc_message msg = { |
| 3403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3404 | .rpc_argp = &args, |
| 3405 | .rpc_resp = &res, |
| 3406 | .rpc_cred = cred, |
| 3407 | }; |
| 3408 | int status; |
| 3409 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3410 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3411 | dentry->d_parent->d_name.name, |
| 3412 | dentry->d_name.name, |
| 3413 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3414 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3416 | 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] | 3417 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3418 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3419 | status += args.pgbase; |
| 3420 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3421 | |
| 3422 | nfs_invalidate_atime(dir); |
| 3423 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3424 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | return status; |
| 3426 | } |
| 3427 | |
| 3428 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3429 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | { |
| 3431 | struct nfs4_exception exception = { }; |
| 3432 | int err; |
| 3433 | do { |
| 3434 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3435 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3436 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | &exception); |
| 3438 | } while (exception.retry); |
| 3439 | return err; |
| 3440 | } |
| 3441 | |
| 3442 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3443 | struct iattr *sattr, dev_t rdev) |
| 3444 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3445 | struct nfs4_createdata *data; |
| 3446 | int mode = sattr->ia_mode; |
| 3447 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3449 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3450 | if (data == NULL) |
| 3451 | goto out; |
| 3452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3454 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3456 | data->arg.ftype = NF4BLK; |
| 3457 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3458 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | } |
| 3460 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3461 | data->arg.ftype = NF4CHR; |
| 3462 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3463 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3464 | } else if (!S_ISSOCK(mode)) { |
| 3465 | status = -EINVAL; |
| 3466 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3469 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3470 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3471 | nfs4_free_createdata(data); |
| 3472 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | return status; |
| 3474 | } |
| 3475 | |
| 3476 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3477 | struct iattr *sattr, dev_t rdev) |
| 3478 | { |
| 3479 | struct nfs4_exception exception = { }; |
| 3480 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3481 | |
| 3482 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | do { |
| 3484 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3485 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3486 | &exception); |
| 3487 | } while (exception.retry); |
| 3488 | return err; |
| 3489 | } |
| 3490 | |
| 3491 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3492 | struct nfs_fsstat *fsstat) |
| 3493 | { |
| 3494 | struct nfs4_statfs_arg args = { |
| 3495 | .fh = fhandle, |
| 3496 | .bitmask = server->attr_bitmask, |
| 3497 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3498 | struct nfs4_statfs_res res = { |
| 3499 | .fsstat = fsstat, |
| 3500 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | struct rpc_message msg = { |
| 3502 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3503 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3504 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | }; |
| 3506 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3507 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3508 | 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] | 3509 | } |
| 3510 | |
| 3511 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3512 | { |
| 3513 | struct nfs4_exception exception = { }; |
| 3514 | int err; |
| 3515 | do { |
| 3516 | err = nfs4_handle_exception(server, |
| 3517 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3518 | &exception); |
| 3519 | } while (exception.retry); |
| 3520 | return err; |
| 3521 | } |
| 3522 | |
| 3523 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3524 | struct nfs_fsinfo *fsinfo) |
| 3525 | { |
| 3526 | struct nfs4_fsinfo_arg args = { |
| 3527 | .fh = fhandle, |
| 3528 | .bitmask = server->attr_bitmask, |
| 3529 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3530 | struct nfs4_fsinfo_res res = { |
| 3531 | .fsinfo = fsinfo, |
| 3532 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | struct rpc_message msg = { |
| 3534 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3535 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3536 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | }; |
| 3538 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3539 | 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] | 3540 | } |
| 3541 | |
| 3542 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3543 | { |
| 3544 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3545 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | int err; |
| 3547 | |
| 3548 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 3549 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3550 | if (err == 0) { |
| 3551 | struct nfs_client *clp = server->nfs_client; |
| 3552 | |
| 3553 | spin_lock(&clp->cl_lock); |
| 3554 | clp->cl_lease_time = fsinfo->lease_time * HZ; |
| 3555 | clp->cl_last_renewal = now; |
| 3556 | spin_unlock(&clp->cl_lock); |
| 3557 | break; |
| 3558 | } |
| 3559 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | } while (exception.retry); |
| 3561 | return err; |
| 3562 | } |
| 3563 | |
| 3564 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3565 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3566 | int error; |
| 3567 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3568 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3569 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3570 | if (error == 0) { |
| 3571 | /* block layout checks this! */ |
| 3572 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3573 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3574 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3575 | |
| 3576 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3580 | struct nfs_pathconf *pathconf) |
| 3581 | { |
| 3582 | struct nfs4_pathconf_arg args = { |
| 3583 | .fh = fhandle, |
| 3584 | .bitmask = server->attr_bitmask, |
| 3585 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3586 | struct nfs4_pathconf_res res = { |
| 3587 | .pathconf = pathconf, |
| 3588 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | struct rpc_message msg = { |
| 3590 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3591 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3592 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | }; |
| 3594 | |
| 3595 | /* None of the pathconf attributes are mandatory to implement */ |
| 3596 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3597 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3598 | return 0; |
| 3599 | } |
| 3600 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3601 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3602 | 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] | 3603 | } |
| 3604 | |
| 3605 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3606 | struct nfs_pathconf *pathconf) |
| 3607 | { |
| 3608 | struct nfs4_exception exception = { }; |
| 3609 | int err; |
| 3610 | |
| 3611 | do { |
| 3612 | err = nfs4_handle_exception(server, |
| 3613 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3614 | &exception); |
| 3615 | } while (exception.retry); |
| 3616 | return err; |
| 3617 | } |
| 3618 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3619 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3620 | const struct nfs_open_context *ctx, |
| 3621 | const struct nfs_lock_context *l_ctx, |
| 3622 | fmode_t fmode) |
| 3623 | { |
| 3624 | const struct nfs_lockowner *lockowner = NULL; |
| 3625 | |
| 3626 | if (l_ctx != NULL) |
| 3627 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3628 | return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3629 | } |
| 3630 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 3631 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3632 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 3633 | const struct nfs_open_context *ctx, |
| 3634 | const struct nfs_lock_context *l_ctx, |
| 3635 | fmode_t fmode) |
| 3636 | { |
| 3637 | nfs4_stateid current_stateid; |
| 3638 | |
| 3639 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode)) |
| 3640 | return false; |
| 3641 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 3642 | } |
| 3643 | |
| 3644 | static bool nfs4_error_stateid_expired(int err) |
| 3645 | { |
| 3646 | switch (err) { |
| 3647 | case -NFS4ERR_DELEG_REVOKED: |
| 3648 | case -NFS4ERR_ADMIN_REVOKED: |
| 3649 | case -NFS4ERR_BAD_STATEID: |
| 3650 | case -NFS4ERR_STALE_STATEID: |
| 3651 | case -NFS4ERR_OLD_STATEID: |
| 3652 | case -NFS4ERR_OPENMODE: |
| 3653 | case -NFS4ERR_EXPIRED: |
| 3654 | return true; |
| 3655 | } |
| 3656 | return false; |
| 3657 | } |
| 3658 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3659 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3660 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3661 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3662 | } |
| 3663 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3664 | 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] | 3665 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3666 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3668 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3669 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3670 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3672 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3673 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3675 | renew_lease(server, data->timestamp); |
| 3676 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3679 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
| 3680 | struct nfs_readargs *args) |
| 3681 | { |
| 3682 | |
| 3683 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3684 | nfs4_stateid_is_current(&args->stateid, |
| 3685 | args->context, |
| 3686 | args->lock_context, |
| 3687 | FMODE_READ)) |
| 3688 | return false; |
| 3689 | rpc_restart_call_prepare(task); |
| 3690 | return true; |
| 3691 | } |
| 3692 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3693 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3694 | { |
| 3695 | |
| 3696 | dprintk("--> %s\n", __func__); |
| 3697 | |
| 3698 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3699 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3700 | if (nfs4_read_stateid_changed(task, &data->args)) |
| 3701 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3702 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3703 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3706 | 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] | 3707 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3709 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3710 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3711 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | } |
| 3713 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3714 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3715 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3716 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3717 | &data->args.seq_args, |
| 3718 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3719 | task)) |
| 3720 | return; |
| 3721 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3722 | data->args.lock_context, FMODE_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3725 | 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] | 3726 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3727 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3729 | 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] | 3730 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3731 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3733 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3735 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3736 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3737 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | } |
| 3739 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3740 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
| 3741 | struct nfs_writeargs *args) |
| 3742 | { |
| 3743 | |
| 3744 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 3745 | nfs4_stateid_is_current(&args->stateid, |
| 3746 | args->context, |
| 3747 | args->lock_context, |
| 3748 | FMODE_WRITE)) |
| 3749 | return false; |
| 3750 | rpc_restart_call_prepare(task); |
| 3751 | return true; |
| 3752 | } |
| 3753 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3754 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3755 | { |
| 3756 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3757 | return -EAGAIN; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 3758 | if (nfs4_write_stateid_changed(task, &data->args)) |
| 3759 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3760 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3761 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3762 | } |
| 3763 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3764 | static |
| 3765 | 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] | 3766 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3767 | const struct nfs_pgio_header *hdr = data->header; |
| 3768 | |
| 3769 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3770 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3771 | return false; |
| 3772 | /* Otherwise, request attributes if and only if we don't hold |
| 3773 | * a delegation |
| 3774 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3775 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3776 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3777 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3778 | 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] | 3779 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3780 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3781 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3782 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3783 | data->args.bitmask = NULL; |
| 3784 | data->res.fattr = NULL; |
| 3785 | } else |
| 3786 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3787 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3788 | if (!data->write_done_cb) |
| 3789 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3790 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | data->timestamp = jiffies; |
| 3792 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3793 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3794 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3797 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3798 | { |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3799 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3800 | &data->args.seq_args, |
| 3801 | &data->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 3802 | task)) |
| 3803 | return; |
| 3804 | nfs4_set_rw_stateid(&data->args.stateid, data->args.context, |
| 3805 | data->args.lock_context, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3808 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3809 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3810 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3811 | &data->args.seq_args, |
| 3812 | &data->res.seq_res, |
| 3813 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3816 | 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] | 3817 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3819 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3820 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3821 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3822 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3824 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3827 | 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] | 3828 | { |
| 3829 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3830 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3831 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3834 | 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] | 3835 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3836 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3837 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3838 | if (data->commit_done_cb == NULL) |
| 3839 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3840 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3841 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3842 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3845 | struct nfs4_renewdata { |
| 3846 | struct nfs_client *client; |
| 3847 | unsigned long timestamp; |
| 3848 | }; |
| 3849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | /* |
| 3851 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3852 | * standalone procedure for queueing an asynchronous RENEW. |
| 3853 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3854 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3855 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3856 | struct nfs4_renewdata *data = calldata; |
| 3857 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3858 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3859 | if (atomic_read(&clp->cl_count) > 1) |
| 3860 | nfs4_schedule_state_renewal(clp); |
| 3861 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3862 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3863 | } |
| 3864 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3865 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3867 | struct nfs4_renewdata *data = calldata; |
| 3868 | struct nfs_client *clp = data->client; |
| 3869 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | |
| 3871 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3872 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3873 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3874 | return; |
| 3875 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3876 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3877 | return; |
| 3878 | } |
| 3879 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3881 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3884 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3885 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3886 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3887 | }; |
| 3888 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3889 | 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] | 3890 | { |
| 3891 | struct rpc_message msg = { |
| 3892 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3893 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3894 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3896 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3898 | if (renew_flags == 0) |
| 3899 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3900 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3901 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3902 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3903 | if (data == NULL) |
| 3904 | return -ENOMEM; |
| 3905 | data->client = clp; |
| 3906 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 3907 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3908 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3911 | 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] | 3912 | { |
| 3913 | struct rpc_message msg = { |
| 3914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3915 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3916 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | }; |
| 3918 | unsigned long now = jiffies; |
| 3919 | int status; |
| 3920 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 3921 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | if (status < 0) |
| 3923 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3924 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | return 0; |
| 3926 | } |
| 3927 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3928 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3929 | { |
| 3930 | return (server->caps & NFS_CAP_ACLS) |
| 3931 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3932 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3933 | } |
| 3934 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3935 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3936 | * 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] | 3937 | * the stack. |
| 3938 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3939 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3940 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3941 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3942 | struct page **pages, unsigned int *pgbase) |
| 3943 | { |
| 3944 | struct page *newpage, **spages; |
| 3945 | int rc = 0; |
| 3946 | size_t len; |
| 3947 | spages = pages; |
| 3948 | |
| 3949 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3950 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3951 | newpage = alloc_page(GFP_KERNEL); |
| 3952 | |
| 3953 | if (newpage == NULL) |
| 3954 | goto unwind; |
| 3955 | memcpy(page_address(newpage), buf, len); |
| 3956 | buf += len; |
| 3957 | buflen -= len; |
| 3958 | *pages++ = newpage; |
| 3959 | rc++; |
| 3960 | } while (buflen != 0); |
| 3961 | |
| 3962 | return rc; |
| 3963 | |
| 3964 | unwind: |
| 3965 | for(; rc > 0; rc--) |
| 3966 | __free_page(spages[rc-1]); |
| 3967 | return -ENOMEM; |
| 3968 | } |
| 3969 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3970 | struct nfs4_cached_acl { |
| 3971 | int cached; |
| 3972 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3973 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3974 | }; |
| 3975 | |
| 3976 | 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] | 3977 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3978 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3979 | |
| 3980 | spin_lock(&inode->i_lock); |
| 3981 | kfree(nfsi->nfs4_acl); |
| 3982 | nfsi->nfs4_acl = acl; |
| 3983 | spin_unlock(&inode->i_lock); |
| 3984 | } |
| 3985 | |
| 3986 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3987 | { |
| 3988 | nfs4_set_cached_acl(inode, NULL); |
| 3989 | } |
| 3990 | |
| 3991 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3992 | { |
| 3993 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3994 | struct nfs4_cached_acl *acl; |
| 3995 | int ret = -ENOENT; |
| 3996 | |
| 3997 | spin_lock(&inode->i_lock); |
| 3998 | acl = nfsi->nfs4_acl; |
| 3999 | if (acl == NULL) |
| 4000 | goto out; |
| 4001 | if (buf == NULL) /* user is just asking for length */ |
| 4002 | goto out_len; |
| 4003 | if (acl->cached == 0) |
| 4004 | goto out; |
| 4005 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4006 | if (acl->len > buflen) |
| 4007 | goto out; |
| 4008 | memcpy(buf, acl->data, acl->len); |
| 4009 | out_len: |
| 4010 | ret = acl->len; |
| 4011 | out: |
| 4012 | spin_unlock(&inode->i_lock); |
| 4013 | return ret; |
| 4014 | } |
| 4015 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4016 | 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] | 4017 | { |
| 4018 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4019 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4020 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4021 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4022 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4023 | if (acl == NULL) |
| 4024 | goto out; |
| 4025 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4026 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4027 | } else { |
| 4028 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4029 | if (acl == NULL) |
| 4030 | goto out; |
| 4031 | acl->cached = 0; |
| 4032 | } |
| 4033 | acl->len = acl_len; |
| 4034 | out: |
| 4035 | nfs4_set_cached_acl(inode, acl); |
| 4036 | } |
| 4037 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4038 | /* |
| 4039 | * The getxattr API returns the required buffer length when called with a |
| 4040 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4041 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4042 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4043 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4044 | * the cache. If not so, we throw away the page, and cache the required |
| 4045 | * length. The next getxattr call will then produce another round trip to |
| 4046 | * the server, this time with the input buf of the required size. |
| 4047 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4048 | 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] | 4049 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4050 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4051 | struct nfs_getaclargs args = { |
| 4052 | .fh = NFS_FH(inode), |
| 4053 | .acl_pages = pages, |
| 4054 | .acl_len = buflen, |
| 4055 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4056 | struct nfs_getaclres res = { |
| 4057 | .acl_len = buflen, |
| 4058 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4059 | struct rpc_message msg = { |
| 4060 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4061 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4062 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4063 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4064 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4065 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4066 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4067 | /* As long as we're doing a round trip to the server anyway, |
| 4068 | * let's be prepared for a page of acl data. */ |
| 4069 | if (npages == 0) |
| 4070 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4071 | if (npages > ARRAY_SIZE(pages)) |
| 4072 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4073 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4074 | for (i = 0; i < npages; i++) { |
| 4075 | pages[i] = alloc_page(GFP_KERNEL); |
| 4076 | if (!pages[i]) |
| 4077 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4078 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4079 | |
| 4080 | /* for decoding across pages */ |
| 4081 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4082 | if (!res.acl_scratch) |
| 4083 | goto out_free; |
| 4084 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4085 | args.acl_len = npages * PAGE_SIZE; |
| 4086 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4087 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4088 | 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] | 4089 | __func__, buf, buflen, npages, args.acl_len); |
| 4090 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4091 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4092 | if (ret) |
| 4093 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4094 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4095 | /* Handle the case where the passed-in buffer is too short */ |
| 4096 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4097 | /* Did the user only issue a request for the acl length? */ |
| 4098 | if (buf == NULL) |
| 4099 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4100 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4101 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4102 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4103 | 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] | 4104 | if (buf) { |
| 4105 | if (res.acl_len > buflen) { |
| 4106 | ret = -ERANGE; |
| 4107 | goto out_free; |
| 4108 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4109 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4110 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4111 | out_ok: |
| 4112 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4113 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4114 | for (i = 0; i < npages; i++) |
| 4115 | if (pages[i]) |
| 4116 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4117 | if (res.acl_scratch) |
| 4118 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4119 | return ret; |
| 4120 | } |
| 4121 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4122 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4123 | { |
| 4124 | struct nfs4_exception exception = { }; |
| 4125 | ssize_t ret; |
| 4126 | do { |
| 4127 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 4128 | if (ret >= 0) |
| 4129 | break; |
| 4130 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4131 | } while (exception.retry); |
| 4132 | return ret; |
| 4133 | } |
| 4134 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4135 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4136 | { |
| 4137 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4138 | int ret; |
| 4139 | |
| 4140 | if (!nfs4_server_supports_acls(server)) |
| 4141 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4142 | ret = nfs_revalidate_inode(server, inode); |
| 4143 | if (ret < 0) |
| 4144 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4145 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4146 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4147 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4148 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4149 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4150 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4151 | return ret; |
| 4152 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4153 | } |
| 4154 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4155 | 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] | 4156 | { |
| 4157 | struct nfs_server *server = NFS_SERVER(inode); |
| 4158 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4159 | struct nfs_setaclargs arg = { |
| 4160 | .fh = NFS_FH(inode), |
| 4161 | .acl_pages = pages, |
| 4162 | .acl_len = buflen, |
| 4163 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4164 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4165 | struct rpc_message msg = { |
| 4166 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4167 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4168 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4169 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4170 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4171 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4172 | |
| 4173 | if (!nfs4_server_supports_acls(server)) |
| 4174 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4175 | if (npages > ARRAY_SIZE(pages)) |
| 4176 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4177 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4178 | if (i < 0) |
| 4179 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4180 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4181 | 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] | 4182 | |
| 4183 | /* |
| 4184 | * Free each page after tx, so the only ref left is |
| 4185 | * held by the network stack |
| 4186 | */ |
| 4187 | for (; i > 0; i--) |
| 4188 | put_page(pages[i-1]); |
| 4189 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4190 | /* |
| 4191 | * Acl update can result in inode attribute update. |
| 4192 | * so mark the attribute cache invalid. |
| 4193 | */ |
| 4194 | spin_lock(&inode->i_lock); |
| 4195 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4196 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4197 | nfs_access_zap_cache(inode); |
| 4198 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4199 | return ret; |
| 4200 | } |
| 4201 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4202 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4203 | { |
| 4204 | struct nfs4_exception exception = { }; |
| 4205 | int err; |
| 4206 | do { |
| 4207 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4208 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4209 | &exception); |
| 4210 | } while (exception.retry); |
| 4211 | return err; |
| 4212 | } |
| 4213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4215 | 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] | 4216 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4217 | struct nfs_client *clp = server->nfs_client; |
| 4218 | |
| 4219 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | return 0; |
| 4221 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4222 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4223 | case -NFS4ERR_ADMIN_REVOKED: |
| 4224 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4225 | if (state == NULL) |
| 4226 | break; |
| 4227 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4228 | case -NFS4ERR_OPENMODE: |
| 4229 | if (state == NULL) |
| 4230 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4231 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4232 | goto stateid_invalid; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4233 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4234 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4235 | if (state != NULL) { |
| 4236 | if (nfs4_schedule_stateid_recovery(server, state) < 0) |
| 4237 | goto stateid_invalid; |
| 4238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4240 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4241 | nfs4_schedule_lease_recovery(clp); |
| 4242 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4243 | #if defined(CONFIG_NFS_V4_1) |
| 4244 | case -NFS4ERR_BADSESSION: |
| 4245 | case -NFS4ERR_BADSLOT: |
| 4246 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4247 | case -NFS4ERR_DEADSESSION: |
| 4248 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4249 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4250 | case -NFS4ERR_SEQ_MISORDERED: |
| 4251 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4252 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4253 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4254 | task->tk_status = 0; |
| 4255 | return -EAGAIN; |
| 4256 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4258 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4259 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4261 | task->tk_status = 0; |
| 4262 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4263 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | case -NFS4ERR_OLD_STATEID: |
| 4265 | task->tk_status = 0; |
| 4266 | return -EAGAIN; |
| 4267 | } |
| 4268 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4269 | return 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4270 | stateid_invalid: |
| 4271 | task->tk_status = -EIO; |
| 4272 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4273 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4274 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4275 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4276 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4277 | task->tk_status = 0; |
| 4278 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4281 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4282 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4283 | { |
| 4284 | __be32 verf[2]; |
| 4285 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4286 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4287 | /* An impossible timestamp guarantees this value |
| 4288 | * will never match a generated boot time. */ |
| 4289 | verf[0] = 0; |
| 4290 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4291 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4292 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4293 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4294 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4295 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4296 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4297 | } |
| 4298 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4299 | static unsigned int |
| 4300 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4301 | char *buf, size_t len) |
| 4302 | { |
| 4303 | unsigned int result; |
| 4304 | |
| 4305 | rcu_read_lock(); |
| 4306 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4307 | clp->cl_ipaddr, |
| 4308 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4309 | RPC_DISPLAY_ADDR), |
| 4310 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4311 | RPC_DISPLAY_PROTO)); |
| 4312 | rcu_read_unlock(); |
| 4313 | return result; |
| 4314 | } |
| 4315 | |
| 4316 | static unsigned int |
| 4317 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4318 | char *buf, size_t len) |
| 4319 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4320 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4321 | |
| 4322 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4323 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4324 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4325 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4326 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4327 | } |
| 4328 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4329 | /** |
| 4330 | * nfs4_proc_setclientid - Negotiate client ID |
| 4331 | * @clp: state data structure |
| 4332 | * @program: RPC program for NFSv4 callback service |
| 4333 | * @port: IP port number for NFS4 callback service |
| 4334 | * @cred: RPC credential to use for this call |
| 4335 | * @res: where to place the result |
| 4336 | * |
| 4337 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4338 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4339 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4340 | unsigned short port, struct rpc_cred *cred, |
| 4341 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | { |
| 4343 | nfs4_verifier sc_verifier; |
| 4344 | struct nfs4_setclientid setclientid = { |
| 4345 | .sc_verifier = &sc_verifier, |
| 4346 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4347 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | }; |
| 4349 | struct rpc_message msg = { |
| 4350 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4351 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4352 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4353 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4355 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4357 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4358 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4359 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4360 | setclientid.sc_name_len = |
| 4361 | nfs4_init_uniform_client_string(clp, |
| 4362 | setclientid.sc_name, |
| 4363 | sizeof(setclientid.sc_name)); |
| 4364 | else |
| 4365 | setclientid.sc_name_len = |
| 4366 | nfs4_init_nonuniform_client_string(clp, |
| 4367 | setclientid.sc_name, |
| 4368 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4369 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4370 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4371 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4372 | sizeof(setclientid.sc_netid), |
| 4373 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4374 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4375 | rcu_read_unlock(); |
| 4376 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4377 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4379 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4380 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4381 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4382 | setclientid.sc_name_len, setclientid.sc_name); |
| 4383 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4384 | dprintk("NFS reply setclientid: %d\n", status); |
| 4385 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | } |
| 4387 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4388 | /** |
| 4389 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4390 | * @clp: state data structure |
| 4391 | * @res: result of a previous SETCLIENTID |
| 4392 | * @cred: RPC credential to use for this call |
| 4393 | * |
| 4394 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4395 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4396 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4397 | struct nfs4_setclientid_res *arg, |
| 4398 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | struct rpc_message msg = { |
| 4401 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4402 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4403 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | int status; |
| 4406 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4407 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4408 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4409 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4410 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4411 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | return status; |
| 4413 | } |
| 4414 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4415 | struct nfs4_delegreturndata { |
| 4416 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4417 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4418 | struct nfs_fh fh; |
| 4419 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4420 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4421 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4422 | int rpc_status; |
| 4423 | }; |
| 4424 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4425 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4426 | { |
| 4427 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4428 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4429 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4430 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4431 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4432 | switch (task->tk_status) { |
| 4433 | case -NFS4ERR_STALE_STATEID: |
| 4434 | case -NFS4ERR_EXPIRED: |
| 4435 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4436 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4437 | break; |
| 4438 | default: |
| 4439 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4440 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4441 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4442 | return; |
| 4443 | } |
| 4444 | } |
| 4445 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | static void nfs4_delegreturn_release(void *calldata) |
| 4449 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4450 | kfree(calldata); |
| 4451 | } |
| 4452 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4453 | #if defined(CONFIG_NFS_V4_1) |
| 4454 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4455 | { |
| 4456 | struct nfs4_delegreturndata *d_data; |
| 4457 | |
| 4458 | d_data = (struct nfs4_delegreturndata *)data; |
| 4459 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4460 | nfs4_setup_sequence(d_data->res.server, |
| 4461 | &d_data->args.seq_args, |
| 4462 | &d_data->res.seq_res, |
| 4463 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4464 | } |
| 4465 | #endif /* CONFIG_NFS_V4_1 */ |
| 4466 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4467 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4468 | #if defined(CONFIG_NFS_V4_1) |
| 4469 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4470 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4471 | .rpc_call_done = nfs4_delegreturn_done, |
| 4472 | .rpc_release = nfs4_delegreturn_release, |
| 4473 | }; |
| 4474 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4475 | 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] | 4476 | { |
| 4477 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4478 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4479 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4480 | struct rpc_message msg = { |
| 4481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4482 | .rpc_cred = cred, |
| 4483 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4484 | struct rpc_task_setup task_setup_data = { |
| 4485 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4486 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4487 | .callback_ops = &nfs4_delegreturn_ops, |
| 4488 | .flags = RPC_TASK_ASYNC, |
| 4489 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4490 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4491 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4492 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4493 | if (data == NULL) |
| 4494 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4495 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4496 | data->args.fhandle = &data->fh; |
| 4497 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4498 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4499 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4500 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4501 | data->res.fattr = &data->fattr; |
| 4502 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4503 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4504 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4505 | data->rpc_status = 0; |
| 4506 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4507 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4508 | msg.rpc_argp = &data->args; |
| 4509 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4510 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4511 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4512 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4513 | if (!issync) |
| 4514 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4515 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4516 | if (status != 0) |
| 4517 | goto out; |
| 4518 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4519 | if (status == 0) |
| 4520 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4521 | else |
| 4522 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4523 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4524 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4525 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | } |
| 4527 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4528 | 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] | 4529 | { |
| 4530 | struct nfs_server *server = NFS_SERVER(inode); |
| 4531 | struct nfs4_exception exception = { }; |
| 4532 | int err; |
| 4533 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4534 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | switch (err) { |
| 4536 | case -NFS4ERR_STALE_STATEID: |
| 4537 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | case 0: |
| 4539 | return 0; |
| 4540 | } |
| 4541 | err = nfs4_handle_exception(server, err, &exception); |
| 4542 | } while (exception.retry); |
| 4543 | return err; |
| 4544 | } |
| 4545 | |
| 4546 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4547 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4548 | |
| 4549 | /* |
| 4550 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4551 | */ |
| 4552 | static unsigned long |
| 4553 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4554 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4555 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | timeout <<= 1; |
| 4557 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4558 | return NFS4_LOCK_MAXTIMEOUT; |
| 4559 | return timeout; |
| 4560 | } |
| 4561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4563 | { |
| 4564 | struct inode *inode = state->inode; |
| 4565 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4566 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4567 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4569 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4571 | struct nfs_lockt_res res = { |
| 4572 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | }; |
| 4574 | struct rpc_message msg = { |
| 4575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4576 | .rpc_argp = &arg, |
| 4577 | .rpc_resp = &res, |
| 4578 | .rpc_cred = state->owner->so_cred, |
| 4579 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | struct nfs4_lock_state *lsp; |
| 4581 | int status; |
| 4582 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4583 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4584 | status = nfs4_set_lock_state(state, request); |
| 4585 | if (status != 0) |
| 4586 | goto out; |
| 4587 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4588 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4589 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4590 | 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] | 4591 | switch (status) { |
| 4592 | case 0: |
| 4593 | request->fl_type = F_UNLCK; |
| 4594 | break; |
| 4595 | case -NFS4ERR_DENIED: |
| 4596 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4598 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4599 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | return status; |
| 4601 | } |
| 4602 | |
| 4603 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4604 | { |
| 4605 | struct nfs4_exception exception = { }; |
| 4606 | int err; |
| 4607 | |
| 4608 | do { |
| 4609 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4610 | _nfs4_proc_getlk(state, cmd, request), |
| 4611 | &exception); |
| 4612 | } while (exception.retry); |
| 4613 | return err; |
| 4614 | } |
| 4615 | |
| 4616 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4617 | { |
| 4618 | int res = 0; |
| 4619 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4620 | case FL_POSIX: |
| 4621 | res = posix_lock_file_wait(file, fl); |
| 4622 | break; |
| 4623 | case FL_FLOCK: |
| 4624 | res = flock_lock_file_wait(file, fl); |
| 4625 | break; |
| 4626 | default: |
| 4627 | BUG(); |
| 4628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | return res; |
| 4630 | } |
| 4631 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4632 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4633 | struct nfs_locku_args arg; |
| 4634 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4635 | struct nfs4_lock_state *lsp; |
| 4636 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4637 | struct file_lock fl; |
| 4638 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4639 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4640 | }; |
| 4641 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4642 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4643 | struct nfs_open_context *ctx, |
| 4644 | struct nfs4_lock_state *lsp, |
| 4645 | struct nfs_seqid *seqid) |
| 4646 | { |
| 4647 | struct nfs4_unlockdata *p; |
| 4648 | struct inode *inode = lsp->ls_state->inode; |
| 4649 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4650 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4651 | if (p == NULL) |
| 4652 | return NULL; |
| 4653 | p->arg.fh = NFS_FH(inode); |
| 4654 | p->arg.fl = &p->fl; |
| 4655 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4656 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4657 | p->arg.stateid = &lsp->ls_stateid; |
| 4658 | p->lsp = lsp; |
| 4659 | atomic_inc(&lsp->ls_count); |
| 4660 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4661 | p->ctx = get_nfs_open_context(ctx); |
| 4662 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4663 | p->server = NFS_SERVER(inode); |
| 4664 | return p; |
| 4665 | } |
| 4666 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4667 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4668 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4669 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4670 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4671 | nfs4_put_lock_state(calldata->lsp); |
| 4672 | put_nfs_open_context(calldata->ctx); |
| 4673 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4676 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4677 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4678 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4679 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4680 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4681 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4682 | switch (task->tk_status) { |
| 4683 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4684 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4685 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4686 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4687 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4688 | case -NFS4ERR_BAD_STATEID: |
| 4689 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4690 | case -NFS4ERR_STALE_STATEID: |
| 4691 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4692 | break; |
| 4693 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4694 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4695 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4696 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4697 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4700 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4701 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4702 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4704 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4705 | goto out_wait; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4706 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4707 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4708 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4709 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4710 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4711 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4712 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4713 | &calldata->res.seq_res, |
| 4714 | task) != 0) |
| 4715 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4716 | return; |
| 4717 | out_no_action: |
| 4718 | task->tk_action = NULL; |
| 4719 | out_wait: |
| 4720 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4723 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4724 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4725 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4726 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4727 | }; |
| 4728 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4729 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4730 | struct nfs_open_context *ctx, |
| 4731 | struct nfs4_lock_state *lsp, |
| 4732 | struct nfs_seqid *seqid) |
| 4733 | { |
| 4734 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4735 | struct rpc_message msg = { |
| 4736 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4737 | .rpc_cred = ctx->cred, |
| 4738 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4739 | struct rpc_task_setup task_setup_data = { |
| 4740 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4741 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4742 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4743 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4744 | .flags = RPC_TASK_ASYNC, |
| 4745 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4746 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4747 | /* Ensure this is an unlock - when canceling a lock, the |
| 4748 | * canceled lock is passed in, and it won't be an unlock. |
| 4749 | */ |
| 4750 | fl->fl_type = F_UNLCK; |
| 4751 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4752 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4753 | if (data == NULL) { |
| 4754 | nfs_free_seqid(seqid); |
| 4755 | return ERR_PTR(-ENOMEM); |
| 4756 | } |
| 4757 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4758 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4759 | msg.rpc_argp = &data->arg; |
| 4760 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4761 | task_setup_data.callback_data = data; |
| 4762 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4766 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4767 | struct inode *inode = state->inode; |
| 4768 | struct nfs4_state_owner *sp = state->owner; |
| 4769 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4770 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4771 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4772 | struct rpc_task *task; |
| 4773 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4774 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4776 | status = nfs4_set_lock_state(state, request); |
| 4777 | /* Unlock _before_ we do the RPC call */ |
| 4778 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4779 | /* Exclude nfs_delegation_claim_locks() */ |
| 4780 | mutex_lock(&sp->so_delegreturn_mutex); |
| 4781 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4782 | down_read(&nfsi->rwsem); |
| 4783 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4784 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4785 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4786 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4787 | } |
| 4788 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 4789 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4790 | if (status != 0) |
| 4791 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4792 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4793 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 4794 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 4795 | goto out; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4796 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4797 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4798 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4799 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4800 | 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] | 4801 | status = PTR_ERR(task); |
| 4802 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4803 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4804 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4805 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4806 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4807 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4808 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | } |
| 4810 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4811 | struct nfs4_lockdata { |
| 4812 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4813 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4814 | struct nfs4_lock_state *lsp; |
| 4815 | struct nfs_open_context *ctx; |
| 4816 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4817 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4818 | int rpc_status; |
| 4819 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4820 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4821 | }; |
| 4822 | |
| 4823 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4824 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4825 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4826 | { |
| 4827 | struct nfs4_lockdata *p; |
| 4828 | struct inode *inode = lsp->ls_state->inode; |
| 4829 | struct nfs_server *server = NFS_SERVER(inode); |
| 4830 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4831 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4832 | if (p == NULL) |
| 4833 | return NULL; |
| 4834 | |
| 4835 | p->arg.fh = NFS_FH(inode); |
| 4836 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4837 | 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] | 4838 | if (p->arg.open_seqid == NULL) |
| 4839 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4840 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4841 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4842 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4843 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4844 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4845 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4846 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4847 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4848 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4849 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4850 | atomic_inc(&lsp->ls_count); |
| 4851 | p->ctx = get_nfs_open_context(ctx); |
| 4852 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4853 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4854 | out_free_seqid: |
| 4855 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4856 | out_free: |
| 4857 | kfree(p); |
| 4858 | return NULL; |
| 4859 | } |
| 4860 | |
| 4861 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4862 | { |
| 4863 | struct nfs4_lockdata *data = calldata; |
| 4864 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4866 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4867 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4868 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4869 | /* Do we need to do an open_to_lock_owner? */ |
| 4870 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4871 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4872 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4873 | } |
Trond Myklebust | 8e472f3 | 2013-04-20 01:30:53 -0400 | [diff] [blame] | 4874 | data->arg.open_stateid = &state->open_stateid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4875 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4876 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4877 | } else |
| 4878 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4879 | if (!nfs4_valid_open_stateid(state)) { |
| 4880 | data->rpc_status = -EBADF; |
| 4881 | task->tk_action = NULL; |
| 4882 | goto out_release_open_seqid; |
| 4883 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4884 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4885 | if (nfs4_setup_sequence(data->server, |
| 4886 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4887 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4888 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4889 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 4890 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4891 | nfs_release_seqid(data->arg.open_seqid); |
| 4892 | out_release_lock_seqid: |
| 4893 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 4894 | out_wait: |
| 4895 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4896 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4897 | } |
| 4898 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4899 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4900 | { |
| 4901 | struct nfs4_lockdata *data = calldata; |
| 4902 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4903 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4904 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4905 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4906 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4907 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4908 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4909 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4910 | if (data->rpc_status == 0) |
| 4911 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4912 | else |
| 4913 | goto out; |
| 4914 | } |
| 4915 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4916 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4917 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4918 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4919 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4920 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4921 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | static void nfs4_lock_release(void *calldata) |
| 4925 | { |
| 4926 | struct nfs4_lockdata *data = calldata; |
| 4927 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4928 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4929 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4930 | if (data->cancelled != 0) { |
| 4931 | struct rpc_task *task; |
| 4932 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4933 | data->arg.lock_seqid); |
| 4934 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4935 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4936 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4937 | } else |
| 4938 | nfs_free_seqid(data->arg.lock_seqid); |
| 4939 | nfs4_put_lock_state(data->lsp); |
| 4940 | put_nfs_open_context(data->ctx); |
| 4941 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4942 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4946 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4947 | .rpc_call_done = nfs4_lock_done, |
| 4948 | .rpc_release = nfs4_lock_release, |
| 4949 | }; |
| 4950 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4951 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4952 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4953 | switch (error) { |
| 4954 | case -NFS4ERR_ADMIN_REVOKED: |
| 4955 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4956 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4957 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4958 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4959 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4960 | break; |
| 4961 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4962 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4963 | case -NFS4ERR_EXPIRED: |
| 4964 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4965 | }; |
| 4966 | } |
| 4967 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4968 | 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] | 4969 | { |
| 4970 | struct nfs4_lockdata *data; |
| 4971 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4972 | struct rpc_message msg = { |
| 4973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4974 | .rpc_cred = state->owner->so_cred, |
| 4975 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4976 | struct rpc_task_setup task_setup_data = { |
| 4977 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4978 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4979 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4980 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4981 | .flags = RPC_TASK_ASYNC, |
| 4982 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4983 | int ret; |
| 4984 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4985 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4986 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4987 | fl->fl_u.nfs4_fl.owner, |
| 4988 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4989 | if (data == NULL) |
| 4990 | return -ENOMEM; |
| 4991 | if (IS_SETLKW(cmd)) |
| 4992 | data->arg.block = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4993 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4994 | msg.rpc_argp = &data->arg; |
| 4995 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4996 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 4997 | if (recovery_type > NFS_LOCK_NEW) { |
| 4998 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 4999 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5000 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5001 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5002 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5003 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5004 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5005 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 5006 | if (ret == 0) { |
| 5007 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5008 | if (ret) |
| 5009 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 5010 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5011 | } else |
| 5012 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5013 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5014 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5015 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 5019 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5020 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5021 | struct nfs4_exception exception = { |
| 5022 | .inode = state->inode, |
| 5023 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5024 | int err; |
| 5025 | |
| 5026 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5027 | /* Cache the lock if possible... */ |
| 5028 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5029 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5030 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5031 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5032 | break; |
| 5033 | nfs4_handle_exception(server, err, &exception); |
| 5034 | } while (exception.retry); |
| 5035 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5039 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5040 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5041 | struct nfs4_exception exception = { |
| 5042 | .inode = state->inode, |
| 5043 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5044 | int err; |
| 5045 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5046 | err = nfs4_set_lock_state(state, request); |
| 5047 | if (err != 0) |
| 5048 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5049 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 5050 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 5051 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5052 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5053 | switch (err) { |
| 5054 | default: |
| 5055 | goto out; |
| 5056 | case -NFS4ERR_GRACE: |
| 5057 | case -NFS4ERR_DELAY: |
| 5058 | nfs4_handle_exception(server, err, &exception); |
| 5059 | err = 0; |
| 5060 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5061 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 5062 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 5063 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5066 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5067 | /** |
| 5068 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 5069 | * |
| 5070 | * @state: NFSv4 state for an inode |
| 5071 | * |
| 5072 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 5073 | * Otherwise a negative NFS4ERR value is returned. |
| 5074 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5075 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5076 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5077 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5078 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5079 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5080 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5081 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5082 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5083 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 5084 | |
| 5085 | status = nfs41_test_stateid(server, |
| 5086 | &lsp->ls_stateid, |
| 5087 | cred); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5088 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 5089 | /* Free the stateid unless the server |
| 5090 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 5091 | if (status != -NFS4ERR_BAD_STATEID) |
| 5092 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 5093 | &lsp->ls_stateid, |
| 5094 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5095 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 5096 | ret = status; |
| 5097 | } |
| 5098 | } |
| 5099 | }; |
| 5100 | |
| 5101 | return ret; |
| 5102 | } |
| 5103 | |
| 5104 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 5105 | { |
| 5106 | int status = NFS_OK; |
| 5107 | |
| 5108 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 5109 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 5110 | if (status != NFS_OK) |
| 5111 | status = nfs4_lock_expired(state, request); |
| 5112 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 5113 | } |
| 5114 | #endif |
| 5115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5117 | { |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5118 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5119 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5120 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5121 | unsigned int seq; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5122 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 5124 | if ((fl_flags & FL_POSIX) && |
| 5125 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 5126 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5127 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5128 | status = nfs4_set_lock_state(state, request); |
| 5129 | if (status != 0) |
| 5130 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5131 | request->fl_flags |= FL_ACCESS; |
| 5132 | status = do_vfs_lock(request->fl_file, request); |
| 5133 | if (status < 0) |
| 5134 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5135 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5136 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5137 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5138 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5139 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5140 | status = do_vfs_lock(request->fl_file, request); |
| 5141 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5142 | } |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5143 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 5144 | up_read(&nfsi->rwsem); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5145 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5146 | if (status != 0) |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5147 | goto out; |
| 5148 | down_read(&nfsi->rwsem); |
| 5149 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { |
| 5150 | status = -NFS4ERR_DELAY; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5151 | goto out_unlock; |
Trond Myklebust | 9a99af49 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 5152 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5153 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5154 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5155 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5156 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 5157 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5158 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5159 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 5160 | out: |
| 5161 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | return status; |
| 5163 | } |
| 5164 | |
| 5165 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5166 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5167 | struct nfs4_exception exception = { |
| 5168 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 5169 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5170 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | int err; |
| 5172 | |
| 5173 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5174 | err = _nfs4_proc_setlk(state, cmd, request); |
| 5175 | if (err == -NFS4ERR_DENIED) |
| 5176 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5178 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | } while (exception.retry); |
| 5180 | return err; |
| 5181 | } |
| 5182 | |
| 5183 | static int |
| 5184 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 5185 | { |
| 5186 | struct nfs_open_context *ctx; |
| 5187 | struct nfs4_state *state; |
| 5188 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 5189 | int status; |
| 5190 | |
| 5191 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5192 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | state = ctx->state; |
| 5194 | |
| 5195 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5196 | return -EINVAL; |
| 5197 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5198 | if (IS_GETLK(cmd)) { |
| 5199 | if (state != NULL) |
| 5200 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5201 | return 0; |
| 5202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | |
| 5204 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5205 | return -EINVAL; |
| 5206 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5207 | if (request->fl_type == F_UNLCK) { |
| 5208 | if (state != NULL) |
| 5209 | return nfs4_proc_unlck(state, cmd, request); |
| 5210 | return 0; |
| 5211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5212 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5213 | if (state == NULL) |
| 5214 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5215 | /* |
| 5216 | * Don't rely on the VFS having checked the file open mode, |
| 5217 | * since it won't do this for flock() locks. |
| 5218 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5219 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5220 | case F_RDLCK: |
| 5221 | if (!(filp->f_mode & FMODE_READ)) |
| 5222 | return -EBADF; |
| 5223 | break; |
| 5224 | case F_WRLCK: |
| 5225 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5226 | return -EBADF; |
| 5227 | } |
| 5228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | do { |
| 5230 | status = nfs4_proc_setlk(state, cmd, request); |
| 5231 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5232 | break; |
| 5233 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5234 | status = -ERESTARTSYS; |
| 5235 | if (signalled()) |
| 5236 | break; |
| 5237 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | return status; |
| 5239 | } |
| 5240 | |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5241 | 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] | 5242 | { |
| 5243 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5244 | int err; |
| 5245 | |
| 5246 | err = nfs4_set_lock_state(state, fl); |
| 5247 | if (err != 0) |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5248 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 5249 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e63 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 5250 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5251 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5252 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5253 | struct nfs_release_lockowner_data { |
| 5254 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5255 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5256 | struct nfs_release_lockowner_args args; |
| 5257 | }; |
| 5258 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5259 | static void nfs4_release_lockowner_release(void *calldata) |
| 5260 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5261 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5262 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5263 | kfree(calldata); |
| 5264 | } |
| 5265 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5266 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5267 | .rpc_release = nfs4_release_lockowner_release, |
| 5268 | }; |
| 5269 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 5270 | 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] | 5271 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5272 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5273 | struct rpc_message msg = { |
| 5274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5275 | }; |
| 5276 | |
| 5277 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5278 | return -EINVAL; |
| 5279 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5280 | if (!data) |
| 5281 | return -ENOMEM; |
| 5282 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5283 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5284 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5285 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5286 | data->args.lock_owner.s_dev = server->s_dev; |
| 5287 | msg.rpc_argp = &data->args; |
| 5288 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5289 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5290 | } |
| 5291 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5292 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5293 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5294 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5295 | const void *buf, size_t buflen, |
| 5296 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5297 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5298 | if (strcmp(key, "") != 0) |
| 5299 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5300 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5301 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5302 | } |
| 5303 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5304 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5305 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5306 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5307 | if (strcmp(key, "") != 0) |
| 5308 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5309 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5310 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5313 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5314 | size_t list_len, const char *name, |
| 5315 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5316 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5317 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5318 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5319 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5320 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5321 | |
| 5322 | if (list && len <= list_len) |
| 5323 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5324 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5327 | /* |
| 5328 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5329 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5330 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5331 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5332 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5333 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5334 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5335 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5336 | return; |
| 5337 | |
| 5338 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5339 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5340 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5341 | fattr->nlink = 2; |
| 5342 | } |
| 5343 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5344 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5345 | const struct qstr *name, |
| 5346 | struct nfs4_fs_locations *fs_locations, |
| 5347 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5348 | { |
| 5349 | struct nfs_server *server = NFS_SERVER(dir); |
| 5350 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5351 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5352 | }; |
| 5353 | struct nfs4_fs_locations_arg args = { |
| 5354 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5355 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5356 | .page = page, |
| 5357 | .bitmask = bitmask, |
| 5358 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5359 | struct nfs4_fs_locations_res res = { |
| 5360 | .fs_locations = fs_locations, |
| 5361 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5362 | struct rpc_message msg = { |
| 5363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5364 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5365 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5366 | }; |
| 5367 | int status; |
| 5368 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5369 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5370 | |
| 5371 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5372 | * is not supported */ |
| 5373 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5374 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5375 | else |
| 5376 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5377 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5378 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5379 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5380 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5381 | 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] | 5382 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5383 | return status; |
| 5384 | } |
| 5385 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5386 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5387 | const struct qstr *name, |
| 5388 | struct nfs4_fs_locations *fs_locations, |
| 5389 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5390 | { |
| 5391 | struct nfs4_exception exception = { }; |
| 5392 | int err; |
| 5393 | do { |
| 5394 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5395 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5396 | &exception); |
| 5397 | } while (exception.retry); |
| 5398 | return err; |
| 5399 | } |
| 5400 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5401 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5402 | { |
| 5403 | int status; |
| 5404 | struct nfs4_secinfo_arg args = { |
| 5405 | .dir_fh = NFS_FH(dir), |
| 5406 | .name = name, |
| 5407 | }; |
| 5408 | struct nfs4_secinfo_res res = { |
| 5409 | .flavors = flavors, |
| 5410 | }; |
| 5411 | struct rpc_message msg = { |
| 5412 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5413 | .rpc_argp = &args, |
| 5414 | .rpc_resp = &res, |
| 5415 | }; |
| 5416 | |
| 5417 | dprintk("NFS call secinfo %s\n", name->name); |
| 5418 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5419 | dprintk("NFS reply secinfo: %d\n", status); |
| 5420 | return status; |
| 5421 | } |
| 5422 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5423 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5424 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5425 | { |
| 5426 | struct nfs4_exception exception = { }; |
| 5427 | int err; |
| 5428 | do { |
| 5429 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5430 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5431 | &exception); |
| 5432 | } while (exception.retry); |
| 5433 | return err; |
| 5434 | } |
| 5435 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5436 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5437 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5438 | * Check the exchange flags returned by the server for invalid flags, having |
| 5439 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5440 | * DS flags set. |
| 5441 | */ |
| 5442 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5443 | { |
| 5444 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5445 | goto out_inval; |
| 5446 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5447 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5448 | goto out_inval; |
| 5449 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5450 | goto out_inval; |
| 5451 | return NFS_OK; |
| 5452 | out_inval: |
| 5453 | return -NFS4ERR_INVAL; |
| 5454 | } |
| 5455 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5456 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5457 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5458 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5459 | { |
| 5460 | if (a->server_scope_sz == b->server_scope_sz && |
| 5461 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5462 | return true; |
| 5463 | |
| 5464 | return false; |
| 5465 | } |
| 5466 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5467 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5468 | * nfs4_proc_bind_conn_to_session() |
| 5469 | * |
| 5470 | * The 4.1 client currently uses the same TCP connection for the |
| 5471 | * fore and backchannel. |
| 5472 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5473 | 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] | 5474 | { |
| 5475 | int status; |
| 5476 | struct nfs41_bind_conn_to_session_res res; |
| 5477 | struct rpc_message msg = { |
| 5478 | .rpc_proc = |
| 5479 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5480 | .rpc_argp = clp, |
| 5481 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5482 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5483 | }; |
| 5484 | |
| 5485 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5486 | |
| 5487 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5488 | if (unlikely(res.session == NULL)) { |
| 5489 | status = -ENOMEM; |
| 5490 | goto out; |
| 5491 | } |
| 5492 | |
| 5493 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5494 | if (status == 0) { |
| 5495 | if (memcmp(res.session->sess_id.data, |
| 5496 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5497 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5498 | status = -EIO; |
| 5499 | goto out_session; |
| 5500 | } |
| 5501 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5502 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5503 | __func__); |
| 5504 | status = -EIO; |
| 5505 | goto out_session; |
| 5506 | } |
| 5507 | if (res.use_conn_in_rdma_mode) { |
| 5508 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5509 | __func__); |
| 5510 | status = -EIO; |
| 5511 | goto out_session; |
| 5512 | } |
| 5513 | } |
| 5514 | out_session: |
| 5515 | kfree(res.session); |
| 5516 | out: |
| 5517 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5518 | return status; |
| 5519 | } |
| 5520 | |
| 5521 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5522 | * nfs4_proc_exchange_id() |
| 5523 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5524 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5525 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5526 | * Since the clientid has expired, all compounds using sessions |
| 5527 | * associated with the stale clientid will be returning |
| 5528 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5529 | * be in some phase of session reset. |
| 5530 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5531 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5532 | { |
| 5533 | nfs4_verifier verifier; |
| 5534 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5535 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5536 | .client = clp, |
Trond Myklebust | 4f0b429 | 2013-05-20 12:24:03 -0400 | [diff] [blame] | 5537 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 5538 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5539 | }; |
| 5540 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5541 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5542 | }; |
| 5543 | int status; |
| 5544 | struct rpc_message msg = { |
| 5545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5546 | .rpc_argp = &args, |
| 5547 | .rpc_resp = &res, |
| 5548 | .rpc_cred = cred, |
| 5549 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5550 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5551 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5552 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5553 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5554 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5555 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5556 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5557 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5558 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5559 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5560 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5561 | status = -ENOMEM; |
| 5562 | goto out; |
| 5563 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5564 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5565 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5566 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5567 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5568 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5569 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5570 | } |
| 5571 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5572 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5573 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5574 | status = -ENOMEM; |
| 5575 | goto out_server_scope; |
| 5576 | } |
| 5577 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5578 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5579 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5580 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5581 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5582 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5583 | clp->cl_clientid = res.clientid; |
| 5584 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5585 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5586 | clp->cl_seqid = res.seqid; |
| 5587 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5588 | kfree(clp->cl_serverowner); |
| 5589 | clp->cl_serverowner = res.server_owner; |
| 5590 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5591 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5592 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5593 | kfree(clp->cl_implid); |
| 5594 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5595 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5596 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5597 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5598 | res.server_scope)) { |
| 5599 | dprintk("%s: server_scope mismatch detected\n", |
| 5600 | __func__); |
| 5601 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5602 | kfree(clp->cl_serverscope); |
| 5603 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5604 | } |
| 5605 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5606 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5607 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5608 | goto out; |
| 5609 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5610 | } else |
| 5611 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5612 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5613 | out_server_owner: |
| 5614 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5615 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5616 | kfree(res.server_scope); |
| 5617 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5618 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5619 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5620 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5621 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5622 | clp->cl_implid->date.seconds, |
| 5623 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5624 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5625 | return status; |
| 5626 | } |
| 5627 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5628 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5629 | struct rpc_cred *cred) |
| 5630 | { |
| 5631 | struct rpc_message msg = { |
| 5632 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5633 | .rpc_argp = clp, |
| 5634 | .rpc_cred = cred, |
| 5635 | }; |
| 5636 | int status; |
| 5637 | |
| 5638 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5639 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5640 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5641 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5642 | return status; |
| 5643 | } |
| 5644 | |
| 5645 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5646 | struct rpc_cred *cred) |
| 5647 | { |
| 5648 | unsigned int loop; |
| 5649 | int ret; |
| 5650 | |
| 5651 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5652 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5653 | switch (ret) { |
| 5654 | case -NFS4ERR_DELAY: |
| 5655 | case -NFS4ERR_CLIENTID_BUSY: |
| 5656 | ssleep(1); |
| 5657 | break; |
| 5658 | default: |
| 5659 | return ret; |
| 5660 | } |
| 5661 | } |
| 5662 | return 0; |
| 5663 | } |
| 5664 | |
| 5665 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5666 | { |
| 5667 | struct rpc_cred *cred; |
| 5668 | int ret = 0; |
| 5669 | |
| 5670 | if (clp->cl_mvops->minor_version < 1) |
| 5671 | goto out; |
| 5672 | if (clp->cl_exchange_flags == 0) |
| 5673 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5674 | if (clp->cl_preserve_clid) |
| 5675 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5676 | cred = nfs4_get_exchange_id_cred(clp); |
| 5677 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5678 | if (cred) |
| 5679 | put_rpccred(cred); |
| 5680 | switch (ret) { |
| 5681 | case 0: |
| 5682 | case -NFS4ERR_STALE_CLIENTID: |
| 5683 | clp->cl_exchange_flags = 0; |
| 5684 | } |
| 5685 | out: |
| 5686 | return ret; |
| 5687 | } |
| 5688 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5689 | struct nfs4_get_lease_time_data { |
| 5690 | struct nfs4_get_lease_time_args *args; |
| 5691 | struct nfs4_get_lease_time_res *res; |
| 5692 | struct nfs_client *clp; |
| 5693 | }; |
| 5694 | |
| 5695 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5696 | void *calldata) |
| 5697 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5698 | struct nfs4_get_lease_time_data *data = |
| 5699 | (struct nfs4_get_lease_time_data *)calldata; |
| 5700 | |
| 5701 | dprintk("--> %s\n", __func__); |
| 5702 | /* just setup sequence, do not trigger session recovery |
| 5703 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5704 | nfs41_setup_sequence(data->clp->cl_session, |
| 5705 | &data->args->la_seq_args, |
| 5706 | &data->res->lr_seq_res, |
| 5707 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5708 | dprintk("<-- %s\n", __func__); |
| 5709 | } |
| 5710 | |
| 5711 | /* |
| 5712 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5713 | * from sequence operation or clientid errors. |
| 5714 | */ |
| 5715 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5716 | { |
| 5717 | struct nfs4_get_lease_time_data *data = |
| 5718 | (struct nfs4_get_lease_time_data *)calldata; |
| 5719 | |
| 5720 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5721 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5722 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5723 | switch (task->tk_status) { |
| 5724 | case -NFS4ERR_DELAY: |
| 5725 | case -NFS4ERR_GRACE: |
| 5726 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5727 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5728 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5729 | /* fall through */ |
| 5730 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5731 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5732 | return; |
| 5733 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5734 | dprintk("<-- %s\n", __func__); |
| 5735 | } |
| 5736 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5737 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5738 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5739 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5740 | }; |
| 5741 | |
| 5742 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5743 | { |
| 5744 | struct rpc_task *task; |
| 5745 | struct nfs4_get_lease_time_args args; |
| 5746 | struct nfs4_get_lease_time_res res = { |
| 5747 | .lr_fsinfo = fsinfo, |
| 5748 | }; |
| 5749 | struct nfs4_get_lease_time_data data = { |
| 5750 | .args = &args, |
| 5751 | .res = &res, |
| 5752 | .clp = clp, |
| 5753 | }; |
| 5754 | struct rpc_message msg = { |
| 5755 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5756 | .rpc_argp = &args, |
| 5757 | .rpc_resp = &res, |
| 5758 | }; |
| 5759 | struct rpc_task_setup task_setup = { |
| 5760 | .rpc_client = clp->cl_rpcclient, |
| 5761 | .rpc_message = &msg, |
| 5762 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5763 | .callback_data = &data, |
| 5764 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5765 | }; |
| 5766 | int status; |
| 5767 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5768 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5769 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5770 | dprintk("--> %s\n", __func__); |
| 5771 | task = rpc_run_task(&task_setup); |
| 5772 | |
| 5773 | if (IS_ERR(task)) |
| 5774 | status = PTR_ERR(task); |
| 5775 | else { |
| 5776 | status = task->tk_status; |
| 5777 | rpc_put_task(task); |
| 5778 | } |
| 5779 | dprintk("<-- %s return %d\n", __func__, status); |
| 5780 | |
| 5781 | return status; |
| 5782 | } |
| 5783 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5784 | /* |
| 5785 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5786 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5787 | * use them. |
| 5788 | * |
| 5789 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5790 | * always set csa_cachethis to FALSE because the current implementation |
| 5791 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5792 | */ |
| 5793 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5794 | { |
| 5795 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5796 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5797 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5798 | |
| 5799 | if (mxrqst_sz == 0) |
| 5800 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5801 | if (mxresp_sz == 0) |
| 5802 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5803 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5804 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5805 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5806 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5807 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5808 | |
| 5809 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5810 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5811 | __func__, |
| 5812 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5813 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5814 | |
| 5815 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5816 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5817 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5818 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5819 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5820 | args->bc_attrs.max_reqs = 1; |
| 5821 | |
| 5822 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5823 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5824 | __func__, |
| 5825 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5826 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5827 | args->bc_attrs.max_reqs); |
| 5828 | } |
| 5829 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5830 | 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] | 5831 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5832 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5833 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5834 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5835 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5836 | return -EINVAL; |
| 5837 | /* |
| 5838 | * Our requested max_ops is the minimum we need; we're not |
| 5839 | * prepared to break up compounds into smaller pieces than that. |
| 5840 | * So, no point even trying to continue if the server won't |
| 5841 | * cooperate: |
| 5842 | */ |
| 5843 | if (rcvd->max_ops < sent->max_ops) |
| 5844 | return -EINVAL; |
| 5845 | if (rcvd->max_reqs == 0) |
| 5846 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5847 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5848 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5849 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5850 | } |
| 5851 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5852 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5853 | { |
| 5854 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5855 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5856 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5857 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5858 | return -EINVAL; |
| 5859 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5860 | return -EINVAL; |
| 5861 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5862 | return -EINVAL; |
| 5863 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5864 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5865 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5866 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5867 | return -EINVAL; |
| 5868 | return 0; |
| 5869 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5870 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5871 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5872 | struct nfs4_session *session) |
| 5873 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5874 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5875 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5876 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5877 | if (ret) |
| 5878 | return ret; |
| 5879 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5880 | } |
| 5881 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5882 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5883 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5884 | { |
| 5885 | struct nfs4_session *session = clp->cl_session; |
| 5886 | struct nfs41_create_session_args args = { |
| 5887 | .client = clp, |
| 5888 | .cb_program = NFS4_CALLBACK, |
| 5889 | }; |
| 5890 | struct nfs41_create_session_res res = { |
| 5891 | .client = clp, |
| 5892 | }; |
| 5893 | struct rpc_message msg = { |
| 5894 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5895 | .rpc_argp = &args, |
| 5896 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5897 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5898 | }; |
| 5899 | int status; |
| 5900 | |
| 5901 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5902 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5903 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5904 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5905 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5906 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5907 | /* Verify the session's negotiated channel_attrs values */ |
| 5908 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5909 | /* Increment the clientid slot sequence id */ |
| 5910 | clp->cl_seqid++; |
| 5911 | } |
| 5912 | |
| 5913 | return status; |
| 5914 | } |
| 5915 | |
| 5916 | /* |
| 5917 | * Issues a CREATE_SESSION operation to the server. |
| 5918 | * It is the responsibility of the caller to verify the session is |
| 5919 | * expired before calling this routine. |
| 5920 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5921 | 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] | 5922 | { |
| 5923 | int status; |
| 5924 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5925 | struct nfs4_session *session = clp->cl_session; |
| 5926 | |
| 5927 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5928 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5929 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5930 | if (status) |
| 5931 | goto out; |
| 5932 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5933 | /* Init or reset the session slot tables */ |
| 5934 | status = nfs4_setup_session_slot_tables(session); |
| 5935 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5936 | if (status) |
| 5937 | goto out; |
| 5938 | |
| 5939 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5940 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5941 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5942 | out: |
| 5943 | dprintk("<-- %s\n", __func__); |
| 5944 | return status; |
| 5945 | } |
| 5946 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5947 | /* |
| 5948 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5949 | * The caller must serialize access to this routine. |
| 5950 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5951 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5952 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5953 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5954 | struct rpc_message msg = { |
| 5955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5956 | .rpc_argp = session, |
| 5957 | .rpc_cred = cred, |
| 5958 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5959 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5960 | |
| 5961 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5962 | |
| 5963 | /* session is still being setup */ |
| 5964 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5965 | return status; |
| 5966 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5967 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5968 | |
| 5969 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5970 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5971 | "Session has been destroyed regardless...\n", status); |
| 5972 | |
| 5973 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5974 | return status; |
| 5975 | } |
| 5976 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5977 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5978 | * Renew the cl_session lease. |
| 5979 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5980 | struct nfs4_sequence_data { |
| 5981 | struct nfs_client *clp; |
| 5982 | struct nfs4_sequence_args args; |
| 5983 | struct nfs4_sequence_res res; |
| 5984 | }; |
| 5985 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5986 | static void nfs41_sequence_release(void *data) |
| 5987 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5988 | struct nfs4_sequence_data *calldata = data; |
| 5989 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5990 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5991 | if (atomic_read(&clp->cl_count) > 1) |
| 5992 | nfs4_schedule_state_renewal(clp); |
| 5993 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5994 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5995 | } |
| 5996 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5997 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5998 | { |
| 5999 | switch(task->tk_status) { |
| 6000 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6001 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6002 | return -EAGAIN; |
| 6003 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6004 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6005 | } |
| 6006 | return 0; |
| 6007 | } |
| 6008 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6009 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6010 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6011 | struct nfs4_sequence_data *calldata = data; |
| 6012 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6013 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6014 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6015 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6016 | |
| 6017 | if (task->tk_status < 0) { |
| 6018 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6019 | if (atomic_read(&clp->cl_count) == 1) |
| 6020 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6021 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6022 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6023 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6024 | return; |
| 6025 | } |
| 6026 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6027 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6028 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6029 | dprintk("<-- %s\n", __func__); |
| 6030 | } |
| 6031 | |
| 6032 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6033 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6034 | struct nfs4_sequence_data *calldata = data; |
| 6035 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6036 | struct nfs4_sequence_args *args; |
| 6037 | struct nfs4_sequence_res *res; |
| 6038 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6039 | args = task->tk_msg.rpc_argp; |
| 6040 | res = task->tk_msg.rpc_resp; |
| 6041 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6042 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6046 | .rpc_call_done = nfs41_sequence_call_done, |
| 6047 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6048 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6049 | }; |
| 6050 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6051 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 6052 | struct rpc_cred *cred, |
| 6053 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6054 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6055 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6056 | struct rpc_message msg = { |
| 6057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6058 | .rpc_cred = cred, |
| 6059 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6060 | struct rpc_task_setup task_setup_data = { |
| 6061 | .rpc_client = clp->cl_rpcclient, |
| 6062 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6063 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 6064 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6065 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6066 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6067 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6068 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6069 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6070 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6071 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6072 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6073 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6074 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6075 | if (is_privileged) |
| 6076 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6077 | msg.rpc_argp = &calldata->args; |
| 6078 | msg.rpc_resp = &calldata->res; |
| 6079 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6080 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6081 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6082 | return rpc_run_task(&task_setup_data); |
| 6083 | } |
| 6084 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6085 | 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] | 6086 | { |
| 6087 | struct rpc_task *task; |
| 6088 | int ret = 0; |
| 6089 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6090 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6091 | return 0; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6092 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6093 | if (IS_ERR(task)) |
| 6094 | ret = PTR_ERR(task); |
| 6095 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6096 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6097 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6098 | return ret; |
| 6099 | } |
| 6100 | |
| 6101 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6102 | { |
| 6103 | struct rpc_task *task; |
| 6104 | int ret; |
| 6105 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6106 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6107 | if (IS_ERR(task)) { |
| 6108 | ret = PTR_ERR(task); |
| 6109 | goto out; |
| 6110 | } |
| 6111 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6112 | if (!ret) { |
| 6113 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6114 | |
| 6115 | if (task->tk_status == 0) |
| 6116 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6117 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6118 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6119 | rpc_put_task(task); |
| 6120 | out: |
| 6121 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6122 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6123 | } |
| 6124 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6125 | struct nfs4_reclaim_complete_data { |
| 6126 | struct nfs_client *clp; |
| 6127 | struct nfs41_reclaim_complete_args arg; |
| 6128 | struct nfs41_reclaim_complete_res res; |
| 6129 | }; |
| 6130 | |
| 6131 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6132 | { |
| 6133 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6134 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6135 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 6136 | &calldata->arg.seq_args, |
| 6137 | &calldata->res.seq_res, |
| 6138 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6139 | } |
| 6140 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6141 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6142 | { |
| 6143 | switch(task->tk_status) { |
| 6144 | case 0: |
| 6145 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6146 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6147 | break; |
| 6148 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6149 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6150 | /* fall through */ |
| 6151 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6152 | return -EAGAIN; |
| 6153 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6154 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6155 | } |
| 6156 | return 0; |
| 6157 | } |
| 6158 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6159 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6160 | { |
| 6161 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6162 | struct nfs_client *clp = calldata->clp; |
| 6163 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6164 | |
| 6165 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6166 | if (!nfs41_sequence_done(task, res)) |
| 6167 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6168 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6169 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6170 | rpc_restart_call_prepare(task); |
| 6171 | return; |
| 6172 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6173 | dprintk("<-- %s\n", __func__); |
| 6174 | } |
| 6175 | |
| 6176 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6177 | { |
| 6178 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6179 | |
| 6180 | kfree(calldata); |
| 6181 | } |
| 6182 | |
| 6183 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6184 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6185 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6186 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6187 | }; |
| 6188 | |
| 6189 | /* |
| 6190 | * Issue a global reclaim complete. |
| 6191 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6192 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 6193 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6194 | { |
| 6195 | struct nfs4_reclaim_complete_data *calldata; |
| 6196 | struct rpc_task *task; |
| 6197 | struct rpc_message msg = { |
| 6198 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 6199 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6200 | }; |
| 6201 | struct rpc_task_setup task_setup_data = { |
| 6202 | .rpc_client = clp->cl_rpcclient, |
| 6203 | .rpc_message = &msg, |
| 6204 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6205 | .flags = RPC_TASK_ASYNC, |
| 6206 | }; |
| 6207 | int status = -ENOMEM; |
| 6208 | |
| 6209 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6210 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6211 | if (calldata == NULL) |
| 6212 | goto out; |
| 6213 | calldata->clp = clp; |
| 6214 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6215 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6216 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6217 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6218 | msg.rpc_argp = &calldata->arg; |
| 6219 | msg.rpc_resp = &calldata->res; |
| 6220 | task_setup_data.callback_data = calldata; |
| 6221 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6222 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6223 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6224 | goto out; |
| 6225 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6226 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6227 | if (status == 0) |
| 6228 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6229 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6230 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6231 | out: |
| 6232 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6233 | return status; |
| 6234 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6235 | |
| 6236 | static void |
| 6237 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6238 | { |
| 6239 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6240 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6241 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6242 | |
| 6243 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6244 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6245 | * right now covering the LAYOUTGET we are about to send. |
| 6246 | * However, that is not so catastrophic, and there seems |
| 6247 | * to be no way to prevent it completely. |
| 6248 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6249 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6250 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6251 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6252 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6253 | NFS_I(lgp->args.inode)->layout, |
| 6254 | lgp->args.ctx->state)) { |
| 6255 | rpc_exit(task, NFS4_OK); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6256 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6260 | { |
| 6261 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6262 | struct inode *inode = lgp->args.inode; |
| 6263 | struct nfs_server *server = NFS_SERVER(inode); |
| 6264 | struct pnfs_layout_hdr *lo; |
| 6265 | struct nfs4_state *state = NULL; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6266 | unsigned long timeo, giveup; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6267 | |
| 6268 | dprintk("--> %s\n", __func__); |
| 6269 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6270 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6271 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6272 | |
| 6273 | switch (task->tk_status) { |
| 6274 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6275 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6276 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6277 | case -NFS4ERR_RECALLCONFLICT: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6278 | timeo = rpc_get_timeout(task->tk_client); |
| 6279 | giveup = lgp->args.timestamp + timeo; |
| 6280 | if (time_after(giveup, jiffies)) |
| 6281 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6282 | break; |
| 6283 | case -NFS4ERR_EXPIRED: |
| 6284 | case -NFS4ERR_BAD_STATEID: |
| 6285 | spin_lock(&inode->i_lock); |
| 6286 | lo = NFS_I(inode)->layout; |
| 6287 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6288 | spin_unlock(&inode->i_lock); |
| 6289 | /* If the open stateid was bad, then recover it. */ |
| 6290 | state = lgp->args.ctx->state; |
| 6291 | } else { |
| 6292 | LIST_HEAD(head); |
| 6293 | |
| 6294 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6295 | spin_unlock(&inode->i_lock); |
| 6296 | /* Mark the bad layout state as invalid, then |
| 6297 | * retry using the open stateid. */ |
| 6298 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6299 | } |
| 6300 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6301 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6302 | rpc_restart_call_prepare(task); |
| 6303 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6304 | dprintk("<-- %s\n", __func__); |
| 6305 | } |
| 6306 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6307 | static size_t max_response_pages(struct nfs_server *server) |
| 6308 | { |
| 6309 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6310 | return nfs_page_array_len(0, max_resp_sz); |
| 6311 | } |
| 6312 | |
| 6313 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6314 | { |
| 6315 | int i; |
| 6316 | |
| 6317 | if (!pages) |
| 6318 | return; |
| 6319 | |
| 6320 | for (i = 0; i < size; i++) { |
| 6321 | if (!pages[i]) |
| 6322 | break; |
| 6323 | __free_page(pages[i]); |
| 6324 | } |
| 6325 | kfree(pages); |
| 6326 | } |
| 6327 | |
| 6328 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6329 | { |
| 6330 | struct page **pages; |
| 6331 | int i; |
| 6332 | |
| 6333 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6334 | if (!pages) { |
| 6335 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6336 | return NULL; |
| 6337 | } |
| 6338 | |
| 6339 | for (i = 0; i < size; i++) { |
| 6340 | pages[i] = alloc_page(gfp_flags); |
| 6341 | if (!pages[i]) { |
| 6342 | dprintk("%s: failed to allocate page\n", __func__); |
| 6343 | nfs4_free_pages(pages, size); |
| 6344 | return NULL; |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | return pages; |
| 6349 | } |
| 6350 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6351 | static void nfs4_layoutget_release(void *calldata) |
| 6352 | { |
| 6353 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6354 | struct inode *inode = lgp->args.inode; |
| 6355 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6356 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6357 | |
| 6358 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6359 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6360 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6361 | put_nfs_open_context(lgp->args.ctx); |
| 6362 | kfree(calldata); |
| 6363 | dprintk("<-- %s\n", __func__); |
| 6364 | } |
| 6365 | |
| 6366 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6367 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6368 | .rpc_call_done = nfs4_layoutget_done, |
| 6369 | .rpc_release = nfs4_layoutget_release, |
| 6370 | }; |
| 6371 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6372 | struct pnfs_layout_segment * |
| 6373 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6374 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6375 | struct inode *inode = lgp->args.inode; |
| 6376 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6377 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6378 | struct rpc_task *task; |
| 6379 | struct rpc_message msg = { |
| 6380 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6381 | .rpc_argp = &lgp->args, |
| 6382 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 6383 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6384 | }; |
| 6385 | struct rpc_task_setup task_setup_data = { |
| 6386 | .rpc_client = server->client, |
| 6387 | .rpc_message = &msg, |
| 6388 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6389 | .callback_data = lgp, |
| 6390 | .flags = RPC_TASK_ASYNC, |
| 6391 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6392 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6393 | int status = 0; |
| 6394 | |
| 6395 | dprintk("--> %s\n", __func__); |
| 6396 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6397 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6398 | if (!lgp->args.layout.pages) { |
| 6399 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6400 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6401 | } |
| 6402 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 6403 | lgp->args.timestamp = jiffies; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6404 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6405 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6406 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6407 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 6408 | |
| 6409 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 6410 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 6411 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6412 | task = rpc_run_task(&task_setup_data); |
| 6413 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6414 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6415 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6416 | if (status == 0) |
| 6417 | status = task->tk_status; |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 6418 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 6419 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6420 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6421 | rpc_put_task(task); |
| 6422 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6423 | if (status) |
| 6424 | return ERR_PTR(status); |
| 6425 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6426 | } |
| 6427 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6428 | static void |
| 6429 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6430 | { |
| 6431 | struct nfs4_layoutreturn *lrp = calldata; |
| 6432 | |
| 6433 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6434 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 6435 | &lrp->args.seq_args, |
| 6436 | &lrp->res.seq_res, |
| 6437 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6441 | { |
| 6442 | struct nfs4_layoutreturn *lrp = calldata; |
| 6443 | struct nfs_server *server; |
| 6444 | |
| 6445 | dprintk("--> %s\n", __func__); |
| 6446 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6447 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6448 | return; |
| 6449 | |
| 6450 | server = NFS_SERVER(lrp->args.inode); |
| 6451 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6452 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6453 | return; |
| 6454 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6455 | dprintk("<-- %s\n", __func__); |
| 6456 | } |
| 6457 | |
| 6458 | static void nfs4_layoutreturn_release(void *calldata) |
| 6459 | { |
| 6460 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6461 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6462 | |
| 6463 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6464 | spin_lock(&lo->plh_inode->i_lock); |
| 6465 | if (lrp->res.lrs_present) |
| 6466 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6467 | lo->plh_block_lgets--; |
| 6468 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6469 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6470 | kfree(calldata); |
| 6471 | dprintk("<-- %s\n", __func__); |
| 6472 | } |
| 6473 | |
| 6474 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6475 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6476 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6477 | .rpc_release = nfs4_layoutreturn_release, |
| 6478 | }; |
| 6479 | |
| 6480 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6481 | { |
| 6482 | struct rpc_task *task; |
| 6483 | struct rpc_message msg = { |
| 6484 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6485 | .rpc_argp = &lrp->args, |
| 6486 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 6487 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6488 | }; |
| 6489 | struct rpc_task_setup task_setup_data = { |
| 6490 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6491 | .rpc_message = &msg, |
| 6492 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6493 | .callback_data = lrp, |
| 6494 | }; |
| 6495 | int status; |
| 6496 | |
| 6497 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6498 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6499 | task = rpc_run_task(&task_setup_data); |
| 6500 | if (IS_ERR(task)) |
| 6501 | return PTR_ERR(task); |
| 6502 | status = task->tk_status; |
| 6503 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6504 | rpc_put_task(task); |
| 6505 | return status; |
| 6506 | } |
| 6507 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6508 | /* |
| 6509 | * Retrieve the list of Data Server devices from the MDS. |
| 6510 | */ |
| 6511 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6512 | const struct nfs_fh *fh, |
| 6513 | struct pnfs_devicelist *devlist) |
| 6514 | { |
| 6515 | struct nfs4_getdevicelist_args args = { |
| 6516 | .fh = fh, |
| 6517 | .layoutclass = server->pnfs_curr_ld->id, |
| 6518 | }; |
| 6519 | struct nfs4_getdevicelist_res res = { |
| 6520 | .devlist = devlist, |
| 6521 | }; |
| 6522 | struct rpc_message msg = { |
| 6523 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6524 | .rpc_argp = &args, |
| 6525 | .rpc_resp = &res, |
| 6526 | }; |
| 6527 | int status; |
| 6528 | |
| 6529 | dprintk("--> %s\n", __func__); |
| 6530 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6531 | &res.seq_res, 0); |
| 6532 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6533 | return status; |
| 6534 | } |
| 6535 | |
| 6536 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6537 | const struct nfs_fh *fh, |
| 6538 | struct pnfs_devicelist *devlist) |
| 6539 | { |
| 6540 | struct nfs4_exception exception = { }; |
| 6541 | int err; |
| 6542 | |
| 6543 | do { |
| 6544 | err = nfs4_handle_exception(server, |
| 6545 | _nfs4_getdevicelist(server, fh, devlist), |
| 6546 | &exception); |
| 6547 | } while (exception.retry); |
| 6548 | |
| 6549 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6550 | err, devlist->num_devs); |
| 6551 | |
| 6552 | return err; |
| 6553 | } |
| 6554 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6555 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6556 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6557 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6558 | struct pnfs_device *pdev, |
| 6559 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6560 | { |
| 6561 | struct nfs4_getdeviceinfo_args args = { |
| 6562 | .pdev = pdev, |
| 6563 | }; |
| 6564 | struct nfs4_getdeviceinfo_res res = { |
| 6565 | .pdev = pdev, |
| 6566 | }; |
| 6567 | struct rpc_message msg = { |
| 6568 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6569 | .rpc_argp = &args, |
| 6570 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6571 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6572 | }; |
| 6573 | int status; |
| 6574 | |
| 6575 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6576 | 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] | 6577 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6578 | |
| 6579 | return status; |
| 6580 | } |
| 6581 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6582 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 6583 | struct pnfs_device *pdev, |
| 6584 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6585 | { |
| 6586 | struct nfs4_exception exception = { }; |
| 6587 | int err; |
| 6588 | |
| 6589 | do { |
| 6590 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 6591 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6592 | &exception); |
| 6593 | } while (exception.retry); |
| 6594 | return err; |
| 6595 | } |
| 6596 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6597 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6598 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6599 | { |
| 6600 | struct nfs4_layoutcommit_data *data = calldata; |
| 6601 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6602 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6603 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6604 | nfs41_setup_sequence(session, |
| 6605 | &data->args.seq_args, |
| 6606 | &data->res.seq_res, |
| 6607 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6608 | } |
| 6609 | |
| 6610 | static void |
| 6611 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6612 | { |
| 6613 | struct nfs4_layoutcommit_data *data = calldata; |
| 6614 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6615 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 6616 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6617 | return; |
| 6618 | |
| 6619 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6620 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6621 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6622 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6623 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6624 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6625 | break; |
| 6626 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6627 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6628 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6629 | break; |
| 6630 | default: |
| 6631 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6632 | rpc_restart_call_prepare(task); |
| 6633 | return; |
| 6634 | } |
| 6635 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6636 | } |
| 6637 | |
| 6638 | static void nfs4_layoutcommit_release(void *calldata) |
| 6639 | { |
| 6640 | struct nfs4_layoutcommit_data *data = calldata; |
| 6641 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6642 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6643 | put_rpccred(data->cred); |
| 6644 | kfree(data); |
| 6645 | } |
| 6646 | |
| 6647 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6648 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6649 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6650 | .rpc_release = nfs4_layoutcommit_release, |
| 6651 | }; |
| 6652 | |
| 6653 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6654 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6655 | { |
| 6656 | struct rpc_message msg = { |
| 6657 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6658 | .rpc_argp = &data->args, |
| 6659 | .rpc_resp = &data->res, |
| 6660 | .rpc_cred = data->cred, |
| 6661 | }; |
| 6662 | struct rpc_task_setup task_setup_data = { |
| 6663 | .task = &data->task, |
| 6664 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6665 | .rpc_message = &msg, |
| 6666 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6667 | .callback_data = data, |
| 6668 | .flags = RPC_TASK_ASYNC, |
| 6669 | }; |
| 6670 | struct rpc_task *task; |
| 6671 | int status = 0; |
| 6672 | |
| 6673 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6674 | "lbw: %llu inode %lu\n", |
| 6675 | data->task.tk_pid, sync, |
| 6676 | data->args.lastbytewritten, |
| 6677 | data->args.inode->i_ino); |
| 6678 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6679 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6680 | task = rpc_run_task(&task_setup_data); |
| 6681 | if (IS_ERR(task)) |
| 6682 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6683 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6684 | goto out; |
| 6685 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6686 | if (status != 0) |
| 6687 | goto out; |
| 6688 | status = task->tk_status; |
| 6689 | out: |
| 6690 | dprintk("%s: status %d\n", __func__, status); |
| 6691 | rpc_put_task(task); |
| 6692 | return status; |
| 6693 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6694 | |
| 6695 | static int |
| 6696 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6697 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6698 | { |
| 6699 | struct nfs41_secinfo_no_name_args args = { |
| 6700 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6701 | }; |
| 6702 | struct nfs4_secinfo_res res = { |
| 6703 | .flavors = flavors, |
| 6704 | }; |
| 6705 | struct rpc_message msg = { |
| 6706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6707 | .rpc_argp = &args, |
| 6708 | .rpc_resp = &res, |
| 6709 | }; |
| 6710 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6711 | } |
| 6712 | |
| 6713 | static int |
| 6714 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6715 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6716 | { |
| 6717 | struct nfs4_exception exception = { }; |
| 6718 | int err; |
| 6719 | do { |
| 6720 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6721 | switch (err) { |
| 6722 | case 0: |
| 6723 | case -NFS4ERR_WRONGSEC: |
| 6724 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6725 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6726 | default: |
| 6727 | err = nfs4_handle_exception(server, err, &exception); |
| 6728 | } |
| 6729 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6730 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6731 | return err; |
| 6732 | } |
| 6733 | |
| 6734 | static int |
| 6735 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6736 | struct nfs_fsinfo *info) |
| 6737 | { |
| 6738 | int err; |
| 6739 | struct page *page; |
| 6740 | rpc_authflavor_t flavor; |
| 6741 | struct nfs4_secinfo_flavors *flavors; |
| 6742 | |
| 6743 | page = alloc_page(GFP_KERNEL); |
| 6744 | if (!page) { |
| 6745 | err = -ENOMEM; |
| 6746 | goto out; |
| 6747 | } |
| 6748 | |
| 6749 | flavors = page_address(page); |
| 6750 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6751 | |
| 6752 | /* |
| 6753 | * Fall back on "guess and check" method if |
| 6754 | * the server doesn't support SECINFO_NO_NAME |
| 6755 | */ |
| 6756 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6757 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6758 | goto out_freepage; |
| 6759 | } |
| 6760 | if (err) |
| 6761 | goto out_freepage; |
| 6762 | |
| 6763 | flavor = nfs_find_best_sec(flavors); |
| 6764 | if (err == 0) |
| 6765 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6766 | |
| 6767 | out_freepage: |
| 6768 | put_page(page); |
| 6769 | if (err == -EACCES) |
| 6770 | return -EPERM; |
| 6771 | out: |
| 6772 | return err; |
| 6773 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6774 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6775 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 6776 | nfs4_stateid *stateid, |
| 6777 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6778 | { |
| 6779 | int status; |
| 6780 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6781 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6782 | }; |
| 6783 | struct nfs41_test_stateid_res res; |
| 6784 | struct rpc_message msg = { |
| 6785 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6786 | .rpc_argp = &args, |
| 6787 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6788 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6789 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6790 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6791 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6792 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6793 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6794 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
| 6795 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6796 | if (status != NFS_OK) { |
| 6797 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6798 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6799 | } |
| 6800 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6801 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6802 | } |
| 6803 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6804 | /** |
| 6805 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6806 | * |
| 6807 | * @server: server / transport on which to perform the operation |
| 6808 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6809 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6810 | * |
| 6811 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6812 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6813 | * failed or the state ID is not currently valid. |
| 6814 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6815 | static int nfs41_test_stateid(struct nfs_server *server, |
| 6816 | nfs4_stateid *stateid, |
| 6817 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6818 | { |
| 6819 | struct nfs4_exception exception = { }; |
| 6820 | int err; |
| 6821 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6822 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6823 | if (err != -NFS4ERR_DELAY) |
| 6824 | break; |
| 6825 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6826 | } while (exception.retry); |
| 6827 | return err; |
| 6828 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6829 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6830 | struct nfs_free_stateid_data { |
| 6831 | struct nfs_server *server; |
| 6832 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6833 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6834 | }; |
| 6835 | |
| 6836 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 6837 | { |
| 6838 | struct nfs_free_stateid_data *data = calldata; |
| 6839 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 6840 | &data->args.seq_args, |
| 6841 | &data->res.seq_res, |
| 6842 | task); |
| 6843 | } |
| 6844 | |
| 6845 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 6846 | { |
| 6847 | struct nfs_free_stateid_data *data = calldata; |
| 6848 | |
| 6849 | nfs41_sequence_done(task, &data->res.seq_res); |
| 6850 | |
| 6851 | switch (task->tk_status) { |
| 6852 | case -NFS4ERR_DELAY: |
| 6853 | if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN) |
| 6854 | rpc_restart_call_prepare(task); |
| 6855 | } |
| 6856 | } |
| 6857 | |
| 6858 | static void nfs41_free_stateid_release(void *calldata) |
| 6859 | { |
| 6860 | kfree(calldata); |
| 6861 | } |
| 6862 | |
| 6863 | const struct rpc_call_ops nfs41_free_stateid_ops = { |
| 6864 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 6865 | .rpc_call_done = nfs41_free_stateid_done, |
| 6866 | .rpc_release = nfs41_free_stateid_release, |
| 6867 | }; |
| 6868 | |
| 6869 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 6870 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6871 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6872 | bool privileged) |
| 6873 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6874 | struct rpc_message msg = { |
| 6875 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6876 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6877 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6878 | struct rpc_task_setup task_setup = { |
| 6879 | .rpc_client = server->client, |
| 6880 | .rpc_message = &msg, |
| 6881 | .callback_ops = &nfs41_free_stateid_ops, |
| 6882 | .flags = RPC_TASK_ASYNC, |
| 6883 | }; |
| 6884 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6885 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6886 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6887 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6888 | if (!data) |
| 6889 | return ERR_PTR(-ENOMEM); |
| 6890 | data->server = server; |
| 6891 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 6892 | |
| 6893 | task_setup.callback_data = data; |
| 6894 | |
| 6895 | msg.rpc_argp = &data->args; |
| 6896 | msg.rpc_resp = &data->res; |
| 6897 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
| 6898 | if (privileged) |
| 6899 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 6900 | |
| 6901 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6902 | } |
| 6903 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6904 | /** |
| 6905 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6906 | * |
| 6907 | * @server: server / transport on which to perform the operation |
| 6908 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6909 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6910 | * |
| 6911 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6912 | * negative NFS4ERR value is returned. |
| 6913 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6914 | static int nfs41_free_stateid(struct nfs_server *server, |
| 6915 | nfs4_stateid *stateid, |
| 6916 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6917 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6918 | struct rpc_task *task; |
| 6919 | int ret; |
| 6920 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6921 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 6922 | if (IS_ERR(task)) |
| 6923 | return PTR_ERR(task); |
| 6924 | ret = rpc_wait_for_completion_task(task); |
| 6925 | if (!ret) |
| 6926 | ret = task->tk_status; |
| 6927 | rpc_put_task(task); |
| 6928 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6929 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6930 | |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 6931 | static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
| 6932 | { |
| 6933 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6934 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 6935 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6936 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 6937 | nfs4_free_lock_state(server, lsp); |
| 6938 | if (IS_ERR(task)) |
| 6939 | return PTR_ERR(task); |
| 6940 | rpc_put_task(task); |
| 6941 | return 0; |
| 6942 | } |
| 6943 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6944 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6945 | const nfs4_stateid *s2) |
| 6946 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6947 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6948 | return false; |
| 6949 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6950 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6951 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6952 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6953 | return true; |
| 6954 | |
| 6955 | return false; |
| 6956 | } |
| 6957 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6958 | #endif /* CONFIG_NFS_V4_1 */ |
| 6959 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6960 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6961 | const nfs4_stateid *s2) |
| 6962 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6963 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6967 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6968 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6969 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6970 | .recover_open = nfs4_open_reclaim, |
| 6971 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6972 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6973 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6974 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6975 | }; |
| 6976 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6977 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6978 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6979 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6980 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6981 | .recover_open = nfs4_open_reclaim, |
| 6982 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6983 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6984 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6985 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6986 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6987 | }; |
| 6988 | #endif /* CONFIG_NFS_V4_1 */ |
| 6989 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6990 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6991 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6992 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6993 | .recover_open = nfs4_open_expired, |
| 6994 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6995 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6996 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6997 | }; |
| 6998 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6999 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7000 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7001 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 7002 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7003 | .recover_open = nfs41_open_expired, |
| 7004 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7005 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7006 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7007 | }; |
| 7008 | #endif /* CONFIG_NFS_V4_1 */ |
| 7009 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7010 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7011 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7012 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7013 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7014 | }; |
| 7015 | |
| 7016 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7017 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7018 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7019 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7020 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7021 | }; |
| 7022 | #endif |
| 7023 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7024 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7025 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7026 | .init_caps = NFS_CAP_READDIRPLUS |
| 7027 | | NFS_CAP_ATOMIC_OPEN |
| 7028 | | NFS_CAP_CHANGE_ATTR |
| 7029 | | NFS_CAP_POSIX_LOCK, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7030 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7031 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7032 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7033 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7034 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7035 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7036 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7037 | }; |
| 7038 | |
| 7039 | #if defined(CONFIG_NFS_V4_1) |
| 7040 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7041 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 7042 | .init_caps = NFS_CAP_READDIRPLUS |
| 7043 | | NFS_CAP_ATOMIC_OPEN |
| 7044 | | NFS_CAP_CHANGE_ATTR |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 7045 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 7046 | | NFS_CAP_STATEID_NFSV41 |
| 7047 | | NFS_CAP_ATOMIC_OPEN_V1, |
Bryan Schumaker | 104287c | 2012-11-12 14:13:13 -0500 | [diff] [blame] | 7048 | .call_sync = nfs4_call_sync_sequence, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7049 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7050 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 7051 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7052 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7053 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7054 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7055 | }; |
| 7056 | #endif |
| 7057 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7058 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7059 | [0] = &nfs_v4_0_minor_ops, |
| 7060 | #if defined(CONFIG_NFS_V4_1) |
| 7061 | [1] = &nfs_v4_1_minor_ops, |
| 7062 | #endif |
| 7063 | }; |
| 7064 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7065 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7066 | .create = nfs_create, |
| 7067 | .lookup = nfs_lookup, |
| 7068 | .atomic_open = nfs_atomic_open, |
| 7069 | .link = nfs_link, |
| 7070 | .unlink = nfs_unlink, |
| 7071 | .symlink = nfs_symlink, |
| 7072 | .mkdir = nfs_mkdir, |
| 7073 | .rmdir = nfs_rmdir, |
| 7074 | .mknod = nfs_mknod, |
| 7075 | .rename = nfs_rename, |
| 7076 | .permission = nfs_permission, |
| 7077 | .getattr = nfs_getattr, |
| 7078 | .setattr = nfs_setattr, |
| 7079 | .getxattr = generic_getxattr, |
| 7080 | .setxattr = generic_setxattr, |
| 7081 | .listxattr = generic_listxattr, |
| 7082 | .removexattr = generic_removexattr, |
| 7083 | }; |
| 7084 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7085 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7086 | .permission = nfs_permission, |
| 7087 | .getattr = nfs_getattr, |
| 7088 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7089 | .getxattr = generic_getxattr, |
| 7090 | .setxattr = generic_setxattr, |
| 7091 | .listxattr = generic_listxattr, |
| 7092 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7093 | }; |
| 7094 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7095 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7096 | .version = 4, /* protocol version */ |
| 7097 | .dentry_ops = &nfs4_dentry_operations, |
| 7098 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7099 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7100 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7101 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7102 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7103 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7104 | .getattr = nfs4_proc_getattr, |
| 7105 | .setattr = nfs4_proc_setattr, |
| 7106 | .lookup = nfs4_proc_lookup, |
| 7107 | .access = nfs4_proc_access, |
| 7108 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7109 | .create = nfs4_proc_create, |
| 7110 | .remove = nfs4_proc_remove, |
| 7111 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7112 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7113 | .unlink_done = nfs4_proc_unlink_done, |
| 7114 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7115 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7116 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7117 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7118 | .link = nfs4_proc_link, |
| 7119 | .symlink = nfs4_proc_symlink, |
| 7120 | .mkdir = nfs4_proc_mkdir, |
| 7121 | .rmdir = nfs4_proc_remove, |
| 7122 | .readdir = nfs4_proc_readdir, |
| 7123 | .mknod = nfs4_proc_mknod, |
| 7124 | .statfs = nfs4_proc_statfs, |
| 7125 | .fsinfo = nfs4_proc_fsinfo, |
| 7126 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7127 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7128 | .decode_dirent = nfs4_decode_dirent, |
| 7129 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7130 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7131 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7132 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7133 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7134 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7135 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7136 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7137 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7138 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7139 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7140 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7141 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7142 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7143 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7144 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7145 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7146 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7147 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7148 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7149 | .create_server = nfs4_create_server, |
| 7150 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7151 | }; |
| 7152 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7153 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7154 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7155 | .list = nfs4_xattr_list_nfs4_acl, |
| 7156 | .get = nfs4_xattr_get_nfs4_acl, |
| 7157 | .set = nfs4_xattr_set_nfs4_acl, |
| 7158 | }; |
| 7159 | |
| 7160 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7161 | &nfs4_xattr_nfs4_acl_handler, |
| 7162 | NULL |
| 7163 | }; |
| 7164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7165 | /* |
| 7166 | * Local variables: |
| 7167 | * c-basic-offset: 8 |
| 7168 | * End: |
| 7169 | */ |