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 | 6926afd1 | 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" |
| 67 | |
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 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 86 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 87 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 90 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 92 | if (err >= -1000) |
| 93 | return err; |
| 94 | switch (err) { |
| 95 | case -NFS4ERR_RESOURCE: |
| 96 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 97 | case -NFS4ERR_WRONGSEC: |
| 98 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 99 | case -NFS4ERR_BADOWNER: |
| 100 | case -NFS4ERR_BADNAME: |
| 101 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 102 | case -NFS4ERR_SHARE_DENIED: |
| 103 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 104 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 105 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 106 | case -NFS4ERR_ACCESS: |
| 107 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 108 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 110 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 111 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 113 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * This is our standard bitmap for GETATTR requests. |
| 118 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 119 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | FATTR4_WORD0_TYPE |
| 121 | | FATTR4_WORD0_CHANGE |
| 122 | | FATTR4_WORD0_SIZE |
| 123 | | FATTR4_WORD0_FSID |
| 124 | | FATTR4_WORD0_FILEID, |
| 125 | FATTR4_WORD1_MODE |
| 126 | | FATTR4_WORD1_NUMLINKS |
| 127 | | FATTR4_WORD1_OWNER |
| 128 | | FATTR4_WORD1_OWNER_GROUP |
| 129 | | FATTR4_WORD1_RAWDEV |
| 130 | | FATTR4_WORD1_SPACE_USED |
| 131 | | FATTR4_WORD1_TIME_ACCESS |
| 132 | | FATTR4_WORD1_TIME_METADATA |
| 133 | | FATTR4_WORD1_TIME_MODIFY |
| 134 | }; |
| 135 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 136 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 137 | FATTR4_WORD0_TYPE |
| 138 | | FATTR4_WORD0_CHANGE |
| 139 | | FATTR4_WORD0_SIZE |
| 140 | | FATTR4_WORD0_FSID |
| 141 | | FATTR4_WORD0_FILEID, |
| 142 | FATTR4_WORD1_MODE |
| 143 | | FATTR4_WORD1_NUMLINKS |
| 144 | | FATTR4_WORD1_OWNER |
| 145 | | FATTR4_WORD1_OWNER_GROUP |
| 146 | | FATTR4_WORD1_RAWDEV |
| 147 | | FATTR4_WORD1_SPACE_USED |
| 148 | | FATTR4_WORD1_TIME_ACCESS |
| 149 | | FATTR4_WORD1_TIME_METADATA |
| 150 | | FATTR4_WORD1_TIME_MODIFY, |
| 151 | FATTR4_WORD2_MDSTHRESHOLD |
| 152 | }; |
| 153 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 154 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 155 | FATTR4_WORD0_TYPE |
| 156 | | FATTR4_WORD0_CHANGE |
| 157 | | FATTR4_WORD0_FILEID, |
| 158 | }; |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | const u32 nfs4_statfs_bitmap[2] = { |
| 161 | FATTR4_WORD0_FILES_AVAIL |
| 162 | | FATTR4_WORD0_FILES_FREE |
| 163 | | FATTR4_WORD0_FILES_TOTAL, |
| 164 | FATTR4_WORD1_SPACE_AVAIL |
| 165 | | FATTR4_WORD1_SPACE_FREE |
| 166 | | FATTR4_WORD1_SPACE_TOTAL |
| 167 | }; |
| 168 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 169 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | FATTR4_WORD0_MAXLINK |
| 171 | | FATTR4_WORD0_MAXNAME, |
| 172 | 0 |
| 173 | }; |
| 174 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 175 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | | FATTR4_WORD0_MAXREAD |
| 177 | | FATTR4_WORD0_MAXWRITE |
| 178 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 179 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 180 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 181 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 184 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID |
| 190 | | FATTR4_WORD0_FS_LOCATIONS, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
| 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 201 | }; |
| 202 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 203 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | struct nfs4_readdir_arg *readdir) |
| 205 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 206 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 209 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | readdir->cookie = 0; |
| 215 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 216 | if (cookie == 2) |
| 217 | return; |
| 218 | |
| 219 | /* |
| 220 | * NFSv4 servers do not return entries for '.' and '..' |
| 221 | * Therefore, we fake these entries here. We let '.' |
| 222 | * have cookie 0 and '..' have cookie 1. Note that |
| 223 | * when talking to the server, we always send cookie 0 |
| 224 | * instead of 1 or 2. |
| 225 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 226 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | if (cookie == 0) { |
| 229 | *p++ = xdr_one; /* next */ |
| 230 | *p++ = xdr_zero; /* cookie, first word */ |
| 231 | *p++ = xdr_one; /* cookie, second word */ |
| 232 | *p++ = xdr_one; /* entry len */ |
| 233 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 234 | p++; |
| 235 | *p++ = xdr_one; /* bitmap length */ |
| 236 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 237 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 238 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | *p++ = xdr_one; /* next */ |
| 242 | *p++ = xdr_zero; /* cookie, first word */ |
| 243 | *p++ = xdr_two; /* cookie, second word */ |
| 244 | *p++ = xdr_two; /* entry len */ |
| 245 | memcpy(p, "..\0\0", 4); /* entry */ |
| 246 | p++; |
| 247 | *p++ = xdr_one; /* bitmap length */ |
| 248 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 249 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 250 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | readdir->pgbase = (char *)p - (char *)start; |
| 253 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 254 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 257 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 258 | { |
| 259 | int res = 0; |
| 260 | |
| 261 | might_sleep(); |
| 262 | |
| 263 | if (*timeout <= 0) |
| 264 | *timeout = NFS4_POLL_RETRY_MIN; |
| 265 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 266 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 267 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 268 | if (fatal_signal_pending(current)) |
| 269 | res = -ERESTARTSYS; |
| 270 | *timeout <<= 1; |
| 271 | return res; |
| 272 | } |
| 273 | |
| 274 | /* This is the error handling routine for processes that are allowed |
| 275 | * to sleep. |
| 276 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 277 | 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] | 278 | { |
| 279 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 280 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 281 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 282 | int ret = errorcode; |
| 283 | |
| 284 | exception->retry = 0; |
| 285 | switch(errorcode) { |
| 286 | case 0: |
| 287 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 288 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 289 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 290 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 291 | exception->retry = 1; |
| 292 | return 0; |
| 293 | } |
| 294 | if (state == NULL) |
| 295 | break; |
| 296 | nfs4_schedule_stateid_recovery(server, state); |
| 297 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 298 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 299 | case -NFS4ERR_ADMIN_REVOKED: |
| 300 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 301 | if (state == NULL) |
| 302 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 303 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 304 | nfs4_schedule_stateid_recovery(server, state); |
| 305 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 306 | case -NFS4ERR_EXPIRED: |
| 307 | if (state != NULL) |
| 308 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 309 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 310 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 311 | nfs4_schedule_lease_recovery(clp); |
| 312 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 313 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 314 | case -NFS4ERR_BADSESSION: |
| 315 | case -NFS4ERR_BADSLOT: |
| 316 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 317 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 318 | case -NFS4ERR_DEADSESSION: |
| 319 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 320 | case -NFS4ERR_SEQ_MISORDERED: |
| 321 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 322 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 323 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 324 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 325 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 327 | if (exception->timeout > HZ) { |
| 328 | /* We have retried a decent amount, time to |
| 329 | * fail |
| 330 | */ |
| 331 | ret = -EBUSY; |
| 332 | break; |
| 333 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 334 | case -NFS4ERR_GRACE: |
| 335 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 336 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 337 | ret = nfs4_delay(server->client, &exception->timeout); |
| 338 | if (ret != 0) |
| 339 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 340 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | case -NFS4ERR_OLD_STATEID: |
| 342 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 343 | break; |
| 344 | case -NFS4ERR_BADOWNER: |
| 345 | /* The following works around a Linux server bug! */ |
| 346 | case -NFS4ERR_BADNAME: |
| 347 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 348 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 349 | exception->retry = 1; |
| 350 | printk(KERN_WARNING "NFS: v4 server %s " |
| 351 | "does not accept raw " |
| 352 | "uid/gids. " |
| 353 | "Reenabling the idmapper.\n", |
| 354 | server->nfs_client->cl_hostname); |
| 355 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 356 | } |
| 357 | /* We failed to handle the error */ |
| 358 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 359 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 360 | ret = nfs4_wait_clnt_recover(clp); |
| 361 | if (ret == 0) |
| 362 | exception->retry = 1; |
| 363 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 367 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | spin_lock(&clp->cl_lock); |
| 370 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 371 | clp->cl_last_renewal = timestamp; |
| 372 | spin_unlock(&clp->cl_lock); |
| 373 | } |
| 374 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 375 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 376 | { |
| 377 | do_renew_lease(server->nfs_client, timestamp); |
| 378 | } |
| 379 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 380 | #if defined(CONFIG_NFS_V4_1) |
| 381 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 382 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 383 | { |
| 384 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 385 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 386 | } |
| 387 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 388 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 389 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 390 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 391 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 392 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 393 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 394 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 395 | /* just wake up the next guy waiting since |
| 396 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 397 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 398 | return; |
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 | tbl = res->sr_slot->table; |
| 401 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 402 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 403 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 404 | /* Be nice to the server: try to ensure that the last transmitted |
| 405 | * value for highest_user_slotid <= target_highest_slotid |
| 406 | */ |
| 407 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 408 | send_new_highest_used_slotid = true; |
| 409 | |
Trond Myklebust | f4af6e2a | 2012-11-20 14:17:32 -0500 | [diff] [blame] | 410 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 411 | |
| 412 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 413 | send_new_highest_used_slotid = false; |
| 414 | if (!nfs4_session_draining(session)) { |
| 415 | if (rpc_wake_up_first(&tbl->slot_tbl_waitq, |
| 416 | nfs4_set_task_privileged, NULL) != NULL) |
| 417 | send_new_highest_used_slotid = false; |
| 418 | } |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 419 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 420 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 421 | if (send_new_highest_used_slotid) |
| 422 | nfs41_server_notify_highest_slotid_update(session->clp); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 423 | } |
| 424 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 425 | 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] | 426 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 427 | struct nfs4_session *session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 428 | struct nfs4_slot *slot; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 429 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 430 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * sr_status remains 1 if an RPC level error occurred. The server |
| 434 | * may or may not have processed the sequence operation.. |
| 435 | * Proceed as if the server received and processed the sequence |
| 436 | * operation. |
| 437 | */ |
| 438 | if (res->sr_status == 1) |
| 439 | res->sr_status = NFS_OK; |
| 440 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 441 | /* don't increment the sequence number if the task wasn't sent */ |
| 442 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 443 | goto out; |
| 444 | |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 445 | slot = res->sr_slot; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 446 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 447 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 448 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 449 | switch (res->sr_status) { |
| 450 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 451 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 452 | ++slot->seq_nr; |
| 453 | timestamp = slot->renewal_time; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 454 | clp = session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 455 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 456 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 457 | if (res->sr_status_flags != 0) |
| 458 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 459 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | break; |
| 461 | case -NFS4ERR_DELAY: |
| 462 | /* The server detected a resend of the RPC call and |
| 463 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 464 | * of RFC5661. |
| 465 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 466 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 467 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 468 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 469 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 470 | goto out_retry; |
| 471 | default: |
| 472 | /* Just update the slot sequence no. */ |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 473 | ++slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 474 | } |
| 475 | out: |
| 476 | /* The session may be reset by one of the error handlers. */ |
| 477 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 478 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 479 | return 1; |
| 480 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 481 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | goto out; |
| 483 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 484 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 485 | } |
| 486 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | static int nfs4_sequence_done(struct rpc_task *task, |
| 488 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 489 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 490 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | return 1; |
| 492 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 495 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 496 | struct nfs4_sequence_res *res, int cache_reply) |
| 497 | { |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 498 | args->sa_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 499 | args->sa_cache_this = 0; |
| 500 | if (cache_reply) |
| 501 | args->sa_cache_this = 1; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 502 | res->sr_slot = NULL; |
| 503 | } |
| 504 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 505 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 506 | struct nfs4_sequence_args *args, |
| 507 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 508 | struct rpc_task *task) |
| 509 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 510 | struct nfs4_slot *slot; |
| 511 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 512 | |
| 513 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 514 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 515 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 516 | return 0; |
| 517 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 518 | tbl = &session->fc_slot_table; |
| 519 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 520 | task->tk_timeout = 0; |
| 521 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 522 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 523 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 524 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 525 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 526 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 527 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 528 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 529 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 530 | } |
| 531 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 532 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 533 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 534 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 535 | spin_unlock(&tbl->slot_tbl_lock); |
| 536 | dprintk("%s enforce FIFO order\n", __func__); |
| 537 | return -EAGAIN; |
| 538 | } |
| 539 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 540 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 541 | if (IS_ERR(slot)) { |
| 542 | /* If out of memory, try again in 1/4 second */ |
| 543 | if (slot == ERR_PTR(-ENOMEM)) |
| 544 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 545 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 546 | spin_unlock(&tbl->slot_tbl_lock); |
| 547 | dprintk("<-- %s: no free slots\n", __func__); |
| 548 | return -EAGAIN; |
| 549 | } |
| 550 | spin_unlock(&tbl->slot_tbl_lock); |
| 551 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 552 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 553 | |
| 554 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 555 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 556 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, |
| 557 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 558 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 559 | res->sr_slot = slot; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 560 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 561 | /* |
| 562 | * sr_status is only set in decode_sequence, and so will remain |
| 563 | * set to 1 if an rpc level failure occurs. |
| 564 | */ |
| 565 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 566 | return 0; |
| 567 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 568 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 569 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 570 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 571 | struct nfs4_sequence_args *args, |
| 572 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 573 | struct rpc_task *task) |
| 574 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 575 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 576 | int ret = 0; |
| 577 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 578 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 579 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 580 | |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 581 | dprintk("--> %s clp %p session %p sr_slot %d\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 582 | __func__, session->clp, session, res->sr_slot ? |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 583 | res->sr_slot->slot_nr : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 584 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 585 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 586 | out: |
| 587 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 592 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 593 | struct nfs4_sequence_args *seq_args; |
| 594 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | }; |
| 596 | |
| 597 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 598 | { |
| 599 | struct nfs41_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 600 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 602 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 603 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 604 | if (nfs41_setup_sequence(session, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 605 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | return; |
| 607 | rpc_call_start(task); |
| 608 | } |
| 609 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 610 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 611 | { |
| 612 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 613 | nfs41_call_sync_prepare(task, calldata); |
| 614 | } |
| 615 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 616 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 617 | { |
| 618 | struct nfs41_call_sync_data *data = calldata; |
| 619 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 620 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 621 | } |
| 622 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 623 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 625 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 626 | }; |
| 627 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 628 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 629 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 630 | .rpc_call_done = nfs41_call_sync_done, |
| 631 | }; |
| 632 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 633 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 634 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 635 | struct rpc_message *msg, |
| 636 | struct nfs4_sequence_args *args, |
| 637 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 638 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 639 | { |
| 640 | int ret; |
| 641 | struct rpc_task *task; |
| 642 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 643 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 644 | .seq_args = args, |
| 645 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 646 | }; |
| 647 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 648 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 649 | .rpc_message = msg, |
| 650 | .callback_ops = &nfs41_call_sync_ops, |
| 651 | .callback_data = &data |
| 652 | }; |
| 653 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 654 | if (privileged) |
| 655 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 656 | task = rpc_run_task(&task_setup); |
| 657 | if (IS_ERR(task)) |
| 658 | ret = PTR_ERR(task); |
| 659 | else { |
| 660 | ret = task->tk_status; |
| 661 | rpc_put_task(task); |
| 662 | } |
| 663 | return ret; |
| 664 | } |
| 665 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 666 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 667 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 668 | struct rpc_message *msg, |
| 669 | struct nfs4_sequence_args *args, |
| 670 | struct nfs4_sequence_res *res, |
| 671 | int cache_reply) |
| 672 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 673 | nfs41_init_sequence(args, res, cache_reply); |
| 674 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 675 | } |
| 676 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 677 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 678 | static inline |
| 679 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 680 | struct nfs4_sequence_res *res, int cache_reply) |
| 681 | { |
| 682 | } |
| 683 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 684 | static int nfs4_sequence_done(struct rpc_task *task, |
| 685 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 687 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 688 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 689 | #endif /* CONFIG_NFS_V4_1 */ |
| 690 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 691 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 692 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 693 | struct rpc_message *msg, |
| 694 | struct nfs4_sequence_args *args, |
| 695 | struct nfs4_sequence_res *res, |
| 696 | int cache_reply) |
| 697 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 698 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 699 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 700 | } |
| 701 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 702 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 703 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 704 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 705 | struct rpc_message *msg, |
| 706 | struct nfs4_sequence_args *args, |
| 707 | struct nfs4_sequence_res *res, |
| 708 | int cache_reply) |
| 709 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 710 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 711 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 712 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 713 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 714 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 716 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 718 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 719 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 720 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 721 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 722 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 723 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 726 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 727 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 728 | struct nfs_openargs o_arg; |
| 729 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 730 | struct nfs_open_confirmargs c_arg; |
| 731 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 732 | struct nfs4_string owner_name; |
| 733 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 734 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 735 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 736 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 737 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 738 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 739 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 740 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 741 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 742 | int rpc_status; |
| 743 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 744 | }; |
| 745 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 746 | |
| 747 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 748 | { |
| 749 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 750 | p->o_res.seqid = p->o_arg.seqid; |
| 751 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 752 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 753 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 754 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 755 | 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] | 756 | } |
| 757 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 758 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 759 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 760 | const struct iattr *attrs, |
| 761 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 762 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 763 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | struct inode *dir = parent->d_inode; |
| 765 | struct nfs_server *server = NFS_SERVER(dir); |
| 766 | struct nfs4_opendata *p; |
| 767 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 768 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | if (p == NULL) |
| 770 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 771 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 772 | if (p->o_arg.seqid == NULL) |
| 773 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 774 | nfs_sb_active(dentry->d_sb); |
| 775 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 776 | p->dir = parent; |
| 777 | p->owner = sp; |
| 778 | atomic_inc(&sp->so_count); |
| 779 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 780 | p->o_arg.open_flags = flags; |
| 781 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 782 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 783 | * will return permission denied for all bits until close */ |
| 784 | if (!(flags & O_EXCL)) { |
| 785 | /* ask server to check for all possible rights as results |
| 786 | * are cached */ |
| 787 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 788 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 789 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 790 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 791 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 792 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 793 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 794 | p->o_arg.server = server; |
| 795 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 796 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 798 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 799 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 800 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 801 | p->o_arg.u.attrs = &p->attrs; |
| 802 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 803 | |
| 804 | verf[0] = jiffies; |
| 805 | verf[1] = current->pid; |
| 806 | memcpy(p->o_arg.u.verifier.data, verf, |
| 807 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 808 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 809 | p->c_arg.fh = &p->o_res.fh; |
| 810 | p->c_arg.stateid = &p->o_res.stateid; |
| 811 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 812 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 813 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 814 | return p; |
| 815 | err_free: |
| 816 | kfree(p); |
| 817 | err: |
| 818 | dput(parent); |
| 819 | return NULL; |
| 820 | } |
| 821 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 822 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 824 | struct nfs4_opendata *p = container_of(kref, |
| 825 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 826 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 827 | |
| 828 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 829 | if (p->state != NULL) |
| 830 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 831 | nfs4_put_state_owner(p->owner); |
| 832 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 833 | dput(p->dentry); |
| 834 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 835 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 836 | kfree(p); |
| 837 | } |
| 838 | |
| 839 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 840 | { |
| 841 | if (p != NULL) |
| 842 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 843 | } |
| 844 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 845 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 846 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 847 | int ret; |
| 848 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 849 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 850 | return ret; |
| 851 | } |
| 852 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 853 | 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] | 854 | { |
| 855 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 856 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 857 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 858 | goto out; |
| 859 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 860 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 861 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 862 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 863 | break; |
| 864 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 865 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 866 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 867 | break; |
| 868 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 869 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 870 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 871 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 872 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 873 | return ret; |
| 874 | } |
| 875 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 876 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 877 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 878 | if (delegation == NULL) |
| 879 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 880 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 881 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 882 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 883 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 884 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 885 | return 1; |
| 886 | } |
| 887 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 888 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 889 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 890 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 891 | case FMODE_WRITE: |
| 892 | state->n_wronly++; |
| 893 | break; |
| 894 | case FMODE_READ: |
| 895 | state->n_rdonly++; |
| 896 | break; |
| 897 | case FMODE_READ|FMODE_WRITE: |
| 898 | state->n_rdwr++; |
| 899 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 901 | } |
| 902 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | 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] | 904 | { |
| 905 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 906 | nfs4_stateid_copy(&state->stateid, stateid); |
| 907 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 908 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 909 | case FMODE_READ: |
| 910 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 911 | break; |
| 912 | case FMODE_WRITE: |
| 913 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 914 | break; |
| 915 | case FMODE_READ|FMODE_WRITE: |
| 916 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 917 | } |
| 918 | } |
| 919 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | 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] | 921 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 922 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 923 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 924 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 925 | } |
| 926 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | 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] | 928 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 929 | /* |
| 930 | * Protect the call to nfs4_state_set_mode_locked and |
| 931 | * serialise the stateid update |
| 932 | */ |
| 933 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 934 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 935 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 936 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 937 | } |
| 938 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 939 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 940 | write_sequnlock(&state->seqlock); |
| 941 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 942 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 943 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | 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] | 947 | { |
| 948 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 949 | struct nfs_delegation *deleg_cur; |
| 950 | int ret = 0; |
| 951 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 952 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 953 | |
| 954 | rcu_read_lock(); |
| 955 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 956 | if (deleg_cur == NULL) |
| 957 | goto no_delegation; |
| 958 | |
| 959 | spin_lock(&deleg_cur->lock); |
| 960 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 962 | goto no_delegation_unlock; |
| 963 | |
| 964 | if (delegation == NULL) |
| 965 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 966 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 967 | goto no_delegation_unlock; |
| 968 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 969 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 971 | ret = 1; |
| 972 | no_delegation_unlock: |
| 973 | spin_unlock(&deleg_cur->lock); |
| 974 | no_delegation: |
| 975 | rcu_read_unlock(); |
| 976 | |
| 977 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 979 | ret = 1; |
| 980 | } |
| 981 | |
| 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 986 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 987 | { |
| 988 | struct nfs_delegation *delegation; |
| 989 | |
| 990 | rcu_read_lock(); |
| 991 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 992 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 993 | rcu_read_unlock(); |
| 994 | return; |
| 995 | } |
| 996 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 997 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 998 | } |
| 999 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1000 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1001 | { |
| 1002 | struct nfs4_state *state = opendata->state; |
| 1003 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1004 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1005 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1006 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1007 | nfs4_stateid stateid; |
| 1008 | int ret = -EAGAIN; |
| 1009 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1010 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1011 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1012 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | if (can_open_cached(state, fmode, open_mode)) { |
| 1014 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1015 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1016 | goto out_return_state; |
| 1017 | } |
| 1018 | spin_unlock(&state->owner->so_lock); |
| 1019 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1020 | rcu_read_lock(); |
| 1021 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1022 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1023 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1024 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1025 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1026 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1027 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1028 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1029 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1030 | if (ret != 0) |
| 1031 | goto out; |
| 1032 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1033 | |
| 1034 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1035 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1036 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1038 | out: |
| 1039 | return ERR_PTR(ret); |
| 1040 | out_return_state: |
| 1041 | atomic_inc(&state->count); |
| 1042 | return state; |
| 1043 | } |
| 1044 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1045 | static void |
| 1046 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1047 | { |
| 1048 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1049 | struct nfs_delegation *delegation; |
| 1050 | int delegation_flags = 0; |
| 1051 | |
| 1052 | rcu_read_lock(); |
| 1053 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1054 | if (delegation) |
| 1055 | delegation_flags = delegation->flags; |
| 1056 | rcu_read_unlock(); |
| 1057 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1058 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1059 | "returning a delegation for " |
| 1060 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1061 | clp->cl_hostname); |
| 1062 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1063 | nfs_inode_set_delegation(state->inode, |
| 1064 | data->owner->so_cred, |
| 1065 | &data->o_res); |
| 1066 | else |
| 1067 | nfs_inode_reclaim_delegation(state->inode, |
| 1068 | data->owner->so_cred, |
| 1069 | &data->o_res); |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1074 | * and update the nfs4_state. |
| 1075 | */ |
| 1076 | static struct nfs4_state * |
| 1077 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1078 | { |
| 1079 | struct inode *inode = data->state->inode; |
| 1080 | struct nfs4_state *state = data->state; |
| 1081 | int ret; |
| 1082 | |
| 1083 | if (!data->rpc_done) { |
| 1084 | ret = data->rpc_status; |
| 1085 | goto err; |
| 1086 | } |
| 1087 | |
| 1088 | ret = -ESTALE; |
| 1089 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1090 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1091 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1092 | goto err; |
| 1093 | |
| 1094 | ret = -ENOMEM; |
| 1095 | state = nfs4_get_open_state(inode, data->owner); |
| 1096 | if (state == NULL) |
| 1097 | goto err; |
| 1098 | |
| 1099 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1100 | if (ret) |
| 1101 | goto err; |
| 1102 | |
| 1103 | if (data->o_res.delegation_type != 0) |
| 1104 | nfs4_opendata_check_deleg(data, state); |
| 1105 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1106 | data->o_arg.fmode); |
| 1107 | |
| 1108 | return state; |
| 1109 | err: |
| 1110 | return ERR_PTR(ret); |
| 1111 | |
| 1112 | } |
| 1113 | |
| 1114 | static struct nfs4_state * |
| 1115 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1116 | { |
| 1117 | struct inode *inode; |
| 1118 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1119 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1120 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1121 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1122 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1123 | goto out; |
| 1124 | } |
| 1125 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1126 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1127 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1128 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1129 | 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] | 1130 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1131 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1132 | goto err; |
| 1133 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1134 | state = nfs4_get_open_state(inode, data->owner); |
| 1135 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1136 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1137 | if (data->o_res.delegation_type != 0) |
| 1138 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1139 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1141 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1142 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1143 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1144 | err_put_inode: |
| 1145 | iput(inode); |
| 1146 | err: |
| 1147 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1150 | static struct nfs4_state * |
| 1151 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1152 | { |
| 1153 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1154 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1155 | return _nfs4_opendata_to_nfs4_state(data); |
| 1156 | } |
| 1157 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1158 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1159 | { |
| 1160 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1161 | struct nfs_open_context *ctx; |
| 1162 | |
| 1163 | spin_lock(&state->inode->i_lock); |
| 1164 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1165 | if (ctx->state != state) |
| 1166 | continue; |
| 1167 | get_nfs_open_context(ctx); |
| 1168 | spin_unlock(&state->inode->i_lock); |
| 1169 | return ctx; |
| 1170 | } |
| 1171 | spin_unlock(&state->inode->i_lock); |
| 1172 | return ERR_PTR(-ENOENT); |
| 1173 | } |
| 1174 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1175 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1176 | { |
| 1177 | struct nfs4_opendata *opendata; |
| 1178 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1179 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1180 | if (opendata == NULL) |
| 1181 | return ERR_PTR(-ENOMEM); |
| 1182 | opendata->state = state; |
| 1183 | atomic_inc(&state->count); |
| 1184 | return opendata; |
| 1185 | } |
| 1186 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1187 | 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] | 1188 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1189 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1190 | int ret; |
| 1191 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1192 | opendata->o_arg.open_flags = 0; |
| 1193 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1194 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1195 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1196 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1197 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | if (ret != 0) |
| 1199 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1200 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1201 | if (IS_ERR(newstate)) |
| 1202 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1203 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1209 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1211 | int ret; |
| 1212 | |
| 1213 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1214 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1215 | smp_rmb(); |
| 1216 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1217 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1218 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1219 | if (ret != 0) |
| 1220 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1221 | if (newstate != state) |
| 1222 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1223 | } |
| 1224 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1225 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1226 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1227 | if (ret != 0) |
| 1228 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1229 | if (newstate != state) |
| 1230 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1231 | } |
| 1232 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1233 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1234 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1235 | if (ret != 0) |
| 1236 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1237 | if (newstate != state) |
| 1238 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1240 | /* |
| 1241 | * We may have performed cached opens for all three recoveries. |
| 1242 | * Check if we need to update the current stateid. |
| 1243 | */ |
| 1244 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1245 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1246 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1247 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1248 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1249 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1250 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | return 0; |
| 1252 | } |
| 1253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | /* |
| 1255 | * OPEN_RECLAIM: |
| 1256 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1258 | 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] | 1259 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1260 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1261 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1262 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | int status; |
| 1264 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1265 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1266 | if (IS_ERR(opendata)) |
| 1267 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1269 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1270 | rcu_read_lock(); |
| 1271 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1272 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1273 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1274 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1275 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1276 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | return status; |
| 1279 | } |
| 1280 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1281 | 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] | 1282 | { |
| 1283 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1284 | struct nfs4_exception exception = { }; |
| 1285 | int err; |
| 1286 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1287 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1288 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1289 | break; |
| 1290 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } while (exception.retry); |
| 1292 | return err; |
| 1293 | } |
| 1294 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1295 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1296 | { |
| 1297 | struct nfs_open_context *ctx; |
| 1298 | int ret; |
| 1299 | |
| 1300 | ctx = nfs4_state_find_open_context(state); |
| 1301 | if (IS_ERR(ctx)) |
| 1302 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1303 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | put_nfs_open_context(ctx); |
| 1305 | return ret; |
| 1306 | } |
| 1307 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1308 | static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1310 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1311 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1313 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1314 | if (IS_ERR(opendata)) |
| 1315 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1316 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1317 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1318 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1319 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1320 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1323 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
| 1325 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1326 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | int err; |
| 1328 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1329 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | switch (err) { |
| 1331 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1332 | case -ENOENT: |
| 1333 | case -ESTALE: |
| 1334 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1335 | case -NFS4ERR_BADSESSION: |
| 1336 | case -NFS4ERR_BADSLOT: |
| 1337 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1338 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1339 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1340 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1341 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | case -NFS4ERR_STALE_CLIENTID: |
| 1343 | case -NFS4ERR_STALE_STATEID: |
| 1344 | case -NFS4ERR_EXPIRED: |
| 1345 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1346 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1347 | goto out; |
| 1348 | case -ERESTARTSYS: |
| 1349 | /* |
| 1350 | * The show must go on: exit, but mark the |
| 1351 | * stateid as needing recovery. |
| 1352 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1353 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1354 | case -NFS4ERR_ADMIN_REVOKED: |
| 1355 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1356 | nfs_inode_find_state_and_recover(state->inode, |
| 1357 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1358 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1359 | case -EKEYEXPIRED: |
| 1360 | /* |
| 1361 | * User RPCSEC_GSS context has expired. |
| 1362 | * We cannot recover this stateid now, so |
| 1363 | * skip it and allow recovery thread to |
| 1364 | * proceed. |
| 1365 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1366 | case -ENOMEM: |
| 1367 | err = 0; |
| 1368 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } |
| 1370 | err = nfs4_handle_exception(server, err, &exception); |
| 1371 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1372 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | return err; |
| 1374 | } |
| 1375 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1376 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1377 | { |
| 1378 | struct nfs4_opendata *data = calldata; |
| 1379 | |
| 1380 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1381 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1382 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1383 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1384 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1385 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1386 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static void nfs4_open_confirm_release(void *calldata) |
| 1390 | { |
| 1391 | struct nfs4_opendata *data = calldata; |
| 1392 | struct nfs4_state *state = NULL; |
| 1393 | |
| 1394 | /* If this request hasn't been cancelled, do nothing */ |
| 1395 | if (data->cancelled == 0) |
| 1396 | goto out_free; |
| 1397 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1398 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1399 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1400 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1401 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1402 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1403 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1404 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1408 | .rpc_call_done = nfs4_open_confirm_done, |
| 1409 | .rpc_release = nfs4_open_confirm_release, |
| 1410 | }; |
| 1411 | |
| 1412 | /* |
| 1413 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1414 | */ |
| 1415 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1416 | { |
| 1417 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1418 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1419 | struct rpc_message msg = { |
| 1420 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1421 | .rpc_argp = &data->c_arg, |
| 1422 | .rpc_resp = &data->c_res, |
| 1423 | .rpc_cred = data->owner->so_cred, |
| 1424 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1425 | struct rpc_task_setup task_setup_data = { |
| 1426 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1427 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1428 | .callback_ops = &nfs4_open_confirm_ops, |
| 1429 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1430 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1431 | .flags = RPC_TASK_ASYNC, |
| 1432 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | int status; |
| 1434 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1435 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1436 | data->rpc_done = 0; |
| 1437 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1438 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1439 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1440 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1441 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1442 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1443 | if (status != 0) { |
| 1444 | data->cancelled = 1; |
| 1445 | smp_wmb(); |
| 1446 | } else |
| 1447 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1448 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | return status; |
| 1450 | } |
| 1451 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1452 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1454 | struct nfs4_opendata *data = calldata; |
| 1455 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1456 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1457 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1458 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1459 | /* |
| 1460 | * Check if we still need to send an OPEN call, or if we can use |
| 1461 | * a delegation instead. |
| 1462 | */ |
| 1463 | if (data->state != NULL) { |
| 1464 | struct nfs_delegation *delegation; |
| 1465 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1466 | 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] | 1467 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1468 | rcu_read_lock(); |
| 1469 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1470 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1471 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1472 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1473 | rcu_read_unlock(); |
| 1474 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1475 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1476 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1477 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1478 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1479 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1480 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1481 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1482 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1483 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1484 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1485 | &data->o_res.seq_res, |
| 1486 | task) != 0) |
| 1487 | nfs_release_seqid(data->o_arg.seqid); |
| 1488 | else |
| 1489 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1490 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1491 | unlock_no_action: |
| 1492 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1493 | out_no_action: |
| 1494 | task->tk_action = NULL; |
| 1495 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1498 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1499 | { |
| 1500 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1501 | nfs4_open_prepare(task, calldata); |
| 1502 | } |
| 1503 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1505 | { |
| 1506 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1508 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1509 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1510 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1511 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1512 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1513 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1514 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1515 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1516 | case S_IFREG: |
| 1517 | break; |
| 1518 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1519 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1520 | break; |
| 1521 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1522 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1523 | break; |
| 1524 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1525 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1526 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1527 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1528 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1529 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1530 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1531 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1532 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1534 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1535 | static void nfs4_open_release(void *calldata) |
| 1536 | { |
| 1537 | struct nfs4_opendata *data = calldata; |
| 1538 | struct nfs4_state *state = NULL; |
| 1539 | |
| 1540 | /* If this request hasn't been cancelled, do nothing */ |
| 1541 | if (data->cancelled == 0) |
| 1542 | goto out_free; |
| 1543 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1544 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1545 | goto out_free; |
| 1546 | /* In case we need an open_confirm, no cleanup! */ |
| 1547 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1548 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1549 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1550 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1551 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1552 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1553 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1557 | .rpc_call_prepare = nfs4_open_prepare, |
| 1558 | .rpc_call_done = nfs4_open_done, |
| 1559 | .rpc_release = nfs4_open_release, |
| 1560 | }; |
| 1561 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1562 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1563 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1564 | .rpc_call_done = nfs4_open_done, |
| 1565 | .rpc_release = nfs4_open_release, |
| 1566 | }; |
| 1567 | |
| 1568 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1569 | { |
| 1570 | struct inode *dir = data->dir->d_inode; |
| 1571 | struct nfs_server *server = NFS_SERVER(dir); |
| 1572 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1573 | struct nfs_openres *o_res = &data->o_res; |
| 1574 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1575 | struct rpc_message msg = { |
| 1576 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1577 | .rpc_argp = o_arg, |
| 1578 | .rpc_resp = o_res, |
| 1579 | .rpc_cred = data->owner->so_cred, |
| 1580 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1581 | struct rpc_task_setup task_setup_data = { |
| 1582 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1583 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1584 | .callback_ops = &nfs4_open_ops, |
| 1585 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1586 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1587 | .flags = RPC_TASK_ASYNC, |
| 1588 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1589 | int status; |
| 1590 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1591 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1592 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1593 | data->rpc_done = 0; |
| 1594 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1595 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1596 | if (isrecover) |
| 1597 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1598 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1599 | if (IS_ERR(task)) |
| 1600 | return PTR_ERR(task); |
| 1601 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1602 | if (status != 0) { |
| 1603 | data->cancelled = 1; |
| 1604 | smp_wmb(); |
| 1605 | } else |
| 1606 | status = data->rpc_status; |
| 1607 | rpc_put_task(task); |
| 1608 | |
| 1609 | return status; |
| 1610 | } |
| 1611 | |
| 1612 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1613 | { |
| 1614 | struct inode *dir = data->dir->d_inode; |
| 1615 | struct nfs_openres *o_res = &data->o_res; |
| 1616 | int status; |
| 1617 | |
| 1618 | status = nfs4_run_open_task(data, 1); |
| 1619 | if (status != 0 || !data->rpc_done) |
| 1620 | return status; |
| 1621 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1622 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1623 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1624 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1625 | status = _nfs4_proc_open_confirm(data); |
| 1626 | if (status != 0) |
| 1627 | return status; |
| 1628 | } |
| 1629 | |
| 1630 | return status; |
| 1631 | } |
| 1632 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1633 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1634 | struct nfs4_opendata *opendata, |
| 1635 | struct nfs4_state *state, fmode_t fmode) |
| 1636 | { |
| 1637 | struct nfs_access_entry cache; |
| 1638 | u32 mask; |
| 1639 | |
| 1640 | /* access call failed or for some reason the server doesn't |
| 1641 | * support any access modes -- defer access call until later */ |
| 1642 | if (opendata->o_res.access_supported == 0) |
| 1643 | return 0; |
| 1644 | |
| 1645 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1646 | /* don't check MAY_WRITE - a newly created file may not have |
| 1647 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1648 | if (fmode & FMODE_READ) |
| 1649 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1650 | if (fmode & FMODE_EXEC) |
| 1651 | mask |= MAY_EXEC; |
| 1652 | |
| 1653 | cache.cred = cred; |
| 1654 | cache.jiffies = jiffies; |
| 1655 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1656 | nfs_access_add_cache(state->inode, &cache); |
| 1657 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1658 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1659 | return 0; |
| 1660 | |
| 1661 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1662 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1663 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1666 | /* |
| 1667 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1668 | */ |
| 1669 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1670 | { |
| 1671 | struct inode *dir = data->dir->d_inode; |
| 1672 | struct nfs_server *server = NFS_SERVER(dir); |
| 1673 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1674 | struct nfs_openres *o_res = &data->o_res; |
| 1675 | int status; |
| 1676 | |
| 1677 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1678 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1679 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1680 | if (status != 0) { |
| 1681 | if (status == -NFS4ERR_BADNAME && |
| 1682 | !(o_arg->open_flags & O_CREAT)) |
| 1683 | return -ENOENT; |
| 1684 | return status; |
| 1685 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1687 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1688 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1689 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1690 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1691 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1692 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1694 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1696 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
| 1698 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1699 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1703 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1704 | { |
| 1705 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1706 | } |
| 1707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | /* |
| 1709 | * OPEN_EXPIRED: |
| 1710 | * reclaim state on the server after a network partition. |
| 1711 | * Assumes caller holds the appropriate lock |
| 1712 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1713 | 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] | 1714 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1715 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1716 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1718 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1719 | if (IS_ERR(opendata)) |
| 1720 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1721 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1722 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1723 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1724 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1725 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1728 | 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] | 1729 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1730 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1731 | struct nfs4_exception exception = { }; |
| 1732 | int err; |
| 1733 | |
| 1734 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1735 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1736 | switch (err) { |
| 1737 | default: |
| 1738 | goto out; |
| 1739 | case -NFS4ERR_GRACE: |
| 1740 | case -NFS4ERR_DELAY: |
| 1741 | nfs4_handle_exception(server, err, &exception); |
| 1742 | err = 0; |
| 1743 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1744 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1745 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1746 | return err; |
| 1747 | } |
| 1748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1750 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1752 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1754 | ctx = nfs4_state_find_open_context(state); |
| 1755 | if (IS_ERR(ctx)) |
| 1756 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1757 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1758 | put_nfs_open_context(ctx); |
| 1759 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1762 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1763 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1764 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1765 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1766 | nfs4_stateid *stateid = &state->stateid; |
| 1767 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1768 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1769 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1770 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1771 | return; |
| 1772 | |
| 1773 | status = nfs41_test_stateid(server, stateid); |
| 1774 | if (status != NFS_OK) { |
| 1775 | /* Free the stateid unless the server explicitly |
| 1776 | * informs us the stateid is unrecognized. */ |
| 1777 | if (status != -NFS4ERR_BAD_STATEID) |
| 1778 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1779 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1780 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1781 | write_seqlock(&state->seqlock); |
| 1782 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1783 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1784 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1790 | * |
| 1791 | * @state: NFSv4 state for an inode |
| 1792 | * |
| 1793 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1794 | * Otherwise a negative NFS4ERR value is returned. |
| 1795 | */ |
| 1796 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1797 | { |
| 1798 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1799 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1800 | int status; |
| 1801 | |
| 1802 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1803 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1804 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1805 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1806 | return -NFS4ERR_BAD_STATEID; |
| 1807 | |
| 1808 | status = nfs41_test_stateid(server, stateid); |
| 1809 | if (status != NFS_OK) { |
| 1810 | /* Free the stateid unless the server explicitly |
| 1811 | * informs us the stateid is unrecognized. */ |
| 1812 | if (status != -NFS4ERR_BAD_STATEID) |
| 1813 | nfs41_free_stateid(server, stateid); |
| 1814 | |
| 1815 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1816 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1817 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1818 | } |
| 1819 | return status; |
| 1820 | } |
| 1821 | |
| 1822 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1823 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1824 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1825 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1826 | nfs41_clear_delegation_stateid(state); |
| 1827 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1828 | if (status != NFS_OK) |
| 1829 | status = nfs4_open_expired(sp, state); |
| 1830 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1831 | } |
| 1832 | #endif |
| 1833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1835 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1836 | * fields corresponding to attributes that were used to store the verifier. |
| 1837 | * Make sure we clobber those fields in the later setattr call |
| 1838 | */ |
| 1839 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1840 | { |
| 1841 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1842 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1843 | sattr->ia_valid |= ATTR_ATIME; |
| 1844 | |
| 1845 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1846 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1847 | sattr->ia_valid |= ATTR_MTIME; |
| 1848 | } |
| 1849 | |
| 1850 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1851 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1853 | static int _nfs4_do_open(struct inode *dir, |
| 1854 | struct dentry *dentry, |
| 1855 | fmode_t fmode, |
| 1856 | int flags, |
| 1857 | struct iattr *sattr, |
| 1858 | struct rpc_cred *cred, |
| 1859 | struct nfs4_state **res, |
| 1860 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | { |
| 1862 | struct nfs4_state_owner *sp; |
| 1863 | struct nfs4_state *state = NULL; |
| 1864 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1865 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1866 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
| 1868 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1870 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1871 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1873 | goto out_err; |
| 1874 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1875 | status = nfs4_recover_expired_lease(server); |
| 1876 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1877 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1878 | if (dentry->d_inode != NULL) |
| 1879 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1880 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1881 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1882 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1883 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1885 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1886 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1887 | if (!opendata->f_attr.mdsthreshold) |
| 1888 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1889 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1890 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1891 | if (dentry->d_inode != NULL) |
| 1892 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1893 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1894 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1896 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1898 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1899 | status = PTR_ERR(state); |
| 1900 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1901 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1902 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1903 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1904 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1905 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 1906 | if (status != 0) |
| 1907 | goto err_opendata_put; |
| 1908 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1909 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1910 | nfs4_exclusive_attrset(opendata, sattr); |
| 1911 | |
| 1912 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1913 | status = nfs4_do_setattr(state->inode, cred, |
| 1914 | opendata->o_res.f_attr, sattr, |
| 1915 | state); |
| 1916 | if (status == 0) |
| 1917 | nfs_setattr_update_inode(state->inode, sattr); |
| 1918 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1919 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1920 | |
| 1921 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1922 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1923 | else |
| 1924 | kfree(opendata->f_attr.mdsthreshold); |
| 1925 | opendata->f_attr.mdsthreshold = NULL; |
| 1926 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1927 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | *res = state; |
| 1930 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1931 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1932 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1933 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1934 | err_put_state_owner: |
| 1935 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | *res = NULL; |
| 1938 | return status; |
| 1939 | } |
| 1940 | |
| 1941 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1942 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1943 | struct dentry *dentry, |
| 1944 | fmode_t fmode, |
| 1945 | int flags, |
| 1946 | struct iattr *sattr, |
| 1947 | struct rpc_cred *cred, |
| 1948 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | { |
| 1950 | struct nfs4_exception exception = { }; |
| 1951 | struct nfs4_state *res; |
| 1952 | int status; |
| 1953 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1954 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1956 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1957 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | if (status == 0) |
| 1959 | break; |
| 1960 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1961 | * book-keeping w.r.t. state-changing operations |
| 1962 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1963 | * It is actually a sign of a bug on the client or on the server. |
| 1964 | * |
| 1965 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1966 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | * have unhashed the old state_owner for us, and that we can |
| 1968 | * therefore safely retry using a new one. We should still warn |
| 1969 | * the user though... |
| 1970 | */ |
| 1971 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1972 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1973 | " returned a bad sequence-id error!\n", |
| 1974 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | exception.retry = 1; |
| 1976 | continue; |
| 1977 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1978 | /* |
| 1979 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1980 | * state before it received the OPEN_CONFIRM. |
| 1981 | * Recover by retrying the request as per the discussion |
| 1982 | * on Page 181 of RFC3530. |
| 1983 | */ |
| 1984 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1985 | exception.retry = 1; |
| 1986 | continue; |
| 1987 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1988 | if (status == -EAGAIN) { |
| 1989 | /* We must have found a delegation */ |
| 1990 | exception.retry = 1; |
| 1991 | continue; |
| 1992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1994 | status, &exception)); |
| 1995 | } while (exception.retry); |
| 1996 | return res; |
| 1997 | } |
| 1998 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1999 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2000 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2001 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2003 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2005 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | .iap = sattr, |
| 2007 | .server = server, |
| 2008 | .bitmask = server->attr_bitmask, |
| 2009 | }; |
| 2010 | struct nfs_setattrres res = { |
| 2011 | .fattr = fattr, |
| 2012 | .server = server, |
| 2013 | }; |
| 2014 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2015 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2016 | .rpc_argp = &arg, |
| 2017 | .rpc_resp = &res, |
| 2018 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2020 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2021 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2023 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2025 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2026 | struct nfs_lockowner lockowner = { |
| 2027 | .l_owner = current->files, |
| 2028 | .l_pid = current->tgid, |
| 2029 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2030 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2031 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2032 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2033 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2034 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2035 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2036 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2038 | 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] | 2039 | if (status == 0 && state != NULL) |
| 2040 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2041 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2044 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2045 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2046 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2048 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2049 | struct nfs4_exception exception = { |
| 2050 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2051 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2052 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | int err; |
| 2054 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2055 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2056 | switch (err) { |
| 2057 | case -NFS4ERR_OPENMODE: |
| 2058 | if (state && !(state->state & FMODE_WRITE)) { |
| 2059 | err = -EBADF; |
| 2060 | if (sattr->ia_valid & ATTR_OPEN) |
| 2061 | err = -EACCES; |
| 2062 | goto out; |
| 2063 | } |
| 2064 | } |
| 2065 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2067 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | return err; |
| 2069 | } |
| 2070 | |
| 2071 | struct nfs4_closedata { |
| 2072 | struct inode *inode; |
| 2073 | struct nfs4_state *state; |
| 2074 | struct nfs_closeargs arg; |
| 2075 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2076 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2077 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2078 | bool roc; |
| 2079 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | }; |
| 2081 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2082 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2083 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2084 | struct nfs4_closedata *calldata = data; |
| 2085 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2086 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2087 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2088 | if (calldata->roc) |
| 2089 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2090 | nfs4_put_open_state(calldata->state); |
| 2091 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2092 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2093 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2094 | kfree(calldata); |
| 2095 | } |
| 2096 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2097 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2098 | fmode_t fmode) |
| 2099 | { |
| 2100 | spin_lock(&state->owner->so_lock); |
| 2101 | if (!(fmode & FMODE_READ)) |
| 2102 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2103 | if (!(fmode & FMODE_WRITE)) |
| 2104 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2105 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2106 | spin_unlock(&state->owner->so_lock); |
| 2107 | } |
| 2108 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2109 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2111 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2114 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2115 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2116 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2117 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | /* hmm. we are done with the inode, and in the process of freeing |
| 2119 | * the state_owner. we keep this around to process errors |
| 2120 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | switch (task->tk_status) { |
| 2122 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2123 | if (calldata->roc) |
| 2124 | pnfs_roc_set_barrier(state->inode, |
| 2125 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2126 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2127 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2128 | nfs4_close_clear_stateid_flags(state, |
| 2129 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | break; |
| 2131 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2132 | case -NFS4ERR_OLD_STATEID: |
| 2133 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2135 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2136 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2138 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2139 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2141 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2142 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2143 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2146 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2148 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2149 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2150 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2151 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2152 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2153 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2154 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2155 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2156 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2157 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2158 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2159 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2160 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2161 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2162 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2163 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2164 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2165 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2166 | } |
| 2167 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2168 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2169 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2170 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2171 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2172 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2173 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2174 | |
| 2175 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2176 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2177 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2178 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2179 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2180 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2181 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2182 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2183 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2184 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2185 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2186 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2187 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2188 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2189 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2190 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2191 | &calldata->arg.seq_args, |
| 2192 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2193 | task) != 0) |
| 2194 | nfs_release_seqid(calldata->arg.seqid); |
| 2195 | else |
| 2196 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2197 | out: |
| 2198 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2201 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2202 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2203 | .rpc_call_done = nfs4_close_done, |
| 2204 | .rpc_release = nfs4_free_closedata, |
| 2205 | }; |
| 2206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | /* |
| 2208 | * It is possible for data to be read/written from a mem-mapped file |
| 2209 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2210 | * This means that we can't safely call nfsv4 close on a file until |
| 2211 | * the inode is cleared. This in turn means that we are not good |
| 2212 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2213 | * share state even when we are done with one of the three share |
| 2214 | * stateid's in the inode. |
| 2215 | * |
| 2216 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2217 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2218 | 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] | 2219 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2220 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2222 | struct nfs4_state_owner *sp = state->owner; |
| 2223 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2224 | struct rpc_message msg = { |
| 2225 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2226 | .rpc_cred = state->owner->so_cred, |
| 2227 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2228 | struct rpc_task_setup task_setup_data = { |
| 2229 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2230 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2231 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2232 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2233 | .flags = RPC_TASK_ASYNC, |
| 2234 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2235 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2237 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2239 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2240 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2241 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2243 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2244 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2246 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2247 | if (calldata->arg.seqid == NULL) |
| 2248 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2249 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2250 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2251 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2252 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2253 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2254 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2255 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2256 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2257 | msg.rpc_argp = &calldata->arg; |
| 2258 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2259 | task_setup_data.callback_data = calldata; |
| 2260 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2261 | if (IS_ERR(task)) |
| 2262 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2263 | status = 0; |
| 2264 | if (wait) |
| 2265 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2266 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2267 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2268 | out_free_calldata: |
| 2269 | kfree(calldata); |
| 2270 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2271 | nfs4_put_open_state(state); |
| 2272 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2273 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2276 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2277 | 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] | 2278 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | struct nfs4_state *state; |
| 2280 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2281 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2282 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2283 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2284 | if (IS_ERR(state)) |
| 2285 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2286 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2287 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2290 | 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] | 2291 | { |
| 2292 | if (ctx->state == NULL) |
| 2293 | return; |
| 2294 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2295 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2296 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2297 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | |
| 2300 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2301 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2302 | struct nfs4_server_caps_arg args = { |
| 2303 | .fhandle = fhandle, |
| 2304 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | struct nfs4_server_caps_res res = {}; |
| 2306 | struct rpc_message msg = { |
| 2307 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2308 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | .rpc_resp = &res, |
| 2310 | }; |
| 2311 | int status; |
| 2312 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2313 | 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] | 2314 | if (status == 0) { |
| 2315 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2316 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2317 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2318 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2319 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2320 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2322 | server->caps |= NFS_CAP_ACLS; |
| 2323 | if (res.has_links != 0) |
| 2324 | server->caps |= NFS_CAP_HARDLINKS; |
| 2325 | if (res.has_symlinks != 0) |
| 2326 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2327 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2328 | server->caps |= NFS_CAP_FILEID; |
| 2329 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2330 | server->caps |= NFS_CAP_MODE; |
| 2331 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2332 | server->caps |= NFS_CAP_NLINK; |
| 2333 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2334 | server->caps |= NFS_CAP_OWNER; |
| 2335 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2336 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2337 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2338 | server->caps |= NFS_CAP_ATIME; |
| 2339 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2340 | server->caps |= NFS_CAP_CTIME; |
| 2341 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2342 | server->caps |= NFS_CAP_MTIME; |
| 2343 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2344 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2345 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2346 | 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] | 2347 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2348 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | return status; |
| 2352 | } |
| 2353 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2354 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | { |
| 2356 | struct nfs4_exception exception = { }; |
| 2357 | int err; |
| 2358 | do { |
| 2359 | err = nfs4_handle_exception(server, |
| 2360 | _nfs4_server_capabilities(server, fhandle), |
| 2361 | &exception); |
| 2362 | } while (exception.retry); |
| 2363 | return err; |
| 2364 | } |
| 2365 | |
| 2366 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2367 | struct nfs_fsinfo *info) |
| 2368 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | struct nfs4_lookup_root_arg args = { |
| 2370 | .bitmask = nfs4_fattr_bitmap, |
| 2371 | }; |
| 2372 | struct nfs4_lookup_res res = { |
| 2373 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2374 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | .fh = fhandle, |
| 2376 | }; |
| 2377 | struct rpc_message msg = { |
| 2378 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2379 | .rpc_argp = &args, |
| 2380 | .rpc_resp = &res, |
| 2381 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2382 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2383 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2384 | 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] | 2385 | } |
| 2386 | |
| 2387 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2388 | struct nfs_fsinfo *info) |
| 2389 | { |
| 2390 | struct nfs4_exception exception = { }; |
| 2391 | int err; |
| 2392 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2393 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2394 | switch (err) { |
| 2395 | case 0: |
| 2396 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2397 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2398 | default: |
| 2399 | err = nfs4_handle_exception(server, err, &exception); |
| 2400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2402 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | return err; |
| 2404 | } |
| 2405 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2406 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2407 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2408 | { |
| 2409 | struct rpc_auth *auth; |
| 2410 | int ret; |
| 2411 | |
| 2412 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2413 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2414 | ret = -EIO; |
| 2415 | goto out; |
| 2416 | } |
| 2417 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2418 | out: |
| 2419 | return ret; |
| 2420 | } |
| 2421 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2422 | 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] | 2423 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2425 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2426 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2428 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2429 | if (len < 0) |
| 2430 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2431 | |
| 2432 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2433 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2434 | * thus has already been tried. */ |
| 2435 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2436 | continue; |
| 2437 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2438 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2439 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2440 | continue; |
| 2441 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2442 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2443 | /* |
| 2444 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2445 | * to access the mount. It could also mean that we tried to mount |
| 2446 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2447 | * existing mount programs don't handle -EACCES very well so it should |
| 2448 | * be mapped to -EPERM instead. |
| 2449 | */ |
| 2450 | if (status == -EACCES) |
| 2451 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2452 | return status; |
| 2453 | } |
| 2454 | |
| 2455 | /* |
| 2456 | * get the file handle for the "/" directory on the server |
| 2457 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2458 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2459 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2460 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2461 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2462 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2463 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2464 | /* |
| 2465 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2466 | * by nfs4_map_errors() as this function exits. |
| 2467 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2468 | status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | if (status == 0) |
| 2470 | status = nfs4_server_capabilities(server, fhandle); |
| 2471 | if (status == 0) |
| 2472 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2473 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2476 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2477 | struct nfs_fsinfo *info) |
| 2478 | { |
| 2479 | int error; |
| 2480 | struct nfs_fattr *fattr = info->fattr; |
| 2481 | |
| 2482 | error = nfs4_server_capabilities(server, mntfh); |
| 2483 | if (error < 0) { |
| 2484 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2485 | return error; |
| 2486 | } |
| 2487 | |
| 2488 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2489 | if (error < 0) { |
| 2490 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2491 | return error; |
| 2492 | } |
| 2493 | |
| 2494 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2495 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2496 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2497 | |
| 2498 | return error; |
| 2499 | } |
| 2500 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2501 | /* |
| 2502 | * Get locations and (maybe) other attributes of a referral. |
| 2503 | * Note that we'll actually follow the referral later when |
| 2504 | * we detect fsid mismatch in inode revalidation |
| 2505 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2506 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2507 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2508 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2509 | { |
| 2510 | int status = -ENOMEM; |
| 2511 | struct page *page = NULL; |
| 2512 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2513 | |
| 2514 | page = alloc_page(GFP_KERNEL); |
| 2515 | if (page == NULL) |
| 2516 | goto out; |
| 2517 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2518 | if (locations == NULL) |
| 2519 | goto out; |
| 2520 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2521 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2522 | if (status != 0) |
| 2523 | goto out; |
| 2524 | /* Make sure server returned a different fsid for the referral */ |
| 2525 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2526 | dprintk("%s: server did not return a different fsid for" |
| 2527 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2528 | status = -EIO; |
| 2529 | goto out; |
| 2530 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2531 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2532 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2533 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2534 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2535 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2536 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2537 | out: |
| 2538 | if (page) |
| 2539 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2540 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2541 | return status; |
| 2542 | } |
| 2543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2545 | { |
| 2546 | struct nfs4_getattr_arg args = { |
| 2547 | .fh = fhandle, |
| 2548 | .bitmask = server->attr_bitmask, |
| 2549 | }; |
| 2550 | struct nfs4_getattr_res res = { |
| 2551 | .fattr = fattr, |
| 2552 | .server = server, |
| 2553 | }; |
| 2554 | struct rpc_message msg = { |
| 2555 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2556 | .rpc_argp = &args, |
| 2557 | .rpc_resp = &res, |
| 2558 | }; |
| 2559 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2560 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2561 | 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] | 2562 | } |
| 2563 | |
| 2564 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2565 | { |
| 2566 | struct nfs4_exception exception = { }; |
| 2567 | int err; |
| 2568 | do { |
| 2569 | err = nfs4_handle_exception(server, |
| 2570 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2571 | &exception); |
| 2572 | } while (exception.retry); |
| 2573 | return err; |
| 2574 | } |
| 2575 | |
| 2576 | /* |
| 2577 | * The file is not closed if it is opened due to the a request to change |
| 2578 | * the size of the file. The open call will not be needed once the |
| 2579 | * VFS layer lookup-intents are implemented. |
| 2580 | * |
| 2581 | * Close is called when the inode is destroyed. |
| 2582 | * If we haven't opened the file for O_WRONLY, we |
| 2583 | * need to in the size_change case to obtain a stateid. |
| 2584 | * |
| 2585 | * Got race? |
| 2586 | * Because OPEN is always done by name in nfsv4, it is |
| 2587 | * possible that we opened a different file by the same |
| 2588 | * name. We can recognize this race condition, but we |
| 2589 | * can't do anything about it besides returning an error. |
| 2590 | * |
| 2591 | * This will be fixed with VFS changes (lookup-intent). |
| 2592 | */ |
| 2593 | static int |
| 2594 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2595 | struct iattr *sattr) |
| 2596 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2597 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2598 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2599 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | int status; |
| 2601 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2602 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2603 | pnfs_return_layout(inode); |
| 2604 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2605 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2607 | /* Deal with open(O_TRUNC) */ |
| 2608 | if (sattr->ia_valid & ATTR_OPEN) |
| 2609 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2610 | |
| 2611 | /* Optimization: if the end result is no change, don't RPC */ |
| 2612 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2613 | return 0; |
| 2614 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2615 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2616 | if (sattr->ia_valid & ATTR_FILE) { |
| 2617 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2618 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2619 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2620 | if (ctx) { |
| 2621 | cred = ctx->cred; |
| 2622 | state = ctx->state; |
| 2623 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2627 | if (status == 0) |
| 2628 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | return status; |
| 2630 | } |
| 2631 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2632 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2633 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2634 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2635 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2636 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2637 | int status; |
| 2638 | struct nfs4_lookup_arg args = { |
| 2639 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2640 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2641 | .name = name, |
| 2642 | }; |
| 2643 | struct nfs4_lookup_res res = { |
| 2644 | .server = server, |
| 2645 | .fattr = fattr, |
| 2646 | .fh = fhandle, |
| 2647 | }; |
| 2648 | struct rpc_message msg = { |
| 2649 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2650 | .rpc_argp = &args, |
| 2651 | .rpc_resp = &res, |
| 2652 | }; |
| 2653 | |
| 2654 | nfs_fattr_init(fattr); |
| 2655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2657 | 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] | 2658 | dprintk("NFS reply lookup: %d\n", status); |
| 2659 | return status; |
| 2660 | } |
| 2661 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2662 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2663 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2664 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2665 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2666 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2667 | fattr->nlink = 2; |
| 2668 | } |
| 2669 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2670 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2671 | struct qstr *name, struct nfs_fh *fhandle, |
| 2672 | struct nfs_fattr *fattr) |
| 2673 | { |
| 2674 | struct nfs4_exception exception = { }; |
| 2675 | struct rpc_clnt *client = *clnt; |
| 2676 | int err; |
| 2677 | do { |
| 2678 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2679 | switch (err) { |
| 2680 | case -NFS4ERR_BADNAME: |
| 2681 | err = -ENOENT; |
| 2682 | goto out; |
| 2683 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2684 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2685 | goto out; |
| 2686 | case -NFS4ERR_WRONGSEC: |
| 2687 | err = -EPERM; |
| 2688 | if (client != *clnt) |
| 2689 | goto out; |
| 2690 | |
| 2691 | client = nfs4_create_sec_client(client, dir, name); |
| 2692 | if (IS_ERR(client)) |
| 2693 | return PTR_ERR(client); |
| 2694 | |
| 2695 | exception.retry = 1; |
| 2696 | break; |
| 2697 | default: |
| 2698 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2699 | } |
| 2700 | } while (exception.retry); |
| 2701 | |
| 2702 | out: |
| 2703 | if (err == 0) |
| 2704 | *clnt = client; |
| 2705 | else if (client != *clnt) |
| 2706 | rpc_shutdown_client(client); |
| 2707 | |
| 2708 | return err; |
| 2709 | } |
| 2710 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2711 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2712 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2714 | int status; |
| 2715 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2716 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2717 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2718 | if (client != NFS_CLIENT(dir)) { |
| 2719 | rpc_shutdown_client(client); |
| 2720 | nfs_fixup_secinfo_attributes(fattr); |
| 2721 | } |
| 2722 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2725 | struct rpc_clnt * |
| 2726 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2727 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2728 | { |
| 2729 | int status; |
| 2730 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2731 | |
| 2732 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2733 | if (status < 0) { |
| 2734 | rpc_shutdown_client(client); |
| 2735 | return ERR_PTR(status); |
| 2736 | } |
| 2737 | return client; |
| 2738 | } |
| 2739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2741 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2742 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | struct nfs4_accessargs args = { |
| 2744 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2745 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2747 | struct nfs4_accessres res = { |
| 2748 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2749 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | struct rpc_message msg = { |
| 2751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2752 | .rpc_argp = &args, |
| 2753 | .rpc_resp = &res, |
| 2754 | .rpc_cred = entry->cred, |
| 2755 | }; |
| 2756 | int mode = entry->mask; |
| 2757 | int status; |
| 2758 | |
| 2759 | /* |
| 2760 | * Determine which access bits we want to ask for... |
| 2761 | */ |
| 2762 | if (mode & MAY_READ) |
| 2763 | args.access |= NFS4_ACCESS_READ; |
| 2764 | if (S_ISDIR(inode->i_mode)) { |
| 2765 | if (mode & MAY_WRITE) |
| 2766 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2767 | if (mode & MAY_EXEC) |
| 2768 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2769 | } else { |
| 2770 | if (mode & MAY_WRITE) |
| 2771 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2772 | if (mode & MAY_EXEC) |
| 2773 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2774 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2775 | |
| 2776 | res.fattr = nfs_alloc_fattr(); |
| 2777 | if (res.fattr == NULL) |
| 2778 | return -ENOMEM; |
| 2779 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2780 | 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] | 2781 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2782 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2783 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2785 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | return status; |
| 2787 | } |
| 2788 | |
| 2789 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2790 | { |
| 2791 | struct nfs4_exception exception = { }; |
| 2792 | int err; |
| 2793 | do { |
| 2794 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2795 | _nfs4_proc_access(inode, entry), |
| 2796 | &exception); |
| 2797 | } while (exception.retry); |
| 2798 | return err; |
| 2799 | } |
| 2800 | |
| 2801 | /* |
| 2802 | * TODO: For the time being, we don't try to get any attributes |
| 2803 | * along with any of the zero-copy operations READ, READDIR, |
| 2804 | * READLINK, WRITE. |
| 2805 | * |
| 2806 | * In the case of the first three, we want to put the GETATTR |
| 2807 | * after the read-type operation -- this is because it is hard |
| 2808 | * to predict the length of a GETATTR response in v4, and thus |
| 2809 | * align the READ data correctly. This means that the GETATTR |
| 2810 | * may end up partially falling into the page cache, and we should |
| 2811 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2812 | * To do this efficiently, we need to know the total length |
| 2813 | * of data received, which doesn't seem to be available outside |
| 2814 | * of the RPC layer. |
| 2815 | * |
| 2816 | * In the case of WRITE, we also want to put the GETATTR after |
| 2817 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2818 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | * |
| 2820 | * Both of these changes to the XDR layer would in fact be quite |
| 2821 | * minor, but I decided to leave them for a subsequent patch. |
| 2822 | */ |
| 2823 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2824 | unsigned int pgbase, unsigned int pglen) |
| 2825 | { |
| 2826 | struct nfs4_readlink args = { |
| 2827 | .fh = NFS_FH(inode), |
| 2828 | .pgbase = pgbase, |
| 2829 | .pglen = pglen, |
| 2830 | .pages = &page, |
| 2831 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2832 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | struct rpc_message msg = { |
| 2834 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2835 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2836 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | }; |
| 2838 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2839 | 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] | 2840 | } |
| 2841 | |
| 2842 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2843 | unsigned int pgbase, unsigned int pglen) |
| 2844 | { |
| 2845 | struct nfs4_exception exception = { }; |
| 2846 | int err; |
| 2847 | do { |
| 2848 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2849 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2850 | &exception); |
| 2851 | } while (exception.retry); |
| 2852 | return err; |
| 2853 | } |
| 2854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2856 | * 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] | 2857 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | static int |
| 2859 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2860 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2862 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | int status = 0; |
| 2865 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2866 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2867 | if (IS_ERR(ctx)) |
| 2868 | return PTR_ERR(ctx); |
| 2869 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2870 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2871 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2872 | flags, sattr, ctx->cred, |
| 2873 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2874 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | if (IS_ERR(state)) { |
| 2876 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2877 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2879 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2880 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2881 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2883 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | return status; |
| 2885 | } |
| 2886 | |
| 2887 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2888 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2889 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2890 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2892 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2894 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2895 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2896 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2898 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2899 | .rpc_argp = &args, |
| 2900 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2902 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2903 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2904 | 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] | 2905 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2906 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | return status; |
| 2908 | } |
| 2909 | |
| 2910 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2911 | { |
| 2912 | struct nfs4_exception exception = { }; |
| 2913 | int err; |
| 2914 | do { |
| 2915 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2916 | _nfs4_proc_remove(dir, name), |
| 2917 | &exception); |
| 2918 | } while (exception.retry); |
| 2919 | return err; |
| 2920 | } |
| 2921 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2922 | 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] | 2923 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2924 | struct nfs_server *server = NFS_SERVER(dir); |
| 2925 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2926 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2928 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2930 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2933 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2934 | { |
| 2935 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2936 | &data->args.seq_args, |
| 2937 | &data->res.seq_res, |
| 2938 | task)) |
| 2939 | return; |
| 2940 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2943 | 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] | 2944 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2945 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2946 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2947 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2948 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2949 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2950 | return 0; |
| 2951 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2952 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2955 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2956 | { |
| 2957 | struct nfs_server *server = NFS_SERVER(dir); |
| 2958 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2959 | struct nfs_renameres *res = msg->rpc_resp; |
| 2960 | |
| 2961 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2962 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2963 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2964 | } |
| 2965 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2966 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2967 | { |
| 2968 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2969 | &data->args.seq_args, |
| 2970 | &data->res.seq_res, |
| 2971 | task)) |
| 2972 | return; |
| 2973 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2977 | struct inode *new_dir) |
| 2978 | { |
| 2979 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2980 | |
| 2981 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2982 | return 0; |
| 2983 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2984 | return 0; |
| 2985 | |
| 2986 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2987 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2988 | return 1; |
| 2989 | } |
| 2990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2992 | struct inode *new_dir, struct qstr *new_name) |
| 2993 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2994 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2995 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | .old_dir = NFS_FH(old_dir), |
| 2997 | .new_dir = NFS_FH(new_dir), |
| 2998 | .old_name = old_name, |
| 2999 | .new_name = new_name, |
| 3000 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3001 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3002 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3003 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | struct rpc_message msg = { |
| 3005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3006 | .rpc_argp = &arg, |
| 3007 | .rpc_resp = &res, |
| 3008 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3009 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3011 | 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] | 3012 | if (!status) { |
| 3013 | update_changeattr(old_dir, &res.old_cinfo); |
| 3014 | update_changeattr(new_dir, &res.new_cinfo); |
| 3015 | } |
| 3016 | return status; |
| 3017 | } |
| 3018 | |
| 3019 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3020 | struct inode *new_dir, struct qstr *new_name) |
| 3021 | { |
| 3022 | struct nfs4_exception exception = { }; |
| 3023 | int err; |
| 3024 | do { |
| 3025 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3026 | _nfs4_proc_rename(old_dir, old_name, |
| 3027 | new_dir, new_name), |
| 3028 | &exception); |
| 3029 | } while (exception.retry); |
| 3030 | return err; |
| 3031 | } |
| 3032 | |
| 3033 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3034 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3035 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | struct nfs4_link_arg arg = { |
| 3037 | .fh = NFS_FH(inode), |
| 3038 | .dir_fh = NFS_FH(dir), |
| 3039 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3040 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3042 | struct nfs4_link_res res = { |
| 3043 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3044 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | struct rpc_message msg = { |
| 3046 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3047 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3048 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3050 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3052 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3053 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3054 | goto out; |
| 3055 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3056 | 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] | 3057 | if (!status) { |
| 3058 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3059 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3060 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3061 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3062 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | return status; |
| 3064 | } |
| 3065 | |
| 3066 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3067 | { |
| 3068 | struct nfs4_exception exception = { }; |
| 3069 | int err; |
| 3070 | do { |
| 3071 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3072 | _nfs4_proc_link(inode, dir, name), |
| 3073 | &exception); |
| 3074 | } while (exception.retry); |
| 3075 | return err; |
| 3076 | } |
| 3077 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3078 | struct nfs4_createdata { |
| 3079 | struct rpc_message msg; |
| 3080 | struct nfs4_create_arg arg; |
| 3081 | struct nfs4_create_res res; |
| 3082 | struct nfs_fh fh; |
| 3083 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3084 | }; |
| 3085 | |
| 3086 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3087 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3088 | { |
| 3089 | struct nfs4_createdata *data; |
| 3090 | |
| 3091 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3092 | if (data != NULL) { |
| 3093 | struct nfs_server *server = NFS_SERVER(dir); |
| 3094 | |
| 3095 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3096 | data->msg.rpc_argp = &data->arg; |
| 3097 | data->msg.rpc_resp = &data->res; |
| 3098 | data->arg.dir_fh = NFS_FH(dir); |
| 3099 | data->arg.server = server; |
| 3100 | data->arg.name = name; |
| 3101 | data->arg.attrs = sattr; |
| 3102 | data->arg.ftype = ftype; |
| 3103 | data->arg.bitmask = server->attr_bitmask; |
| 3104 | data->res.server = server; |
| 3105 | data->res.fh = &data->fh; |
| 3106 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3107 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3108 | } |
| 3109 | return data; |
| 3110 | } |
| 3111 | |
| 3112 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3113 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3114 | 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] | 3115 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3116 | if (status == 0) { |
| 3117 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3118 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3119 | } |
| 3120 | return status; |
| 3121 | } |
| 3122 | |
| 3123 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3124 | { |
| 3125 | kfree(data); |
| 3126 | } |
| 3127 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3128 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3129 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3131 | struct nfs4_createdata *data; |
| 3132 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3134 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3135 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3136 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3137 | status = -ENOMEM; |
| 3138 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3139 | if (data == NULL) |
| 3140 | goto out; |
| 3141 | |
| 3142 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3143 | data->arg.u.symlink.pages = &page; |
| 3144 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3146 | status = nfs4_do_create(dir, dentry, data); |
| 3147 | |
| 3148 | nfs4_free_createdata(data); |
| 3149 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | return status; |
| 3151 | } |
| 3152 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3153 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3154 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | { |
| 3156 | struct nfs4_exception exception = { }; |
| 3157 | int err; |
| 3158 | do { |
| 3159 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3160 | _nfs4_proc_symlink(dir, dentry, page, |
| 3161 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | &exception); |
| 3163 | } while (exception.retry); |
| 3164 | return err; |
| 3165 | } |
| 3166 | |
| 3167 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3168 | struct iattr *sattr) |
| 3169 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3170 | struct nfs4_createdata *data; |
| 3171 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3173 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3174 | if (data == NULL) |
| 3175 | goto out; |
| 3176 | |
| 3177 | status = nfs4_do_create(dir, dentry, data); |
| 3178 | |
| 3179 | nfs4_free_createdata(data); |
| 3180 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | return status; |
| 3182 | } |
| 3183 | |
| 3184 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3185 | struct iattr *sattr) |
| 3186 | { |
| 3187 | struct nfs4_exception exception = { }; |
| 3188 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3189 | |
| 3190 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | do { |
| 3192 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3193 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3194 | &exception); |
| 3195 | } while (exception.retry); |
| 3196 | return err; |
| 3197 | } |
| 3198 | |
| 3199 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3200 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | { |
| 3202 | struct inode *dir = dentry->d_inode; |
| 3203 | struct nfs4_readdir_arg args = { |
| 3204 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3205 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | .pgbase = 0, |
| 3207 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3208 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3209 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | }; |
| 3211 | struct nfs4_readdir_res res; |
| 3212 | struct rpc_message msg = { |
| 3213 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3214 | .rpc_argp = &args, |
| 3215 | .rpc_resp = &res, |
| 3216 | .rpc_cred = cred, |
| 3217 | }; |
| 3218 | int status; |
| 3219 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3220 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3221 | dentry->d_parent->d_name.name, |
| 3222 | dentry->d_name.name, |
| 3223 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3224 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3226 | 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] | 3227 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3228 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3229 | status += args.pgbase; |
| 3230 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3231 | |
| 3232 | nfs_invalidate_atime(dir); |
| 3233 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3234 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | return status; |
| 3236 | } |
| 3237 | |
| 3238 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3239 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | { |
| 3241 | struct nfs4_exception exception = { }; |
| 3242 | int err; |
| 3243 | do { |
| 3244 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3245 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3246 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | &exception); |
| 3248 | } while (exception.retry); |
| 3249 | return err; |
| 3250 | } |
| 3251 | |
| 3252 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3253 | struct iattr *sattr, dev_t rdev) |
| 3254 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3255 | struct nfs4_createdata *data; |
| 3256 | int mode = sattr->ia_mode; |
| 3257 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3259 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3260 | if (data == NULL) |
| 3261 | goto out; |
| 3262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3264 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3266 | data->arg.ftype = NF4BLK; |
| 3267 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3268 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | } |
| 3270 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3271 | data->arg.ftype = NF4CHR; |
| 3272 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3273 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3274 | } else if (!S_ISSOCK(mode)) { |
| 3275 | status = -EINVAL; |
| 3276 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3279 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3280 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3281 | nfs4_free_createdata(data); |
| 3282 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | return status; |
| 3284 | } |
| 3285 | |
| 3286 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3287 | struct iattr *sattr, dev_t rdev) |
| 3288 | { |
| 3289 | struct nfs4_exception exception = { }; |
| 3290 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3291 | |
| 3292 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | do { |
| 3294 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3295 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3296 | &exception); |
| 3297 | } while (exception.retry); |
| 3298 | return err; |
| 3299 | } |
| 3300 | |
| 3301 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3302 | struct nfs_fsstat *fsstat) |
| 3303 | { |
| 3304 | struct nfs4_statfs_arg args = { |
| 3305 | .fh = fhandle, |
| 3306 | .bitmask = server->attr_bitmask, |
| 3307 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3308 | struct nfs4_statfs_res res = { |
| 3309 | .fsstat = fsstat, |
| 3310 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | struct rpc_message msg = { |
| 3312 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3313 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3314 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | }; |
| 3316 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3317 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3318 | 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] | 3319 | } |
| 3320 | |
| 3321 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3322 | { |
| 3323 | struct nfs4_exception exception = { }; |
| 3324 | int err; |
| 3325 | do { |
| 3326 | err = nfs4_handle_exception(server, |
| 3327 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3328 | &exception); |
| 3329 | } while (exception.retry); |
| 3330 | return err; |
| 3331 | } |
| 3332 | |
| 3333 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3334 | struct nfs_fsinfo *fsinfo) |
| 3335 | { |
| 3336 | struct nfs4_fsinfo_arg args = { |
| 3337 | .fh = fhandle, |
| 3338 | .bitmask = server->attr_bitmask, |
| 3339 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3340 | struct nfs4_fsinfo_res res = { |
| 3341 | .fsinfo = fsinfo, |
| 3342 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | struct rpc_message msg = { |
| 3344 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3345 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3346 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | }; |
| 3348 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3349 | 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] | 3350 | } |
| 3351 | |
| 3352 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3353 | { |
| 3354 | struct nfs4_exception exception = { }; |
| 3355 | int err; |
| 3356 | |
| 3357 | do { |
| 3358 | err = nfs4_handle_exception(server, |
| 3359 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3360 | &exception); |
| 3361 | } while (exception.retry); |
| 3362 | return err; |
| 3363 | } |
| 3364 | |
| 3365 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3366 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3367 | int error; |
| 3368 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3369 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3370 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3371 | if (error == 0) { |
| 3372 | /* block layout checks this! */ |
| 3373 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3374 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3375 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3376 | |
| 3377 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3381 | struct nfs_pathconf *pathconf) |
| 3382 | { |
| 3383 | struct nfs4_pathconf_arg args = { |
| 3384 | .fh = fhandle, |
| 3385 | .bitmask = server->attr_bitmask, |
| 3386 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3387 | struct nfs4_pathconf_res res = { |
| 3388 | .pathconf = pathconf, |
| 3389 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | struct rpc_message msg = { |
| 3391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3392 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3393 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | }; |
| 3395 | |
| 3396 | /* None of the pathconf attributes are mandatory to implement */ |
| 3397 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3398 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3399 | return 0; |
| 3400 | } |
| 3401 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3402 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3403 | 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] | 3404 | } |
| 3405 | |
| 3406 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3407 | struct nfs_pathconf *pathconf) |
| 3408 | { |
| 3409 | struct nfs4_exception exception = { }; |
| 3410 | int err; |
| 3411 | |
| 3412 | do { |
| 3413 | err = nfs4_handle_exception(server, |
| 3414 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3415 | &exception); |
| 3416 | } while (exception.retry); |
| 3417 | return err; |
| 3418 | } |
| 3419 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3420 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3421 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3422 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3423 | } |
| 3424 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3425 | 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] | 3426 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3427 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3429 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3430 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3431 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3433 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3434 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3436 | renew_lease(server, data->timestamp); |
| 3437 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3440 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3441 | { |
| 3442 | |
| 3443 | dprintk("--> %s\n", __func__); |
| 3444 | |
| 3445 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3446 | return -EAGAIN; |
| 3447 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3448 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3449 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3450 | } |
| 3451 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3452 | 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] | 3453 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3455 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3456 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3457 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3460 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3461 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3462 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3463 | &data->args.seq_args, |
| 3464 | &data->res.seq_res, |
| 3465 | task)) |
| 3466 | return; |
| 3467 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3470 | 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] | 3471 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3472 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3474 | 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] | 3475 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3476 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3478 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3480 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3481 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3482 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3485 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3486 | { |
| 3487 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3488 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3489 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3490 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3493 | static |
| 3494 | 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] | 3495 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3496 | const struct nfs_pgio_header *hdr = data->header; |
| 3497 | |
| 3498 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3499 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3500 | return false; |
| 3501 | /* Otherwise, request attributes if and only if we don't hold |
| 3502 | * a delegation |
| 3503 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3504 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3505 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3506 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3507 | 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] | 3508 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3509 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3510 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3511 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3512 | data->args.bitmask = NULL; |
| 3513 | data->res.fattr = NULL; |
| 3514 | } else |
| 3515 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3516 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3517 | if (!data->write_done_cb) |
| 3518 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3519 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | data->timestamp = jiffies; |
| 3521 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3522 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3523 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3526 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3527 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3528 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3529 | &data->args.seq_args, |
| 3530 | &data->res.seq_res, |
| 3531 | task)) |
| 3532 | return; |
| 3533 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3536 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3537 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3539 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3540 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | return; |
| 3543 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3544 | } |
| 3545 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3546 | 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] | 3547 | { |
| 3548 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3549 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3550 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3551 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3552 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3554 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3557 | 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] | 3558 | { |
| 3559 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3560 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3561 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3564 | 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] | 3565 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3566 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3567 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3568 | if (data->commit_done_cb == NULL) |
| 3569 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3570 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3571 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3572 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3575 | struct nfs4_renewdata { |
| 3576 | struct nfs_client *client; |
| 3577 | unsigned long timestamp; |
| 3578 | }; |
| 3579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | /* |
| 3581 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3582 | * standalone procedure for queueing an asynchronous RENEW. |
| 3583 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3584 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3585 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3586 | struct nfs4_renewdata *data = calldata; |
| 3587 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3588 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3589 | if (atomic_read(&clp->cl_count) > 1) |
| 3590 | nfs4_schedule_state_renewal(clp); |
| 3591 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3592 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3593 | } |
| 3594 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3595 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3597 | struct nfs4_renewdata *data = calldata; |
| 3598 | struct nfs_client *clp = data->client; |
| 3599 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | |
| 3601 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3602 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3603 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3604 | return; |
| 3605 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3606 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3607 | return; |
| 3608 | } |
| 3609 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3611 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3614 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3615 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3616 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3617 | }; |
| 3618 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3619 | 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] | 3620 | { |
| 3621 | struct rpc_message msg = { |
| 3622 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3623 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3624 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3626 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3628 | if (renew_flags == 0) |
| 3629 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3630 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3631 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3632 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3633 | if (data == NULL) |
| 3634 | return -ENOMEM; |
| 3635 | data->client = clp; |
| 3636 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3638 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3641 | 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] | 3642 | { |
| 3643 | struct rpc_message msg = { |
| 3644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3645 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3646 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | }; |
| 3648 | unsigned long now = jiffies; |
| 3649 | int status; |
| 3650 | |
| 3651 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3652 | if (status < 0) |
| 3653 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3654 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | return 0; |
| 3656 | } |
| 3657 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3658 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3659 | { |
| 3660 | return (server->caps & NFS_CAP_ACLS) |
| 3661 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3662 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3663 | } |
| 3664 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3665 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3666 | * 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] | 3667 | * the stack. |
| 3668 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3669 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3670 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3671 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3672 | struct page **pages, unsigned int *pgbase) |
| 3673 | { |
| 3674 | struct page *newpage, **spages; |
| 3675 | int rc = 0; |
| 3676 | size_t len; |
| 3677 | spages = pages; |
| 3678 | |
| 3679 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3680 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3681 | newpage = alloc_page(GFP_KERNEL); |
| 3682 | |
| 3683 | if (newpage == NULL) |
| 3684 | goto unwind; |
| 3685 | memcpy(page_address(newpage), buf, len); |
| 3686 | buf += len; |
| 3687 | buflen -= len; |
| 3688 | *pages++ = newpage; |
| 3689 | rc++; |
| 3690 | } while (buflen != 0); |
| 3691 | |
| 3692 | return rc; |
| 3693 | |
| 3694 | unwind: |
| 3695 | for(; rc > 0; rc--) |
| 3696 | __free_page(spages[rc-1]); |
| 3697 | return -ENOMEM; |
| 3698 | } |
| 3699 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3700 | struct nfs4_cached_acl { |
| 3701 | int cached; |
| 3702 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3703 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3704 | }; |
| 3705 | |
| 3706 | 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] | 3707 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3708 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3709 | |
| 3710 | spin_lock(&inode->i_lock); |
| 3711 | kfree(nfsi->nfs4_acl); |
| 3712 | nfsi->nfs4_acl = acl; |
| 3713 | spin_unlock(&inode->i_lock); |
| 3714 | } |
| 3715 | |
| 3716 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3717 | { |
| 3718 | nfs4_set_cached_acl(inode, NULL); |
| 3719 | } |
| 3720 | |
| 3721 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3722 | { |
| 3723 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3724 | struct nfs4_cached_acl *acl; |
| 3725 | int ret = -ENOENT; |
| 3726 | |
| 3727 | spin_lock(&inode->i_lock); |
| 3728 | acl = nfsi->nfs4_acl; |
| 3729 | if (acl == NULL) |
| 3730 | goto out; |
| 3731 | if (buf == NULL) /* user is just asking for length */ |
| 3732 | goto out_len; |
| 3733 | if (acl->cached == 0) |
| 3734 | goto out; |
| 3735 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3736 | if (acl->len > buflen) |
| 3737 | goto out; |
| 3738 | memcpy(buf, acl->data, acl->len); |
| 3739 | out_len: |
| 3740 | ret = acl->len; |
| 3741 | out: |
| 3742 | spin_unlock(&inode->i_lock); |
| 3743 | return ret; |
| 3744 | } |
| 3745 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3746 | 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] | 3747 | { |
| 3748 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3749 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3750 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3751 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3752 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3753 | if (acl == NULL) |
| 3754 | goto out; |
| 3755 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3756 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3757 | } else { |
| 3758 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3759 | if (acl == NULL) |
| 3760 | goto out; |
| 3761 | acl->cached = 0; |
| 3762 | } |
| 3763 | acl->len = acl_len; |
| 3764 | out: |
| 3765 | nfs4_set_cached_acl(inode, acl); |
| 3766 | } |
| 3767 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3768 | /* |
| 3769 | * The getxattr API returns the required buffer length when called with a |
| 3770 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3771 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3772 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3773 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3774 | * the cache. If not so, we throw away the page, and cache the required |
| 3775 | * length. The next getxattr call will then produce another round trip to |
| 3776 | * the server, this time with the input buf of the required size. |
| 3777 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3778 | 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] | 3779 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3780 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3781 | struct nfs_getaclargs args = { |
| 3782 | .fh = NFS_FH(inode), |
| 3783 | .acl_pages = pages, |
| 3784 | .acl_len = buflen, |
| 3785 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3786 | struct nfs_getaclres res = { |
| 3787 | .acl_len = buflen, |
| 3788 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3789 | struct rpc_message msg = { |
| 3790 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3791 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3792 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3793 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3794 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3795 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3796 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3797 | /* As long as we're doing a round trip to the server anyway, |
| 3798 | * let's be prepared for a page of acl data. */ |
| 3799 | if (npages == 0) |
| 3800 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3801 | if (npages > ARRAY_SIZE(pages)) |
| 3802 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3803 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3804 | for (i = 0; i < npages; i++) { |
| 3805 | pages[i] = alloc_page(GFP_KERNEL); |
| 3806 | if (!pages[i]) |
| 3807 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3808 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3809 | |
| 3810 | /* for decoding across pages */ |
| 3811 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3812 | if (!res.acl_scratch) |
| 3813 | goto out_free; |
| 3814 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3815 | args.acl_len = npages * PAGE_SIZE; |
| 3816 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3817 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3818 | 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] | 3819 | __func__, buf, buflen, npages, args.acl_len); |
| 3820 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3821 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3822 | if (ret) |
| 3823 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3824 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3825 | /* Handle the case where the passed-in buffer is too short */ |
| 3826 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3827 | /* Did the user only issue a request for the acl length? */ |
| 3828 | if (buf == NULL) |
| 3829 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3830 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3831 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3832 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3833 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3834 | if (buf) |
| 3835 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3836 | out_ok: |
| 3837 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3838 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3839 | for (i = 0; i < npages; i++) |
| 3840 | if (pages[i]) |
| 3841 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3842 | if (res.acl_scratch) |
| 3843 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3844 | return ret; |
| 3845 | } |
| 3846 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3847 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3848 | { |
| 3849 | struct nfs4_exception exception = { }; |
| 3850 | ssize_t ret; |
| 3851 | do { |
| 3852 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3853 | if (ret >= 0) |
| 3854 | break; |
| 3855 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3856 | } while (exception.retry); |
| 3857 | return ret; |
| 3858 | } |
| 3859 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3860 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3861 | { |
| 3862 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3863 | int ret; |
| 3864 | |
| 3865 | if (!nfs4_server_supports_acls(server)) |
| 3866 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3867 | ret = nfs_revalidate_inode(server, inode); |
| 3868 | if (ret < 0) |
| 3869 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3870 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3871 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3872 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3873 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3874 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3875 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3876 | return ret; |
| 3877 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3880 | 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] | 3881 | { |
| 3882 | struct nfs_server *server = NFS_SERVER(inode); |
| 3883 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3884 | struct nfs_setaclargs arg = { |
| 3885 | .fh = NFS_FH(inode), |
| 3886 | .acl_pages = pages, |
| 3887 | .acl_len = buflen, |
| 3888 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3889 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3890 | struct rpc_message msg = { |
| 3891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3892 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3893 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3894 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3895 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3896 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3897 | |
| 3898 | if (!nfs4_server_supports_acls(server)) |
| 3899 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3900 | if (npages > ARRAY_SIZE(pages)) |
| 3901 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3902 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3903 | if (i < 0) |
| 3904 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3905 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3906 | 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] | 3907 | |
| 3908 | /* |
| 3909 | * Free each page after tx, so the only ref left is |
| 3910 | * held by the network stack |
| 3911 | */ |
| 3912 | for (; i > 0; i--) |
| 3913 | put_page(pages[i-1]); |
| 3914 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3915 | /* |
| 3916 | * Acl update can result in inode attribute update. |
| 3917 | * so mark the attribute cache invalid. |
| 3918 | */ |
| 3919 | spin_lock(&inode->i_lock); |
| 3920 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3921 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3922 | nfs_access_zap_cache(inode); |
| 3923 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3924 | return ret; |
| 3925 | } |
| 3926 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3927 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3928 | { |
| 3929 | struct nfs4_exception exception = { }; |
| 3930 | int err; |
| 3931 | do { |
| 3932 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3933 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3934 | &exception); |
| 3935 | } while (exception.retry); |
| 3936 | return err; |
| 3937 | } |
| 3938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3940 | 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] | 3941 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3942 | struct nfs_client *clp = server->nfs_client; |
| 3943 | |
| 3944 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | return 0; |
| 3946 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3947 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3948 | case -NFS4ERR_ADMIN_REVOKED: |
| 3949 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3950 | if (state == NULL) |
| 3951 | break; |
| 3952 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3953 | case -NFS4ERR_OPENMODE: |
| 3954 | if (state == NULL) |
| 3955 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3956 | nfs4_schedule_stateid_recovery(server, state); |
| 3957 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3958 | case -NFS4ERR_EXPIRED: |
| 3959 | if (state != NULL) |
| 3960 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3962 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3963 | nfs4_schedule_lease_recovery(clp); |
| 3964 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3965 | #if defined(CONFIG_NFS_V4_1) |
| 3966 | case -NFS4ERR_BADSESSION: |
| 3967 | case -NFS4ERR_BADSLOT: |
| 3968 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3969 | case -NFS4ERR_DEADSESSION: |
| 3970 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3971 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3972 | case -NFS4ERR_SEQ_MISORDERED: |
| 3973 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3974 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3975 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3976 | task->tk_status = 0; |
| 3977 | return -EAGAIN; |
| 3978 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3980 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3981 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3982 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3984 | task->tk_status = 0; |
| 3985 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3986 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | case -NFS4ERR_OLD_STATEID: |
| 3988 | task->tk_status = 0; |
| 3989 | return -EAGAIN; |
| 3990 | } |
| 3991 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3992 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3993 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3994 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3995 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3996 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3997 | task->tk_status = 0; |
| 3998 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4001 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4002 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4003 | { |
| 4004 | __be32 verf[2]; |
| 4005 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4006 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4007 | /* An impossible timestamp guarantees this value |
| 4008 | * will never match a generated boot time. */ |
| 4009 | verf[0] = 0; |
| 4010 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4011 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4012 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4013 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4014 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4015 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4016 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4017 | } |
| 4018 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4019 | static unsigned int |
| 4020 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4021 | char *buf, size_t len) |
| 4022 | { |
| 4023 | unsigned int result; |
| 4024 | |
| 4025 | rcu_read_lock(); |
| 4026 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4027 | clp->cl_ipaddr, |
| 4028 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4029 | RPC_DISPLAY_ADDR), |
| 4030 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4031 | RPC_DISPLAY_PROTO)); |
| 4032 | rcu_read_unlock(); |
| 4033 | return result; |
| 4034 | } |
| 4035 | |
| 4036 | static unsigned int |
| 4037 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4038 | char *buf, size_t len) |
| 4039 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4040 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4041 | |
| 4042 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4043 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4044 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4045 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4046 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4047 | } |
| 4048 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4049 | /** |
| 4050 | * nfs4_proc_setclientid - Negotiate client ID |
| 4051 | * @clp: state data structure |
| 4052 | * @program: RPC program for NFSv4 callback service |
| 4053 | * @port: IP port number for NFS4 callback service |
| 4054 | * @cred: RPC credential to use for this call |
| 4055 | * @res: where to place the result |
| 4056 | * |
| 4057 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4058 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4059 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4060 | unsigned short port, struct rpc_cred *cred, |
| 4061 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | { |
| 4063 | nfs4_verifier sc_verifier; |
| 4064 | struct nfs4_setclientid setclientid = { |
| 4065 | .sc_verifier = &sc_verifier, |
| 4066 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4067 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | }; |
| 4069 | struct rpc_message msg = { |
| 4070 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4071 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4072 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4073 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4075 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4077 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4078 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4079 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4080 | setclientid.sc_name_len = |
| 4081 | nfs4_init_uniform_client_string(clp, |
| 4082 | setclientid.sc_name, |
| 4083 | sizeof(setclientid.sc_name)); |
| 4084 | else |
| 4085 | setclientid.sc_name_len = |
| 4086 | nfs4_init_nonuniform_client_string(clp, |
| 4087 | setclientid.sc_name, |
| 4088 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4089 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4090 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4091 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4092 | sizeof(setclientid.sc_netid), |
| 4093 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4094 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4095 | rcu_read_unlock(); |
| 4096 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4097 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4099 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4100 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4101 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4102 | setclientid.sc_name_len, setclientid.sc_name); |
| 4103 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4104 | dprintk("NFS reply setclientid: %d\n", status); |
| 4105 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4108 | /** |
| 4109 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4110 | * @clp: state data structure |
| 4111 | * @res: result of a previous SETCLIENTID |
| 4112 | * @cred: RPC credential to use for this call |
| 4113 | * |
| 4114 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4115 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4116 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4117 | struct nfs4_setclientid_res *arg, |
| 4118 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | { |
| 4120 | struct nfs_fsinfo fsinfo; |
| 4121 | struct rpc_message msg = { |
| 4122 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4123 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4125 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | }; |
| 4127 | unsigned long now; |
| 4128 | int status; |
| 4129 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4130 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4131 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4132 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4134 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | if (status == 0) { |
| 4136 | spin_lock(&clp->cl_lock); |
| 4137 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4138 | clp->cl_last_renewal = now; |
| 4139 | spin_unlock(&clp->cl_lock); |
| 4140 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4141 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | return status; |
| 4143 | } |
| 4144 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4145 | struct nfs4_delegreturndata { |
| 4146 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4147 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4148 | struct nfs_fh fh; |
| 4149 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4150 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4151 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4152 | int rpc_status; |
| 4153 | }; |
| 4154 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4155 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4156 | { |
| 4157 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4158 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4159 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4160 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4161 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4162 | switch (task->tk_status) { |
| 4163 | case -NFS4ERR_STALE_STATEID: |
| 4164 | case -NFS4ERR_EXPIRED: |
| 4165 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4166 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4167 | break; |
| 4168 | default: |
| 4169 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4170 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4171 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4172 | return; |
| 4173 | } |
| 4174 | } |
| 4175 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | static void nfs4_delegreturn_release(void *calldata) |
| 4179 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4180 | kfree(calldata); |
| 4181 | } |
| 4182 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4183 | #if defined(CONFIG_NFS_V4_1) |
| 4184 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4185 | { |
| 4186 | struct nfs4_delegreturndata *d_data; |
| 4187 | |
| 4188 | d_data = (struct nfs4_delegreturndata *)data; |
| 4189 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4190 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4191 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4192 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4193 | return; |
| 4194 | rpc_call_start(task); |
| 4195 | } |
| 4196 | #endif /* CONFIG_NFS_V4_1 */ |
| 4197 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4198 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4199 | #if defined(CONFIG_NFS_V4_1) |
| 4200 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4201 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4202 | .rpc_call_done = nfs4_delegreturn_done, |
| 4203 | .rpc_release = nfs4_delegreturn_release, |
| 4204 | }; |
| 4205 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4206 | 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] | 4207 | { |
| 4208 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4209 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4210 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4211 | struct rpc_message msg = { |
| 4212 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4213 | .rpc_cred = cred, |
| 4214 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4215 | struct rpc_task_setup task_setup_data = { |
| 4216 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4217 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4218 | .callback_ops = &nfs4_delegreturn_ops, |
| 4219 | .flags = RPC_TASK_ASYNC, |
| 4220 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4221 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4222 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4223 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4224 | if (data == NULL) |
| 4225 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4226 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4227 | data->args.fhandle = &data->fh; |
| 4228 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4229 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4230 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4231 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4232 | data->res.fattr = &data->fattr; |
| 4233 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4234 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4235 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4236 | data->rpc_status = 0; |
| 4237 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4238 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4239 | msg.rpc_argp = &data->args; |
| 4240 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4241 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4242 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4243 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4244 | if (!issync) |
| 4245 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4246 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4247 | if (status != 0) |
| 4248 | goto out; |
| 4249 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4250 | if (status == 0) |
| 4251 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4252 | else |
| 4253 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4254 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4255 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4256 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4259 | 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] | 4260 | { |
| 4261 | struct nfs_server *server = NFS_SERVER(inode); |
| 4262 | struct nfs4_exception exception = { }; |
| 4263 | int err; |
| 4264 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4265 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | switch (err) { |
| 4267 | case -NFS4ERR_STALE_STATEID: |
| 4268 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | case 0: |
| 4270 | return 0; |
| 4271 | } |
| 4272 | err = nfs4_handle_exception(server, err, &exception); |
| 4273 | } while (exception.retry); |
| 4274 | return err; |
| 4275 | } |
| 4276 | |
| 4277 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4278 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4279 | |
| 4280 | /* |
| 4281 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4282 | */ |
| 4283 | static unsigned long |
| 4284 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4285 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4286 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | timeout <<= 1; |
| 4288 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4289 | return NFS4_LOCK_MAXTIMEOUT; |
| 4290 | return timeout; |
| 4291 | } |
| 4292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4294 | { |
| 4295 | struct inode *inode = state->inode; |
| 4296 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4297 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4298 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4300 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4302 | struct nfs_lockt_res res = { |
| 4303 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | }; |
| 4305 | struct rpc_message msg = { |
| 4306 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4307 | .rpc_argp = &arg, |
| 4308 | .rpc_resp = &res, |
| 4309 | .rpc_cred = state->owner->so_cred, |
| 4310 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | struct nfs4_lock_state *lsp; |
| 4312 | int status; |
| 4313 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4314 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4315 | status = nfs4_set_lock_state(state, request); |
| 4316 | if (status != 0) |
| 4317 | goto out; |
| 4318 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4319 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4320 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4321 | 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] | 4322 | switch (status) { |
| 4323 | case 0: |
| 4324 | request->fl_type = F_UNLCK; |
| 4325 | break; |
| 4326 | case -NFS4ERR_DENIED: |
| 4327 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4329 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4330 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | return status; |
| 4332 | } |
| 4333 | |
| 4334 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4335 | { |
| 4336 | struct nfs4_exception exception = { }; |
| 4337 | int err; |
| 4338 | |
| 4339 | do { |
| 4340 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4341 | _nfs4_proc_getlk(state, cmd, request), |
| 4342 | &exception); |
| 4343 | } while (exception.retry); |
| 4344 | return err; |
| 4345 | } |
| 4346 | |
| 4347 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4348 | { |
| 4349 | int res = 0; |
| 4350 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4351 | case FL_POSIX: |
| 4352 | res = posix_lock_file_wait(file, fl); |
| 4353 | break; |
| 4354 | case FL_FLOCK: |
| 4355 | res = flock_lock_file_wait(file, fl); |
| 4356 | break; |
| 4357 | default: |
| 4358 | BUG(); |
| 4359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | return res; |
| 4361 | } |
| 4362 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4363 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4364 | struct nfs_locku_args arg; |
| 4365 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4366 | struct nfs4_lock_state *lsp; |
| 4367 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4368 | struct file_lock fl; |
| 4369 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4370 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4371 | }; |
| 4372 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4373 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4374 | struct nfs_open_context *ctx, |
| 4375 | struct nfs4_lock_state *lsp, |
| 4376 | struct nfs_seqid *seqid) |
| 4377 | { |
| 4378 | struct nfs4_unlockdata *p; |
| 4379 | struct inode *inode = lsp->ls_state->inode; |
| 4380 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4381 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4382 | if (p == NULL) |
| 4383 | return NULL; |
| 4384 | p->arg.fh = NFS_FH(inode); |
| 4385 | p->arg.fl = &p->fl; |
| 4386 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4387 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4388 | p->arg.stateid = &lsp->ls_stateid; |
| 4389 | p->lsp = lsp; |
| 4390 | atomic_inc(&lsp->ls_count); |
| 4391 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4392 | p->ctx = get_nfs_open_context(ctx); |
| 4393 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4394 | p->server = NFS_SERVER(inode); |
| 4395 | return p; |
| 4396 | } |
| 4397 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4398 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4399 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4400 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4401 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4402 | nfs4_put_lock_state(calldata->lsp); |
| 4403 | put_nfs_open_context(calldata->ctx); |
| 4404 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4407 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4408 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4409 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4410 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4411 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4412 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4413 | switch (task->tk_status) { |
| 4414 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4415 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4416 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4417 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4418 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4419 | case -NFS4ERR_BAD_STATEID: |
| 4420 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4421 | case -NFS4ERR_STALE_STATEID: |
| 4422 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4423 | break; |
| 4424 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4425 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4426 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4427 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4428 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4431 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4432 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4433 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4435 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4436 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4437 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4438 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4439 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4440 | return; |
| 4441 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4442 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4443 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4444 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4445 | &calldata->res.seq_res, |
| 4446 | task) != 0) |
| 4447 | nfs_release_seqid(calldata->arg.seqid); |
| 4448 | else |
| 4449 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | } |
| 4451 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4452 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4453 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4454 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4455 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4456 | }; |
| 4457 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4458 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4459 | struct nfs_open_context *ctx, |
| 4460 | struct nfs4_lock_state *lsp, |
| 4461 | struct nfs_seqid *seqid) |
| 4462 | { |
| 4463 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4464 | struct rpc_message msg = { |
| 4465 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4466 | .rpc_cred = ctx->cred, |
| 4467 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4468 | struct rpc_task_setup task_setup_data = { |
| 4469 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4470 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4471 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4472 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4473 | .flags = RPC_TASK_ASYNC, |
| 4474 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4475 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4476 | /* Ensure this is an unlock - when canceling a lock, the |
| 4477 | * canceled lock is passed in, and it won't be an unlock. |
| 4478 | */ |
| 4479 | fl->fl_type = F_UNLCK; |
| 4480 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4481 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4482 | if (data == NULL) { |
| 4483 | nfs_free_seqid(seqid); |
| 4484 | return ERR_PTR(-ENOMEM); |
| 4485 | } |
| 4486 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4487 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4488 | msg.rpc_argp = &data->arg; |
| 4489 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4490 | task_setup_data.callback_data = data; |
| 4491 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4492 | } |
| 4493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4495 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4496 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4497 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4498 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4499 | struct rpc_task *task; |
| 4500 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4501 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4503 | status = nfs4_set_lock_state(state, request); |
| 4504 | /* Unlock _before_ we do the RPC call */ |
| 4505 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4506 | down_read(&nfsi->rwsem); |
| 4507 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4508 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4509 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4510 | } |
| 4511 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4512 | if (status != 0) |
| 4513 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4514 | /* Is this a delegated lock? */ |
| 4515 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4516 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4517 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4518 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4519 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4520 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4521 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4522 | 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] | 4523 | status = PTR_ERR(task); |
| 4524 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4525 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4526 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4527 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4528 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4529 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4530 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4533 | struct nfs4_lockdata { |
| 4534 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4535 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4536 | struct nfs4_lock_state *lsp; |
| 4537 | struct nfs_open_context *ctx; |
| 4538 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4539 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4540 | int rpc_status; |
| 4541 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4542 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4543 | }; |
| 4544 | |
| 4545 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4546 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4547 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4548 | { |
| 4549 | struct nfs4_lockdata *p; |
| 4550 | struct inode *inode = lsp->ls_state->inode; |
| 4551 | struct nfs_server *server = NFS_SERVER(inode); |
| 4552 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4553 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4554 | if (p == NULL) |
| 4555 | return NULL; |
| 4556 | |
| 4557 | p->arg.fh = NFS_FH(inode); |
| 4558 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4559 | 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] | 4560 | if (p->arg.open_seqid == NULL) |
| 4561 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4562 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4563 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4564 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4565 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4566 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4567 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4568 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4569 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4570 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4571 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4572 | atomic_inc(&lsp->ls_count); |
| 4573 | p->ctx = get_nfs_open_context(ctx); |
| 4574 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4575 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4576 | out_free_seqid: |
| 4577 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4578 | out_free: |
| 4579 | kfree(p); |
| 4580 | return NULL; |
| 4581 | } |
| 4582 | |
| 4583 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4584 | { |
| 4585 | struct nfs4_lockdata *data = calldata; |
| 4586 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4588 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4589 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4590 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4591 | /* Do we need to do an open_to_lock_owner? */ |
| 4592 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4593 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4594 | goto out_release_lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4595 | data->arg.open_stateid = &state->stateid; |
| 4596 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4597 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4598 | } else |
| 4599 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4600 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4601 | if (nfs4_setup_sequence(data->server, |
| 4602 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4603 | &data->res.seq_res, |
| 4604 | task) == 0) { |
| 4605 | rpc_call_start(task); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4606 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4607 | } |
| 4608 | nfs_release_seqid(data->arg.open_seqid); |
| 4609 | out_release_lock_seqid: |
| 4610 | nfs_release_seqid(data->arg.lock_seqid); |
| 4611 | dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4612 | } |
| 4613 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4614 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4615 | { |
| 4616 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4617 | nfs4_lock_prepare(task, calldata); |
| 4618 | } |
| 4619 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4620 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4621 | { |
| 4622 | struct nfs4_lockdata *data = calldata; |
| 4623 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4624 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4625 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4626 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4627 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4628 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4629 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4630 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4631 | if (data->rpc_status == 0) |
| 4632 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4633 | else |
| 4634 | goto out; |
| 4635 | } |
| 4636 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4637 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4638 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4639 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4640 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4641 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4642 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | static void nfs4_lock_release(void *calldata) |
| 4646 | { |
| 4647 | struct nfs4_lockdata *data = calldata; |
| 4648 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4649 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4650 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4651 | if (data->cancelled != 0) { |
| 4652 | struct rpc_task *task; |
| 4653 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4654 | data->arg.lock_seqid); |
| 4655 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4656 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4657 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4658 | } else |
| 4659 | nfs_free_seqid(data->arg.lock_seqid); |
| 4660 | nfs4_put_lock_state(data->lsp); |
| 4661 | put_nfs_open_context(data->ctx); |
| 4662 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4663 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4667 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4668 | .rpc_call_done = nfs4_lock_done, |
| 4669 | .rpc_release = nfs4_lock_release, |
| 4670 | }; |
| 4671 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4672 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4673 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4674 | .rpc_call_done = nfs4_lock_done, |
| 4675 | .rpc_release = nfs4_lock_release, |
| 4676 | }; |
| 4677 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4678 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4679 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4680 | switch (error) { |
| 4681 | case -NFS4ERR_ADMIN_REVOKED: |
| 4682 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4683 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4684 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4685 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4686 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4687 | break; |
| 4688 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4689 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4690 | case -NFS4ERR_EXPIRED: |
| 4691 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4692 | }; |
| 4693 | } |
| 4694 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4695 | 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] | 4696 | { |
| 4697 | struct nfs4_lockdata *data; |
| 4698 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4699 | struct rpc_message msg = { |
| 4700 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4701 | .rpc_cred = state->owner->so_cred, |
| 4702 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4703 | struct rpc_task_setup task_setup_data = { |
| 4704 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4705 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4706 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4707 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4708 | .flags = RPC_TASK_ASYNC, |
| 4709 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4710 | int ret; |
| 4711 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4712 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4713 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4714 | fl->fl_u.nfs4_fl.owner, |
| 4715 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4716 | if (data == NULL) |
| 4717 | return -ENOMEM; |
| 4718 | if (IS_SETLKW(cmd)) |
| 4719 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4720 | if (recovery_type > NFS_LOCK_NEW) { |
| 4721 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4722 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4723 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4724 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4725 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4726 | msg.rpc_argp = &data->arg; |
| 4727 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4728 | task_setup_data.callback_data = data; |
| 4729 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4730 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4731 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4732 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4733 | if (ret == 0) { |
| 4734 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4735 | if (ret) |
| 4736 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4737 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4738 | } else |
| 4739 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4740 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4741 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4742 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4746 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4747 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4748 | struct nfs4_exception exception = { |
| 4749 | .inode = state->inode, |
| 4750 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4751 | int err; |
| 4752 | |
| 4753 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4754 | /* Cache the lock if possible... */ |
| 4755 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4756 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4757 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4758 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4759 | break; |
| 4760 | nfs4_handle_exception(server, err, &exception); |
| 4761 | } while (exception.retry); |
| 4762 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4766 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4767 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4768 | struct nfs4_exception exception = { |
| 4769 | .inode = state->inode, |
| 4770 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4771 | int err; |
| 4772 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4773 | err = nfs4_set_lock_state(state, request); |
| 4774 | if (err != 0) |
| 4775 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4776 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4777 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4778 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4779 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4780 | switch (err) { |
| 4781 | default: |
| 4782 | goto out; |
| 4783 | case -NFS4ERR_GRACE: |
| 4784 | case -NFS4ERR_DELAY: |
| 4785 | nfs4_handle_exception(server, err, &exception); |
| 4786 | err = 0; |
| 4787 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4788 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4789 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4790 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4793 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4794 | /** |
| 4795 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4796 | * |
| 4797 | * @state: NFSv4 state for an inode |
| 4798 | * |
| 4799 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4800 | * Otherwise a negative NFS4ERR value is returned. |
| 4801 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4802 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4803 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4804 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4805 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4806 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4807 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4808 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4809 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4810 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4811 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4812 | /* Free the stateid unless the server |
| 4813 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4814 | if (status != -NFS4ERR_BAD_STATEID) |
| 4815 | nfs41_free_stateid(server, |
| 4816 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4817 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4818 | ret = status; |
| 4819 | } |
| 4820 | } |
| 4821 | }; |
| 4822 | |
| 4823 | return ret; |
| 4824 | } |
| 4825 | |
| 4826 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4827 | { |
| 4828 | int status = NFS_OK; |
| 4829 | |
| 4830 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4831 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4832 | if (status != NFS_OK) |
| 4833 | status = nfs4_lock_expired(state, request); |
| 4834 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4835 | } |
| 4836 | #endif |
| 4837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4839 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4840 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4841 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4842 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4844 | if ((fl_flags & FL_POSIX) && |
| 4845 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4846 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4847 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4848 | status = nfs4_set_lock_state(state, request); |
| 4849 | if (status != 0) |
| 4850 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4851 | request->fl_flags |= FL_ACCESS; |
| 4852 | status = do_vfs_lock(request->fl_file, request); |
| 4853 | if (status < 0) |
| 4854 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4855 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4856 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4857 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4858 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4859 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4860 | status = do_vfs_lock(request->fl_file, request); |
| 4861 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4862 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4863 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4864 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4865 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4866 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4867 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4868 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4869 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4870 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4871 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4872 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4873 | out: |
| 4874 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | return status; |
| 4876 | } |
| 4877 | |
| 4878 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4879 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4880 | struct nfs4_exception exception = { |
| 4881 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4882 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4883 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | int err; |
| 4885 | |
| 4886 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4887 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4888 | if (err == -NFS4ERR_DENIED) |
| 4889 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4891 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | } while (exception.retry); |
| 4893 | return err; |
| 4894 | } |
| 4895 | |
| 4896 | static int |
| 4897 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4898 | { |
| 4899 | struct nfs_open_context *ctx; |
| 4900 | struct nfs4_state *state; |
| 4901 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4902 | int status; |
| 4903 | |
| 4904 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4905 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | state = ctx->state; |
| 4907 | |
| 4908 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4909 | return -EINVAL; |
| 4910 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4911 | if (IS_GETLK(cmd)) { |
| 4912 | if (state != NULL) |
| 4913 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4914 | return 0; |
| 4915 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | |
| 4917 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4918 | return -EINVAL; |
| 4919 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4920 | if (request->fl_type == F_UNLCK) { |
| 4921 | if (state != NULL) |
| 4922 | return nfs4_proc_unlck(state, cmd, request); |
| 4923 | return 0; |
| 4924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4926 | if (state == NULL) |
| 4927 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4928 | /* |
| 4929 | * Don't rely on the VFS having checked the file open mode, |
| 4930 | * since it won't do this for flock() locks. |
| 4931 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4932 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4933 | case F_RDLCK: |
| 4934 | if (!(filp->f_mode & FMODE_READ)) |
| 4935 | return -EBADF; |
| 4936 | break; |
| 4937 | case F_WRLCK: |
| 4938 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4939 | return -EBADF; |
| 4940 | } |
| 4941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | do { |
| 4943 | status = nfs4_proc_setlk(state, cmd, request); |
| 4944 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4945 | break; |
| 4946 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4947 | status = -ERESTARTSYS; |
| 4948 | if (signalled()) |
| 4949 | break; |
| 4950 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | return status; |
| 4952 | } |
| 4953 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4954 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4955 | { |
| 4956 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4957 | struct nfs4_exception exception = { }; |
| 4958 | int err; |
| 4959 | |
| 4960 | err = nfs4_set_lock_state(state, fl); |
| 4961 | if (err != 0) |
| 4962 | goto out; |
| 4963 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4964 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4965 | switch (err) { |
| 4966 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4967 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4968 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4969 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4970 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4971 | goto out; |
| 4972 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4973 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4974 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4975 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4976 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4977 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4978 | case -NFS4ERR_BADSESSION: |
| 4979 | case -NFS4ERR_BADSLOT: |
| 4980 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4981 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4982 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4983 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4984 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4985 | case -ERESTARTSYS: |
| 4986 | /* |
| 4987 | * The show must go on: exit, but mark the |
| 4988 | * stateid as needing recovery. |
| 4989 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4990 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4991 | case -NFS4ERR_ADMIN_REVOKED: |
| 4992 | case -NFS4ERR_BAD_STATEID: |
| 4993 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4994 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4995 | err = 0; |
| 4996 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4997 | case -EKEYEXPIRED: |
| 4998 | /* |
| 4999 | * User RPCSEC_GSS context has expired. |
| 5000 | * We cannot recover this stateid now, so |
| 5001 | * skip it and allow recovery thread to |
| 5002 | * proceed. |
| 5003 | */ |
| 5004 | err = 0; |
| 5005 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5006 | case -ENOMEM: |
| 5007 | case -NFS4ERR_DENIED: |
| 5008 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5009 | err = 0; |
| 5010 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5011 | case -NFS4ERR_DELAY: |
| 5012 | break; |
| 5013 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5014 | err = nfs4_handle_exception(server, err, &exception); |
| 5015 | } while (exception.retry); |
| 5016 | out: |
| 5017 | return err; |
| 5018 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5019 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5020 | struct nfs_release_lockowner_data { |
| 5021 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5022 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5023 | struct nfs_release_lockowner_args args; |
| 5024 | }; |
| 5025 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5026 | static void nfs4_release_lockowner_release(void *calldata) |
| 5027 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5028 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5029 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5030 | kfree(calldata); |
| 5031 | } |
| 5032 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5033 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5034 | .rpc_release = nfs4_release_lockowner_release, |
| 5035 | }; |
| 5036 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5037 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5038 | { |
| 5039 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5040 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5041 | struct rpc_message msg = { |
| 5042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5043 | }; |
| 5044 | |
| 5045 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5046 | return -EINVAL; |
| 5047 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5048 | if (!data) |
| 5049 | return -ENOMEM; |
| 5050 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5051 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5052 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5053 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5054 | data->args.lock_owner.s_dev = server->s_dev; |
| 5055 | msg.rpc_argp = &data->args; |
| 5056 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5057 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5058 | } |
| 5059 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5060 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5061 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5062 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5063 | const void *buf, size_t buflen, |
| 5064 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5065 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5066 | if (strcmp(key, "") != 0) |
| 5067 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5068 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5069 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5070 | } |
| 5071 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5072 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5073 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5074 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5075 | if (strcmp(key, "") != 0) |
| 5076 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5077 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5078 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5081 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5082 | size_t list_len, const char *name, |
| 5083 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5084 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5085 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5086 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5087 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5088 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5089 | |
| 5090 | if (list && len <= list_len) |
| 5091 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5092 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5093 | } |
| 5094 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5095 | /* |
| 5096 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5097 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5098 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5099 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5100 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5101 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5102 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5103 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5104 | return; |
| 5105 | |
| 5106 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5107 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5108 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5109 | fattr->nlink = 2; |
| 5110 | } |
| 5111 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5112 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5113 | const struct qstr *name, |
| 5114 | struct nfs4_fs_locations *fs_locations, |
| 5115 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5116 | { |
| 5117 | struct nfs_server *server = NFS_SERVER(dir); |
| 5118 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5119 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5120 | }; |
| 5121 | struct nfs4_fs_locations_arg args = { |
| 5122 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5123 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5124 | .page = page, |
| 5125 | .bitmask = bitmask, |
| 5126 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5127 | struct nfs4_fs_locations_res res = { |
| 5128 | .fs_locations = fs_locations, |
| 5129 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5130 | struct rpc_message msg = { |
| 5131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5132 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5133 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5134 | }; |
| 5135 | int status; |
| 5136 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5137 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5138 | |
| 5139 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5140 | * is not supported */ |
| 5141 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5142 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5143 | else |
| 5144 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5145 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5146 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5147 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5148 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5149 | 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] | 5150 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5151 | return status; |
| 5152 | } |
| 5153 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5154 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5155 | const struct qstr *name, |
| 5156 | struct nfs4_fs_locations *fs_locations, |
| 5157 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5158 | { |
| 5159 | struct nfs4_exception exception = { }; |
| 5160 | int err; |
| 5161 | do { |
| 5162 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5163 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5164 | &exception); |
| 5165 | } while (exception.retry); |
| 5166 | return err; |
| 5167 | } |
| 5168 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5169 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5170 | { |
| 5171 | int status; |
| 5172 | struct nfs4_secinfo_arg args = { |
| 5173 | .dir_fh = NFS_FH(dir), |
| 5174 | .name = name, |
| 5175 | }; |
| 5176 | struct nfs4_secinfo_res res = { |
| 5177 | .flavors = flavors, |
| 5178 | }; |
| 5179 | struct rpc_message msg = { |
| 5180 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5181 | .rpc_argp = &args, |
| 5182 | .rpc_resp = &res, |
| 5183 | }; |
| 5184 | |
| 5185 | dprintk("NFS call secinfo %s\n", name->name); |
| 5186 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5187 | dprintk("NFS reply secinfo: %d\n", status); |
| 5188 | return status; |
| 5189 | } |
| 5190 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5191 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5192 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5193 | { |
| 5194 | struct nfs4_exception exception = { }; |
| 5195 | int err; |
| 5196 | do { |
| 5197 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5198 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5199 | &exception); |
| 5200 | } while (exception.retry); |
| 5201 | return err; |
| 5202 | } |
| 5203 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5204 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5205 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5206 | * Check the exchange flags returned by the server for invalid flags, having |
| 5207 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5208 | * DS flags set. |
| 5209 | */ |
| 5210 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5211 | { |
| 5212 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5213 | goto out_inval; |
| 5214 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5215 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5216 | goto out_inval; |
| 5217 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5218 | goto out_inval; |
| 5219 | return NFS_OK; |
| 5220 | out_inval: |
| 5221 | return -NFS4ERR_INVAL; |
| 5222 | } |
| 5223 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5224 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5225 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5226 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5227 | { |
| 5228 | if (a->server_scope_sz == b->server_scope_sz && |
| 5229 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5230 | return true; |
| 5231 | |
| 5232 | return false; |
| 5233 | } |
| 5234 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5235 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5236 | * nfs4_proc_bind_conn_to_session() |
| 5237 | * |
| 5238 | * The 4.1 client currently uses the same TCP connection for the |
| 5239 | * fore and backchannel. |
| 5240 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5241 | 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] | 5242 | { |
| 5243 | int status; |
| 5244 | struct nfs41_bind_conn_to_session_res res; |
| 5245 | struct rpc_message msg = { |
| 5246 | .rpc_proc = |
| 5247 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5248 | .rpc_argp = clp, |
| 5249 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5250 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5251 | }; |
| 5252 | |
| 5253 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5254 | |
| 5255 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5256 | if (unlikely(res.session == NULL)) { |
| 5257 | status = -ENOMEM; |
| 5258 | goto out; |
| 5259 | } |
| 5260 | |
| 5261 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5262 | if (status == 0) { |
| 5263 | if (memcmp(res.session->sess_id.data, |
| 5264 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5265 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5266 | status = -EIO; |
| 5267 | goto out_session; |
| 5268 | } |
| 5269 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5270 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5271 | __func__); |
| 5272 | status = -EIO; |
| 5273 | goto out_session; |
| 5274 | } |
| 5275 | if (res.use_conn_in_rdma_mode) { |
| 5276 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5277 | __func__); |
| 5278 | status = -EIO; |
| 5279 | goto out_session; |
| 5280 | } |
| 5281 | } |
| 5282 | out_session: |
| 5283 | kfree(res.session); |
| 5284 | out: |
| 5285 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5286 | return status; |
| 5287 | } |
| 5288 | |
| 5289 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5290 | * nfs4_proc_exchange_id() |
| 5291 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5292 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5293 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5294 | * Since the clientid has expired, all compounds using sessions |
| 5295 | * associated with the stale clientid will be returning |
| 5296 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5297 | * be in some phase of session reset. |
| 5298 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5299 | 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] | 5300 | { |
| 5301 | nfs4_verifier verifier; |
| 5302 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5303 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5304 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5305 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5306 | }; |
| 5307 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5308 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5309 | }; |
| 5310 | int status; |
| 5311 | struct rpc_message msg = { |
| 5312 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5313 | .rpc_argp = &args, |
| 5314 | .rpc_resp = &res, |
| 5315 | .rpc_cred = cred, |
| 5316 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5317 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5318 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5319 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5320 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5321 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5322 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5323 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5324 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5325 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5326 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5327 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5328 | status = -ENOMEM; |
| 5329 | goto out; |
| 5330 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5331 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5332 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5333 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5334 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5335 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5336 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5337 | } |
| 5338 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5339 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5340 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5341 | status = -ENOMEM; |
| 5342 | goto out_server_scope; |
| 5343 | } |
| 5344 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5345 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5346 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5347 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5348 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5349 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5350 | clp->cl_clientid = res.clientid; |
| 5351 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5352 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5353 | clp->cl_seqid = res.seqid; |
| 5354 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5355 | kfree(clp->cl_serverowner); |
| 5356 | clp->cl_serverowner = res.server_owner; |
| 5357 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5358 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5359 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5360 | kfree(clp->cl_implid); |
| 5361 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5362 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5363 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5364 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5365 | res.server_scope)) { |
| 5366 | dprintk("%s: server_scope mismatch detected\n", |
| 5367 | __func__); |
| 5368 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5369 | kfree(clp->cl_serverscope); |
| 5370 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5371 | } |
| 5372 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5373 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5374 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5375 | goto out; |
| 5376 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5377 | } else |
| 5378 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5379 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5380 | out_server_owner: |
| 5381 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5382 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5383 | kfree(res.server_scope); |
| 5384 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5385 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5386 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5387 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5388 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5389 | clp->cl_implid->date.seconds, |
| 5390 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5391 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5392 | return status; |
| 5393 | } |
| 5394 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5395 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5396 | struct rpc_cred *cred) |
| 5397 | { |
| 5398 | struct rpc_message msg = { |
| 5399 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5400 | .rpc_argp = clp, |
| 5401 | .rpc_cred = cred, |
| 5402 | }; |
| 5403 | int status; |
| 5404 | |
| 5405 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5406 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5407 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5408 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5409 | return status; |
| 5410 | } |
| 5411 | |
| 5412 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5413 | struct rpc_cred *cred) |
| 5414 | { |
| 5415 | unsigned int loop; |
| 5416 | int ret; |
| 5417 | |
| 5418 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5419 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5420 | switch (ret) { |
| 5421 | case -NFS4ERR_DELAY: |
| 5422 | case -NFS4ERR_CLIENTID_BUSY: |
| 5423 | ssleep(1); |
| 5424 | break; |
| 5425 | default: |
| 5426 | return ret; |
| 5427 | } |
| 5428 | } |
| 5429 | return 0; |
| 5430 | } |
| 5431 | |
| 5432 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5433 | { |
| 5434 | struct rpc_cred *cred; |
| 5435 | int ret = 0; |
| 5436 | |
| 5437 | if (clp->cl_mvops->minor_version < 1) |
| 5438 | goto out; |
| 5439 | if (clp->cl_exchange_flags == 0) |
| 5440 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5441 | if (clp->cl_preserve_clid) |
| 5442 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5443 | cred = nfs4_get_exchange_id_cred(clp); |
| 5444 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5445 | if (cred) |
| 5446 | put_rpccred(cred); |
| 5447 | switch (ret) { |
| 5448 | case 0: |
| 5449 | case -NFS4ERR_STALE_CLIENTID: |
| 5450 | clp->cl_exchange_flags = 0; |
| 5451 | } |
| 5452 | out: |
| 5453 | return ret; |
| 5454 | } |
| 5455 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5456 | struct nfs4_get_lease_time_data { |
| 5457 | struct nfs4_get_lease_time_args *args; |
| 5458 | struct nfs4_get_lease_time_res *res; |
| 5459 | struct nfs_client *clp; |
| 5460 | }; |
| 5461 | |
| 5462 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5463 | void *calldata) |
| 5464 | { |
| 5465 | int ret; |
| 5466 | struct nfs4_get_lease_time_data *data = |
| 5467 | (struct nfs4_get_lease_time_data *)calldata; |
| 5468 | |
| 5469 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5470 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5471 | /* just setup sequence, do not trigger session recovery |
| 5472 | since we're invoked within one */ |
| 5473 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5474 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5475 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5476 | |
Trond Myklebust | d3edcf9 | 2012-10-15 13:14:43 -0400 | [diff] [blame] | 5477 | if (ret != -EAGAIN) |
| 5478 | rpc_call_start(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5479 | dprintk("<-- %s\n", __func__); |
| 5480 | } |
| 5481 | |
| 5482 | /* |
| 5483 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5484 | * from sequence operation or clientid errors. |
| 5485 | */ |
| 5486 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5487 | { |
| 5488 | struct nfs4_get_lease_time_data *data = |
| 5489 | (struct nfs4_get_lease_time_data *)calldata; |
| 5490 | |
| 5491 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5492 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5493 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5494 | switch (task->tk_status) { |
| 5495 | case -NFS4ERR_DELAY: |
| 5496 | case -NFS4ERR_GRACE: |
| 5497 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5498 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5499 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5500 | /* fall through */ |
| 5501 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5502 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5503 | return; |
| 5504 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5505 | dprintk("<-- %s\n", __func__); |
| 5506 | } |
| 5507 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5508 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5509 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5510 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5511 | }; |
| 5512 | |
| 5513 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5514 | { |
| 5515 | struct rpc_task *task; |
| 5516 | struct nfs4_get_lease_time_args args; |
| 5517 | struct nfs4_get_lease_time_res res = { |
| 5518 | .lr_fsinfo = fsinfo, |
| 5519 | }; |
| 5520 | struct nfs4_get_lease_time_data data = { |
| 5521 | .args = &args, |
| 5522 | .res = &res, |
| 5523 | .clp = clp, |
| 5524 | }; |
| 5525 | struct rpc_message msg = { |
| 5526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5527 | .rpc_argp = &args, |
| 5528 | .rpc_resp = &res, |
| 5529 | }; |
| 5530 | struct rpc_task_setup task_setup = { |
| 5531 | .rpc_client = clp->cl_rpcclient, |
| 5532 | .rpc_message = &msg, |
| 5533 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5534 | .callback_data = &data, |
| 5535 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5536 | }; |
| 5537 | int status; |
| 5538 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5539 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5540 | dprintk("--> %s\n", __func__); |
| 5541 | task = rpc_run_task(&task_setup); |
| 5542 | |
| 5543 | if (IS_ERR(task)) |
| 5544 | status = PTR_ERR(task); |
| 5545 | else { |
| 5546 | status = task->tk_status; |
| 5547 | rpc_put_task(task); |
| 5548 | } |
| 5549 | dprintk("<-- %s return %d\n", __func__, status); |
| 5550 | |
| 5551 | return status; |
| 5552 | } |
| 5553 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5554 | /* |
| 5555 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5556 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5557 | * use them. |
| 5558 | * |
| 5559 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5560 | * always set csa_cachethis to FALSE because the current implementation |
| 5561 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5562 | */ |
| 5563 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5564 | { |
| 5565 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5566 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5567 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5568 | |
| 5569 | if (mxrqst_sz == 0) |
| 5570 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5571 | if (mxresp_sz == 0) |
| 5572 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5573 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5574 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5575 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5576 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5577 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5578 | |
| 5579 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5580 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5581 | __func__, |
| 5582 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5583 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5584 | |
| 5585 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5586 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5587 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5588 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5589 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5590 | args->bc_attrs.max_reqs = 1; |
| 5591 | |
| 5592 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5593 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5594 | __func__, |
| 5595 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5596 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5597 | args->bc_attrs.max_reqs); |
| 5598 | } |
| 5599 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5600 | 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] | 5601 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5602 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5603 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5604 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5605 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5606 | return -EINVAL; |
| 5607 | /* |
| 5608 | * Our requested max_ops is the minimum we need; we're not |
| 5609 | * prepared to break up compounds into smaller pieces than that. |
| 5610 | * So, no point even trying to continue if the server won't |
| 5611 | * cooperate: |
| 5612 | */ |
| 5613 | if (rcvd->max_ops < sent->max_ops) |
| 5614 | return -EINVAL; |
| 5615 | if (rcvd->max_reqs == 0) |
| 5616 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5617 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5618 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5619 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5620 | } |
| 5621 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5622 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5623 | { |
| 5624 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5625 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5626 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5627 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5628 | return -EINVAL; |
| 5629 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5630 | return -EINVAL; |
| 5631 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5632 | return -EINVAL; |
| 5633 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5634 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5635 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5636 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5637 | return -EINVAL; |
| 5638 | return 0; |
| 5639 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5640 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5641 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5642 | struct nfs4_session *session) |
| 5643 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5644 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5645 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5646 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5647 | if (ret) |
| 5648 | return ret; |
| 5649 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5650 | } |
| 5651 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5652 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5653 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5654 | { |
| 5655 | struct nfs4_session *session = clp->cl_session; |
| 5656 | struct nfs41_create_session_args args = { |
| 5657 | .client = clp, |
| 5658 | .cb_program = NFS4_CALLBACK, |
| 5659 | }; |
| 5660 | struct nfs41_create_session_res res = { |
| 5661 | .client = clp, |
| 5662 | }; |
| 5663 | struct rpc_message msg = { |
| 5664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5665 | .rpc_argp = &args, |
| 5666 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5667 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5668 | }; |
| 5669 | int status; |
| 5670 | |
| 5671 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5672 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5673 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5674 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5675 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5676 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5677 | /* Verify the session's negotiated channel_attrs values */ |
| 5678 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5679 | /* Increment the clientid slot sequence id */ |
| 5680 | clp->cl_seqid++; |
| 5681 | } |
| 5682 | |
| 5683 | return status; |
| 5684 | } |
| 5685 | |
| 5686 | /* |
| 5687 | * Issues a CREATE_SESSION operation to the server. |
| 5688 | * It is the responsibility of the caller to verify the session is |
| 5689 | * expired before calling this routine. |
| 5690 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5691 | 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] | 5692 | { |
| 5693 | int status; |
| 5694 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5695 | struct nfs4_session *session = clp->cl_session; |
| 5696 | |
| 5697 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5698 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5699 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5700 | if (status) |
| 5701 | goto out; |
| 5702 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5703 | /* Init or reset the session slot tables */ |
| 5704 | status = nfs4_setup_session_slot_tables(session); |
| 5705 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5706 | if (status) |
| 5707 | goto out; |
| 5708 | |
| 5709 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5710 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5711 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5712 | out: |
| 5713 | dprintk("<-- %s\n", __func__); |
| 5714 | return status; |
| 5715 | } |
| 5716 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5717 | /* |
| 5718 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5719 | * The caller must serialize access to this routine. |
| 5720 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5721 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5722 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5723 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5724 | struct rpc_message msg = { |
| 5725 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5726 | .rpc_argp = session, |
| 5727 | .rpc_cred = cred, |
| 5728 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5729 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5730 | |
| 5731 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5732 | |
| 5733 | /* session is still being setup */ |
| 5734 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5735 | return status; |
| 5736 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5737 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5738 | |
| 5739 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5740 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5741 | "Session has been destroyed regardless...\n", status); |
| 5742 | |
| 5743 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5744 | return status; |
| 5745 | } |
| 5746 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5747 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5748 | * Renew the cl_session lease. |
| 5749 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5750 | struct nfs4_sequence_data { |
| 5751 | struct nfs_client *clp; |
| 5752 | struct nfs4_sequence_args args; |
| 5753 | struct nfs4_sequence_res res; |
| 5754 | }; |
| 5755 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5756 | static void nfs41_sequence_release(void *data) |
| 5757 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5758 | struct nfs4_sequence_data *calldata = data; |
| 5759 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5760 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5761 | if (atomic_read(&clp->cl_count) > 1) |
| 5762 | nfs4_schedule_state_renewal(clp); |
| 5763 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5764 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5765 | } |
| 5766 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5767 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5768 | { |
| 5769 | switch(task->tk_status) { |
| 5770 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5771 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5772 | return -EAGAIN; |
| 5773 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5774 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5775 | } |
| 5776 | return 0; |
| 5777 | } |
| 5778 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5779 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5780 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5781 | struct nfs4_sequence_data *calldata = data; |
| 5782 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5783 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5784 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5785 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5786 | |
| 5787 | if (task->tk_status < 0) { |
| 5788 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5789 | if (atomic_read(&clp->cl_count) == 1) |
| 5790 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5791 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5792 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5793 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5794 | return; |
| 5795 | } |
| 5796 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5797 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5798 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5799 | dprintk("<-- %s\n", __func__); |
| 5800 | } |
| 5801 | |
| 5802 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5803 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5804 | struct nfs4_sequence_data *calldata = data; |
| 5805 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5806 | struct nfs4_sequence_args *args; |
| 5807 | struct nfs4_sequence_res *res; |
| 5808 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5809 | args = task->tk_msg.rpc_argp; |
| 5810 | res = task->tk_msg.rpc_resp; |
| 5811 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5812 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5813 | return; |
| 5814 | rpc_call_start(task); |
| 5815 | } |
| 5816 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5817 | static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data) |
| 5818 | { |
| 5819 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 5820 | nfs41_sequence_prepare(task, data); |
| 5821 | } |
| 5822 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5823 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5824 | .rpc_call_done = nfs41_sequence_call_done, |
| 5825 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5826 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5827 | }; |
| 5828 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5829 | static const struct rpc_call_ops nfs41_sequence_privileged_ops = { |
| 5830 | .rpc_call_done = nfs41_sequence_call_done, |
| 5831 | .rpc_call_prepare = nfs41_sequence_prepare_privileged, |
| 5832 | .rpc_release = nfs41_sequence_release, |
| 5833 | }; |
| 5834 | |
| 5835 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred, |
| 5836 | const struct rpc_call_ops *seq_ops) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5837 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5838 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5839 | struct rpc_message msg = { |
| 5840 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5841 | .rpc_cred = cred, |
| 5842 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5843 | struct rpc_task_setup task_setup_data = { |
| 5844 | .rpc_client = clp->cl_rpcclient, |
| 5845 | .rpc_message = &msg, |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5846 | .callback_ops = seq_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5847 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5848 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5849 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5850 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5851 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5852 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5853 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5854 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5855 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5856 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5857 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5858 | msg.rpc_argp = &calldata->args; |
| 5859 | msg.rpc_resp = &calldata->res; |
| 5860 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5861 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5862 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5863 | return rpc_run_task(&task_setup_data); |
| 5864 | } |
| 5865 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5866 | 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] | 5867 | { |
| 5868 | struct rpc_task *task; |
| 5869 | int ret = 0; |
| 5870 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5871 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5872 | return 0; |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5873 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5874 | if (IS_ERR(task)) |
| 5875 | ret = PTR_ERR(task); |
| 5876 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5877 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5878 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5879 | return ret; |
| 5880 | } |
| 5881 | |
| 5882 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5883 | { |
| 5884 | struct rpc_task *task; |
| 5885 | int ret; |
| 5886 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5887 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5888 | if (IS_ERR(task)) { |
| 5889 | ret = PTR_ERR(task); |
| 5890 | goto out; |
| 5891 | } |
| 5892 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5893 | if (!ret) { |
| 5894 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5895 | |
| 5896 | if (task->tk_status == 0) |
| 5897 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5898 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5899 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5900 | rpc_put_task(task); |
| 5901 | out: |
| 5902 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5903 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5904 | } |
| 5905 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5906 | struct nfs4_reclaim_complete_data { |
| 5907 | struct nfs_client *clp; |
| 5908 | struct nfs41_reclaim_complete_args arg; |
| 5909 | struct nfs41_reclaim_complete_res res; |
| 5910 | }; |
| 5911 | |
| 5912 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5913 | { |
| 5914 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5915 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5916 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5917 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5918 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5919 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5920 | return; |
| 5921 | |
| 5922 | rpc_call_start(task); |
| 5923 | } |
| 5924 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5925 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5926 | { |
| 5927 | switch(task->tk_status) { |
| 5928 | case 0: |
| 5929 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5930 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5931 | break; |
| 5932 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5933 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5934 | /* fall through */ |
| 5935 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5936 | return -EAGAIN; |
| 5937 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5938 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5939 | } |
| 5940 | return 0; |
| 5941 | } |
| 5942 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5943 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5944 | { |
| 5945 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5946 | struct nfs_client *clp = calldata->clp; |
| 5947 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5948 | |
| 5949 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5950 | if (!nfs41_sequence_done(task, res)) |
| 5951 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5952 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5953 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5954 | rpc_restart_call_prepare(task); |
| 5955 | return; |
| 5956 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5957 | dprintk("<-- %s\n", __func__); |
| 5958 | } |
| 5959 | |
| 5960 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5961 | { |
| 5962 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5963 | |
| 5964 | kfree(calldata); |
| 5965 | } |
| 5966 | |
| 5967 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5968 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5969 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5970 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5971 | }; |
| 5972 | |
| 5973 | /* |
| 5974 | * Issue a global reclaim complete. |
| 5975 | */ |
| 5976 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5977 | { |
| 5978 | struct nfs4_reclaim_complete_data *calldata; |
| 5979 | struct rpc_task *task; |
| 5980 | struct rpc_message msg = { |
| 5981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5982 | }; |
| 5983 | struct rpc_task_setup task_setup_data = { |
| 5984 | .rpc_client = clp->cl_rpcclient, |
| 5985 | .rpc_message = &msg, |
| 5986 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5987 | .flags = RPC_TASK_ASYNC, |
| 5988 | }; |
| 5989 | int status = -ENOMEM; |
| 5990 | |
| 5991 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5992 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5993 | if (calldata == NULL) |
| 5994 | goto out; |
| 5995 | calldata->clp = clp; |
| 5996 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5997 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5998 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5999 | msg.rpc_argp = &calldata->arg; |
| 6000 | msg.rpc_resp = &calldata->res; |
| 6001 | task_setup_data.callback_data = calldata; |
| 6002 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6003 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6004 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6005 | goto out; |
| 6006 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6007 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6008 | if (status == 0) |
| 6009 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6010 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6011 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6012 | out: |
| 6013 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6014 | return status; |
| 6015 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6016 | |
| 6017 | static void |
| 6018 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6019 | { |
| 6020 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6021 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6022 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6023 | |
| 6024 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6025 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6026 | * right now covering the LAYOUTGET we are about to send. |
| 6027 | * However, that is not so catastrophic, and there seems |
| 6028 | * to be no way to prevent it completely. |
| 6029 | */ |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6030 | if (nfs41_setup_sequence(session, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6031 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6032 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6033 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6034 | NFS_I(lgp->args.inode)->layout, |
| 6035 | lgp->args.ctx->state)) { |
| 6036 | rpc_exit(task, NFS4_OK); |
| 6037 | return; |
| 6038 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6039 | rpc_call_start(task); |
| 6040 | } |
| 6041 | |
| 6042 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6043 | { |
| 6044 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6045 | struct inode *inode = lgp->args.inode; |
| 6046 | struct nfs_server *server = NFS_SERVER(inode); |
| 6047 | struct pnfs_layout_hdr *lo; |
| 6048 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6049 | |
| 6050 | dprintk("--> %s\n", __func__); |
| 6051 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6052 | if (!nfs41_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6053 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6054 | |
| 6055 | switch (task->tk_status) { |
| 6056 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6057 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6058 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6059 | case -NFS4ERR_RECALLCONFLICT: |
| 6060 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6061 | break; |
| 6062 | case -NFS4ERR_EXPIRED: |
| 6063 | case -NFS4ERR_BAD_STATEID: |
| 6064 | spin_lock(&inode->i_lock); |
| 6065 | lo = NFS_I(inode)->layout; |
| 6066 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6067 | spin_unlock(&inode->i_lock); |
| 6068 | /* If the open stateid was bad, then recover it. */ |
| 6069 | state = lgp->args.ctx->state; |
| 6070 | } else { |
| 6071 | LIST_HEAD(head); |
| 6072 | |
| 6073 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6074 | spin_unlock(&inode->i_lock); |
| 6075 | /* Mark the bad layout state as invalid, then |
| 6076 | * retry using the open stateid. */ |
| 6077 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6078 | } |
| 6079 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6080 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6081 | rpc_restart_call_prepare(task); |
| 6082 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6083 | dprintk("<-- %s\n", __func__); |
| 6084 | } |
| 6085 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6086 | static size_t max_response_pages(struct nfs_server *server) |
| 6087 | { |
| 6088 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6089 | return nfs_page_array_len(0, max_resp_sz); |
| 6090 | } |
| 6091 | |
| 6092 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6093 | { |
| 6094 | int i; |
| 6095 | |
| 6096 | if (!pages) |
| 6097 | return; |
| 6098 | |
| 6099 | for (i = 0; i < size; i++) { |
| 6100 | if (!pages[i]) |
| 6101 | break; |
| 6102 | __free_page(pages[i]); |
| 6103 | } |
| 6104 | kfree(pages); |
| 6105 | } |
| 6106 | |
| 6107 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6108 | { |
| 6109 | struct page **pages; |
| 6110 | int i; |
| 6111 | |
| 6112 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6113 | if (!pages) { |
| 6114 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6115 | return NULL; |
| 6116 | } |
| 6117 | |
| 6118 | for (i = 0; i < size; i++) { |
| 6119 | pages[i] = alloc_page(gfp_flags); |
| 6120 | if (!pages[i]) { |
| 6121 | dprintk("%s: failed to allocate page\n", __func__); |
| 6122 | nfs4_free_pages(pages, size); |
| 6123 | return NULL; |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | return pages; |
| 6128 | } |
| 6129 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6130 | static void nfs4_layoutget_release(void *calldata) |
| 6131 | { |
| 6132 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6133 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6134 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6135 | |
| 6136 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6137 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6138 | put_nfs_open_context(lgp->args.ctx); |
| 6139 | kfree(calldata); |
| 6140 | dprintk("<-- %s\n", __func__); |
| 6141 | } |
| 6142 | |
| 6143 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6144 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6145 | .rpc_call_done = nfs4_layoutget_done, |
| 6146 | .rpc_release = nfs4_layoutget_release, |
| 6147 | }; |
| 6148 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6149 | struct pnfs_layout_segment * |
| 6150 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6151 | { |
| 6152 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6153 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6154 | struct rpc_task *task; |
| 6155 | struct rpc_message msg = { |
| 6156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6157 | .rpc_argp = &lgp->args, |
| 6158 | .rpc_resp = &lgp->res, |
| 6159 | }; |
| 6160 | struct rpc_task_setup task_setup_data = { |
| 6161 | .rpc_client = server->client, |
| 6162 | .rpc_message = &msg, |
| 6163 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6164 | .callback_data = lgp, |
| 6165 | .flags = RPC_TASK_ASYNC, |
| 6166 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6167 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6168 | int status = 0; |
| 6169 | |
| 6170 | dprintk("--> %s\n", __func__); |
| 6171 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6172 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6173 | if (!lgp->args.layout.pages) { |
| 6174 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6175 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6176 | } |
| 6177 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6178 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6179 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6180 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6181 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6182 | task = rpc_run_task(&task_setup_data); |
| 6183 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6184 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6185 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6186 | if (status == 0) |
| 6187 | status = task->tk_status; |
| 6188 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6189 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6190 | rpc_put_task(task); |
| 6191 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6192 | if (status) |
| 6193 | return ERR_PTR(status); |
| 6194 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6195 | } |
| 6196 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6197 | static void |
| 6198 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6199 | { |
| 6200 | struct nfs4_layoutreturn *lrp = calldata; |
| 6201 | |
| 6202 | dprintk("--> %s\n", __func__); |
| 6203 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6204 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6205 | return; |
| 6206 | rpc_call_start(task); |
| 6207 | } |
| 6208 | |
| 6209 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6210 | { |
| 6211 | struct nfs4_layoutreturn *lrp = calldata; |
| 6212 | struct nfs_server *server; |
| 6213 | |
| 6214 | dprintk("--> %s\n", __func__); |
| 6215 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6216 | if (!nfs41_sequence_done(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6217 | return; |
| 6218 | |
| 6219 | server = NFS_SERVER(lrp->args.inode); |
| 6220 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6221 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6222 | return; |
| 6223 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6224 | dprintk("<-- %s\n", __func__); |
| 6225 | } |
| 6226 | |
| 6227 | static void nfs4_layoutreturn_release(void *calldata) |
| 6228 | { |
| 6229 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6230 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6231 | |
| 6232 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6233 | spin_lock(&lo->plh_inode->i_lock); |
| 6234 | if (lrp->res.lrs_present) |
| 6235 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6236 | lo->plh_block_lgets--; |
| 6237 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6238 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6239 | kfree(calldata); |
| 6240 | dprintk("<-- %s\n", __func__); |
| 6241 | } |
| 6242 | |
| 6243 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6244 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6245 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6246 | .rpc_release = nfs4_layoutreturn_release, |
| 6247 | }; |
| 6248 | |
| 6249 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6250 | { |
| 6251 | struct rpc_task *task; |
| 6252 | struct rpc_message msg = { |
| 6253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6254 | .rpc_argp = &lrp->args, |
| 6255 | .rpc_resp = &lrp->res, |
| 6256 | }; |
| 6257 | struct rpc_task_setup task_setup_data = { |
| 6258 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6259 | .rpc_message = &msg, |
| 6260 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6261 | .callback_data = lrp, |
| 6262 | }; |
| 6263 | int status; |
| 6264 | |
| 6265 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6266 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6267 | task = rpc_run_task(&task_setup_data); |
| 6268 | if (IS_ERR(task)) |
| 6269 | return PTR_ERR(task); |
| 6270 | status = task->tk_status; |
| 6271 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6272 | rpc_put_task(task); |
| 6273 | return status; |
| 6274 | } |
| 6275 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6276 | /* |
| 6277 | * Retrieve the list of Data Server devices from the MDS. |
| 6278 | */ |
| 6279 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6280 | const struct nfs_fh *fh, |
| 6281 | struct pnfs_devicelist *devlist) |
| 6282 | { |
| 6283 | struct nfs4_getdevicelist_args args = { |
| 6284 | .fh = fh, |
| 6285 | .layoutclass = server->pnfs_curr_ld->id, |
| 6286 | }; |
| 6287 | struct nfs4_getdevicelist_res res = { |
| 6288 | .devlist = devlist, |
| 6289 | }; |
| 6290 | struct rpc_message msg = { |
| 6291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6292 | .rpc_argp = &args, |
| 6293 | .rpc_resp = &res, |
| 6294 | }; |
| 6295 | int status; |
| 6296 | |
| 6297 | dprintk("--> %s\n", __func__); |
| 6298 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6299 | &res.seq_res, 0); |
| 6300 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6301 | return status; |
| 6302 | } |
| 6303 | |
| 6304 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6305 | const struct nfs_fh *fh, |
| 6306 | struct pnfs_devicelist *devlist) |
| 6307 | { |
| 6308 | struct nfs4_exception exception = { }; |
| 6309 | int err; |
| 6310 | |
| 6311 | do { |
| 6312 | err = nfs4_handle_exception(server, |
| 6313 | _nfs4_getdevicelist(server, fh, devlist), |
| 6314 | &exception); |
| 6315 | } while (exception.retry); |
| 6316 | |
| 6317 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6318 | err, devlist->num_devs); |
| 6319 | |
| 6320 | return err; |
| 6321 | } |
| 6322 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6323 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6324 | static int |
| 6325 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6326 | { |
| 6327 | struct nfs4_getdeviceinfo_args args = { |
| 6328 | .pdev = pdev, |
| 6329 | }; |
| 6330 | struct nfs4_getdeviceinfo_res res = { |
| 6331 | .pdev = pdev, |
| 6332 | }; |
| 6333 | struct rpc_message msg = { |
| 6334 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6335 | .rpc_argp = &args, |
| 6336 | .rpc_resp = &res, |
| 6337 | }; |
| 6338 | int status; |
| 6339 | |
| 6340 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6341 | 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] | 6342 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6343 | |
| 6344 | return status; |
| 6345 | } |
| 6346 | |
| 6347 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6348 | { |
| 6349 | struct nfs4_exception exception = { }; |
| 6350 | int err; |
| 6351 | |
| 6352 | do { |
| 6353 | err = nfs4_handle_exception(server, |
| 6354 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6355 | &exception); |
| 6356 | } while (exception.retry); |
| 6357 | return err; |
| 6358 | } |
| 6359 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6360 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6361 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6362 | { |
| 6363 | struct nfs4_layoutcommit_data *data = calldata; |
| 6364 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6365 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6366 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6367 | if (nfs41_setup_sequence(session, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6368 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6369 | return; |
| 6370 | rpc_call_start(task); |
| 6371 | } |
| 6372 | |
| 6373 | static void |
| 6374 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6375 | { |
| 6376 | struct nfs4_layoutcommit_data *data = calldata; |
| 6377 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6378 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame^] | 6379 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6380 | return; |
| 6381 | |
| 6382 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6383 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6384 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6385 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6386 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6387 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6388 | break; |
| 6389 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6390 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6391 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6392 | break; |
| 6393 | default: |
| 6394 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6395 | rpc_restart_call_prepare(task); |
| 6396 | return; |
| 6397 | } |
| 6398 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | static void nfs4_layoutcommit_release(void *calldata) |
| 6402 | { |
| 6403 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6404 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6405 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6406 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6407 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6408 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6409 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6410 | list_del_init(&lseg->pls_lc_list); |
| 6411 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6412 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6413 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6414 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6415 | |
| 6416 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6417 | smp_mb__after_clear_bit(); |
| 6418 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6419 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6420 | put_rpccred(data->cred); |
| 6421 | kfree(data); |
| 6422 | } |
| 6423 | |
| 6424 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6425 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6426 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6427 | .rpc_release = nfs4_layoutcommit_release, |
| 6428 | }; |
| 6429 | |
| 6430 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6431 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6432 | { |
| 6433 | struct rpc_message msg = { |
| 6434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6435 | .rpc_argp = &data->args, |
| 6436 | .rpc_resp = &data->res, |
| 6437 | .rpc_cred = data->cred, |
| 6438 | }; |
| 6439 | struct rpc_task_setup task_setup_data = { |
| 6440 | .task = &data->task, |
| 6441 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6442 | .rpc_message = &msg, |
| 6443 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6444 | .callback_data = data, |
| 6445 | .flags = RPC_TASK_ASYNC, |
| 6446 | }; |
| 6447 | struct rpc_task *task; |
| 6448 | int status = 0; |
| 6449 | |
| 6450 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6451 | "lbw: %llu inode %lu\n", |
| 6452 | data->task.tk_pid, sync, |
| 6453 | data->args.lastbytewritten, |
| 6454 | data->args.inode->i_ino); |
| 6455 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6456 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6457 | task = rpc_run_task(&task_setup_data); |
| 6458 | if (IS_ERR(task)) |
| 6459 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6460 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6461 | goto out; |
| 6462 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6463 | if (status != 0) |
| 6464 | goto out; |
| 6465 | status = task->tk_status; |
| 6466 | out: |
| 6467 | dprintk("%s: status %d\n", __func__, status); |
| 6468 | rpc_put_task(task); |
| 6469 | return status; |
| 6470 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6471 | |
| 6472 | static int |
| 6473 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6474 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6475 | { |
| 6476 | struct nfs41_secinfo_no_name_args args = { |
| 6477 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6478 | }; |
| 6479 | struct nfs4_secinfo_res res = { |
| 6480 | .flavors = flavors, |
| 6481 | }; |
| 6482 | struct rpc_message msg = { |
| 6483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6484 | .rpc_argp = &args, |
| 6485 | .rpc_resp = &res, |
| 6486 | }; |
| 6487 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6488 | } |
| 6489 | |
| 6490 | static int |
| 6491 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6492 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6493 | { |
| 6494 | struct nfs4_exception exception = { }; |
| 6495 | int err; |
| 6496 | do { |
| 6497 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6498 | switch (err) { |
| 6499 | case 0: |
| 6500 | case -NFS4ERR_WRONGSEC: |
| 6501 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6502 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6503 | default: |
| 6504 | err = nfs4_handle_exception(server, err, &exception); |
| 6505 | } |
| 6506 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6507 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6508 | return err; |
| 6509 | } |
| 6510 | |
| 6511 | static int |
| 6512 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6513 | struct nfs_fsinfo *info) |
| 6514 | { |
| 6515 | int err; |
| 6516 | struct page *page; |
| 6517 | rpc_authflavor_t flavor; |
| 6518 | struct nfs4_secinfo_flavors *flavors; |
| 6519 | |
| 6520 | page = alloc_page(GFP_KERNEL); |
| 6521 | if (!page) { |
| 6522 | err = -ENOMEM; |
| 6523 | goto out; |
| 6524 | } |
| 6525 | |
| 6526 | flavors = page_address(page); |
| 6527 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6528 | |
| 6529 | /* |
| 6530 | * Fall back on "guess and check" method if |
| 6531 | * the server doesn't support SECINFO_NO_NAME |
| 6532 | */ |
| 6533 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6534 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6535 | goto out_freepage; |
| 6536 | } |
| 6537 | if (err) |
| 6538 | goto out_freepage; |
| 6539 | |
| 6540 | flavor = nfs_find_best_sec(flavors); |
| 6541 | if (err == 0) |
| 6542 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6543 | |
| 6544 | out_freepage: |
| 6545 | put_page(page); |
| 6546 | if (err == -EACCES) |
| 6547 | return -EPERM; |
| 6548 | out: |
| 6549 | return err; |
| 6550 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6551 | |
| 6552 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6553 | { |
| 6554 | int status; |
| 6555 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6556 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6557 | }; |
| 6558 | struct nfs41_test_stateid_res res; |
| 6559 | struct rpc_message msg = { |
| 6560 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6561 | .rpc_argp = &args, |
| 6562 | .rpc_resp = &res, |
| 6563 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6564 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6565 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6566 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6567 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6568 | if (status != NFS_OK) { |
| 6569 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6570 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6571 | } |
| 6572 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6573 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6574 | } |
| 6575 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6576 | /** |
| 6577 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6578 | * |
| 6579 | * @server: server / transport on which to perform the operation |
| 6580 | * @stateid: state ID to test |
| 6581 | * |
| 6582 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6583 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6584 | * failed or the state ID is not currently valid. |
| 6585 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6586 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6587 | { |
| 6588 | struct nfs4_exception exception = { }; |
| 6589 | int err; |
| 6590 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6591 | err = _nfs41_test_stateid(server, stateid); |
| 6592 | if (err != -NFS4ERR_DELAY) |
| 6593 | break; |
| 6594 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6595 | } while (exception.retry); |
| 6596 | return err; |
| 6597 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6598 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6599 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6600 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6601 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6602 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6603 | }; |
| 6604 | struct nfs41_free_stateid_res res; |
| 6605 | struct rpc_message msg = { |
| 6606 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6607 | .rpc_argp = &args, |
| 6608 | .rpc_resp = &res, |
| 6609 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6610 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6611 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6612 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6613 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6614 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6615 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6616 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6617 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6618 | } |
| 6619 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6620 | /** |
| 6621 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6622 | * |
| 6623 | * @server: server / transport on which to perform the operation |
| 6624 | * @stateid: state ID to release |
| 6625 | * |
| 6626 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6627 | * negative NFS4ERR value is returned. |
| 6628 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6629 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6630 | { |
| 6631 | struct nfs4_exception exception = { }; |
| 6632 | int err; |
| 6633 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6634 | err = _nfs4_free_stateid(server, stateid); |
| 6635 | if (err != -NFS4ERR_DELAY) |
| 6636 | break; |
| 6637 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6638 | } while (exception.retry); |
| 6639 | return err; |
| 6640 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6641 | |
| 6642 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6643 | const nfs4_stateid *s2) |
| 6644 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6645 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6646 | return false; |
| 6647 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6648 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6649 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6650 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6651 | return true; |
| 6652 | |
| 6653 | return false; |
| 6654 | } |
| 6655 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6656 | #endif /* CONFIG_NFS_V4_1 */ |
| 6657 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6658 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6659 | const nfs4_stateid *s2) |
| 6660 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6661 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6665 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6666 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6667 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6668 | .recover_open = nfs4_open_reclaim, |
| 6669 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6670 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6671 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6672 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6673 | }; |
| 6674 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6675 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6676 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6677 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6678 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6679 | .recover_open = nfs4_open_reclaim, |
| 6680 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6681 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6682 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6683 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6684 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6685 | }; |
| 6686 | #endif /* CONFIG_NFS_V4_1 */ |
| 6687 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6688 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6689 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6690 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6691 | .recover_open = nfs4_open_expired, |
| 6692 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6693 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6694 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6695 | }; |
| 6696 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6697 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6698 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6699 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6700 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6701 | .recover_open = nfs41_open_expired, |
| 6702 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6703 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6704 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6705 | }; |
| 6706 | #endif /* CONFIG_NFS_V4_1 */ |
| 6707 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6708 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6709 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6710 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6711 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6712 | }; |
| 6713 | |
| 6714 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6715 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6716 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6717 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6718 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6719 | }; |
| 6720 | #endif |
| 6721 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6722 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6723 | .minor_version = 0, |
| 6724 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6725 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6726 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6727 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6728 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6729 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6730 | }; |
| 6731 | |
| 6732 | #if defined(CONFIG_NFS_V4_1) |
| 6733 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6734 | .minor_version = 1, |
| 6735 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6736 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6737 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6738 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6739 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6740 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6741 | }; |
| 6742 | #endif |
| 6743 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6744 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6745 | [0] = &nfs_v4_0_minor_ops, |
| 6746 | #if defined(CONFIG_NFS_V4_1) |
| 6747 | [1] = &nfs_v4_1_minor_ops, |
| 6748 | #endif |
| 6749 | }; |
| 6750 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6751 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6752 | .create = nfs_create, |
| 6753 | .lookup = nfs_lookup, |
| 6754 | .atomic_open = nfs_atomic_open, |
| 6755 | .link = nfs_link, |
| 6756 | .unlink = nfs_unlink, |
| 6757 | .symlink = nfs_symlink, |
| 6758 | .mkdir = nfs_mkdir, |
| 6759 | .rmdir = nfs_rmdir, |
| 6760 | .mknod = nfs_mknod, |
| 6761 | .rename = nfs_rename, |
| 6762 | .permission = nfs_permission, |
| 6763 | .getattr = nfs_getattr, |
| 6764 | .setattr = nfs_setattr, |
| 6765 | .getxattr = generic_getxattr, |
| 6766 | .setxattr = generic_setxattr, |
| 6767 | .listxattr = generic_listxattr, |
| 6768 | .removexattr = generic_removexattr, |
| 6769 | }; |
| 6770 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6771 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6772 | .permission = nfs_permission, |
| 6773 | .getattr = nfs_getattr, |
| 6774 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6775 | .getxattr = generic_getxattr, |
| 6776 | .setxattr = generic_setxattr, |
| 6777 | .listxattr = generic_listxattr, |
| 6778 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6779 | }; |
| 6780 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6781 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6782 | .version = 4, /* protocol version */ |
| 6783 | .dentry_ops = &nfs4_dentry_operations, |
| 6784 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6785 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6786 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6787 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6788 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6789 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | .getattr = nfs4_proc_getattr, |
| 6791 | .setattr = nfs4_proc_setattr, |
| 6792 | .lookup = nfs4_proc_lookup, |
| 6793 | .access = nfs4_proc_access, |
| 6794 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6795 | .create = nfs4_proc_create, |
| 6796 | .remove = nfs4_proc_remove, |
| 6797 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6798 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6799 | .unlink_done = nfs4_proc_unlink_done, |
| 6800 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6801 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6802 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6803 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6804 | .link = nfs4_proc_link, |
| 6805 | .symlink = nfs4_proc_symlink, |
| 6806 | .mkdir = nfs4_proc_mkdir, |
| 6807 | .rmdir = nfs4_proc_remove, |
| 6808 | .readdir = nfs4_proc_readdir, |
| 6809 | .mknod = nfs4_proc_mknod, |
| 6810 | .statfs = nfs4_proc_statfs, |
| 6811 | .fsinfo = nfs4_proc_fsinfo, |
| 6812 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6813 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6814 | .decode_dirent = nfs4_decode_dirent, |
| 6815 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6816 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6817 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6818 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6819 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6820 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6821 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6822 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6823 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6824 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6825 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6826 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6827 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6828 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6829 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6830 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6831 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6832 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6833 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6834 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6835 | .create_server = nfs4_create_server, |
| 6836 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6837 | }; |
| 6838 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6839 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6840 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6841 | .list = nfs4_xattr_list_nfs4_acl, |
| 6842 | .get = nfs4_xattr_get_nfs4_acl, |
| 6843 | .set = nfs4_xattr_set_nfs4_acl, |
| 6844 | }; |
| 6845 | |
| 6846 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6847 | &nfs4_xattr_nfs4_acl_handler, |
| 6848 | NULL |
| 6849 | }; |
| 6850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6851 | /* |
| 6852 | * Local variables: |
| 6853 | * c-basic-offset: 8 |
| 6854 | * End: |
| 6855 | */ |