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; |
| 600 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 601 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 602 | |
| 603 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 604 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 605 | return; |
| 606 | rpc_call_start(task); |
| 607 | } |
| 608 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 609 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 610 | { |
| 611 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 612 | nfs41_call_sync_prepare(task, calldata); |
| 613 | } |
| 614 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 615 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 616 | { |
| 617 | struct nfs41_call_sync_data *data = calldata; |
| 618 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 619 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 620 | } |
| 621 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 622 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 624 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | }; |
| 626 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 627 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 628 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 629 | .rpc_call_done = nfs41_call_sync_done, |
| 630 | }; |
| 631 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 632 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 633 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | struct rpc_message *msg, |
| 635 | struct nfs4_sequence_args *args, |
| 636 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 637 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | { |
| 639 | int ret; |
| 640 | struct rpc_task *task; |
| 641 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 642 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 643 | .seq_args = args, |
| 644 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | }; |
| 646 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 647 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 648 | .rpc_message = msg, |
| 649 | .callback_ops = &nfs41_call_sync_ops, |
| 650 | .callback_data = &data |
| 651 | }; |
| 652 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 653 | if (privileged) |
| 654 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 655 | task = rpc_run_task(&task_setup); |
| 656 | if (IS_ERR(task)) |
| 657 | ret = PTR_ERR(task); |
| 658 | else { |
| 659 | ret = task->tk_status; |
| 660 | rpc_put_task(task); |
| 661 | } |
| 662 | return ret; |
| 663 | } |
| 664 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 665 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 666 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 667 | struct rpc_message *msg, |
| 668 | struct nfs4_sequence_args *args, |
| 669 | struct nfs4_sequence_res *res, |
| 670 | int cache_reply) |
| 671 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 672 | nfs41_init_sequence(args, res, cache_reply); |
| 673 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 674 | } |
| 675 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 677 | static inline |
| 678 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 679 | struct nfs4_sequence_res *res, int cache_reply) |
| 680 | { |
| 681 | } |
| 682 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 683 | static int nfs4_sequence_done(struct rpc_task *task, |
| 684 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 685 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 686 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 687 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 688 | #endif /* CONFIG_NFS_V4_1 */ |
| 689 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 690 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 691 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 692 | struct rpc_message *msg, |
| 693 | struct nfs4_sequence_args *args, |
| 694 | struct nfs4_sequence_res *res, |
| 695 | int cache_reply) |
| 696 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 697 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 698 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 701 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 702 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 703 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 704 | struct rpc_message *msg, |
| 705 | struct nfs4_sequence_args *args, |
| 706 | struct nfs4_sequence_res *res, |
| 707 | int cache_reply) |
| 708 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 709 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 710 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 711 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 712 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 713 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 715 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 717 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 718 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 719 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 720 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 721 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 722 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 725 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 726 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 727 | struct nfs_openargs o_arg; |
| 728 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 729 | struct nfs_open_confirmargs c_arg; |
| 730 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 731 | struct nfs4_string owner_name; |
| 732 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 733 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 734 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 735 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 736 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 737 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 738 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 739 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 740 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 741 | int rpc_status; |
| 742 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 743 | }; |
| 744 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 745 | |
| 746 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 747 | { |
| 748 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 749 | p->o_res.seqid = p->o_arg.seqid; |
| 750 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 751 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 752 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 753 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 754 | 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] | 755 | } |
| 756 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 757 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 758 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 759 | const struct iattr *attrs, |
| 760 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 762 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct inode *dir = parent->d_inode; |
| 764 | struct nfs_server *server = NFS_SERVER(dir); |
| 765 | struct nfs4_opendata *p; |
| 766 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 767 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 768 | if (p == NULL) |
| 769 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 770 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | if (p->o_arg.seqid == NULL) |
| 772 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 773 | nfs_sb_active(dentry->d_sb); |
| 774 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 775 | p->dir = parent; |
| 776 | p->owner = sp; |
| 777 | atomic_inc(&sp->so_count); |
| 778 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 779 | p->o_arg.open_flags = flags; |
| 780 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 781 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 782 | * will return permission denied for all bits until close */ |
| 783 | if (!(flags & O_EXCL)) { |
| 784 | /* ask server to check for all possible rights as results |
| 785 | * are cached */ |
| 786 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 787 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 788 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 789 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 790 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 791 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 792 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | p->o_arg.server = server; |
| 794 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 795 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 797 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 798 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 799 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 800 | p->o_arg.u.attrs = &p->attrs; |
| 801 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 802 | |
| 803 | verf[0] = jiffies; |
| 804 | verf[1] = current->pid; |
| 805 | memcpy(p->o_arg.u.verifier.data, verf, |
| 806 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 807 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 808 | p->c_arg.fh = &p->o_res.fh; |
| 809 | p->c_arg.stateid = &p->o_res.stateid; |
| 810 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 811 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 812 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 813 | return p; |
| 814 | err_free: |
| 815 | kfree(p); |
| 816 | err: |
| 817 | dput(parent); |
| 818 | return NULL; |
| 819 | } |
| 820 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 821 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 823 | struct nfs4_opendata *p = container_of(kref, |
| 824 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 825 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 826 | |
| 827 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 828 | if (p->state != NULL) |
| 829 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 830 | nfs4_put_state_owner(p->owner); |
| 831 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 832 | dput(p->dentry); |
| 833 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 834 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 835 | kfree(p); |
| 836 | } |
| 837 | |
| 838 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 839 | { |
| 840 | if (p != NULL) |
| 841 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 842 | } |
| 843 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 844 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 845 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 846 | int ret; |
| 847 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 848 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 849 | return ret; |
| 850 | } |
| 851 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 852 | 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] | 853 | { |
| 854 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 855 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 856 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 857 | goto out; |
| 858 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 859 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 860 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 861 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 862 | break; |
| 863 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 864 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 865 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 866 | break; |
| 867 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 868 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 869 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 870 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 871 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 872 | return ret; |
| 873 | } |
| 874 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 875 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 876 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 877 | if (delegation == NULL) |
| 878 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 879 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 880 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 881 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 882 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 883 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 884 | return 1; |
| 885 | } |
| 886 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 887 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 888 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 889 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 890 | case FMODE_WRITE: |
| 891 | state->n_wronly++; |
| 892 | break; |
| 893 | case FMODE_READ: |
| 894 | state->n_rdonly++; |
| 895 | break; |
| 896 | case FMODE_READ|FMODE_WRITE: |
| 897 | state->n_rdwr++; |
| 898 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 899 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 902 | 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] | 903 | { |
| 904 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 905 | nfs4_stateid_copy(&state->stateid, stateid); |
| 906 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 907 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 908 | case FMODE_READ: |
| 909 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 910 | break; |
| 911 | case FMODE_WRITE: |
| 912 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 913 | break; |
| 914 | case FMODE_READ|FMODE_WRITE: |
| 915 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 916 | } |
| 917 | } |
| 918 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 919 | 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] | 920 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 921 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 922 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 923 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 924 | } |
| 925 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 926 | 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] | 927 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 928 | /* |
| 929 | * Protect the call to nfs4_state_set_mode_locked and |
| 930 | * serialise the stateid update |
| 931 | */ |
| 932 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 933 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 934 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 935 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 936 | } |
| 937 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | write_sequnlock(&state->seqlock); |
| 940 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 941 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 942 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 945 | 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] | 946 | { |
| 947 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 948 | struct nfs_delegation *deleg_cur; |
| 949 | int ret = 0; |
| 950 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 952 | |
| 953 | rcu_read_lock(); |
| 954 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 955 | if (deleg_cur == NULL) |
| 956 | goto no_delegation; |
| 957 | |
| 958 | spin_lock(&deleg_cur->lock); |
| 959 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 960 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 961 | goto no_delegation_unlock; |
| 962 | |
| 963 | if (delegation == NULL) |
| 964 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 965 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 966 | goto no_delegation_unlock; |
| 967 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 968 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 970 | ret = 1; |
| 971 | no_delegation_unlock: |
| 972 | spin_unlock(&deleg_cur->lock); |
| 973 | no_delegation: |
| 974 | rcu_read_unlock(); |
| 975 | |
| 976 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 978 | ret = 1; |
| 979 | } |
| 980 | |
| 981 | return ret; |
| 982 | } |
| 983 | |
| 984 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 985 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 986 | { |
| 987 | struct nfs_delegation *delegation; |
| 988 | |
| 989 | rcu_read_lock(); |
| 990 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 991 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 992 | rcu_read_unlock(); |
| 993 | return; |
| 994 | } |
| 995 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 996 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 997 | } |
| 998 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 999 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1000 | { |
| 1001 | struct nfs4_state *state = opendata->state; |
| 1002 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1003 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1004 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1006 | nfs4_stateid stateid; |
| 1007 | int ret = -EAGAIN; |
| 1008 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1009 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1010 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1011 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | if (can_open_cached(state, fmode, open_mode)) { |
| 1013 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1014 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1015 | goto out_return_state; |
| 1016 | } |
| 1017 | spin_unlock(&state->owner->so_lock); |
| 1018 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1019 | rcu_read_lock(); |
| 1020 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1021 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1022 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1023 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1024 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1026 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1027 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1028 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1029 | if (ret != 0) |
| 1030 | goto out; |
| 1031 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1032 | |
| 1033 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1034 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1035 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1036 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | out: |
| 1038 | return ERR_PTR(ret); |
| 1039 | out_return_state: |
| 1040 | atomic_inc(&state->count); |
| 1041 | return state; |
| 1042 | } |
| 1043 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1044 | static void |
| 1045 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1046 | { |
| 1047 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1048 | struct nfs_delegation *delegation; |
| 1049 | int delegation_flags = 0; |
| 1050 | |
| 1051 | rcu_read_lock(); |
| 1052 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1053 | if (delegation) |
| 1054 | delegation_flags = delegation->flags; |
| 1055 | rcu_read_unlock(); |
| 1056 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1057 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1058 | "returning a delegation for " |
| 1059 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1060 | clp->cl_hostname); |
| 1061 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1062 | nfs_inode_set_delegation(state->inode, |
| 1063 | data->owner->so_cred, |
| 1064 | &data->o_res); |
| 1065 | else |
| 1066 | nfs_inode_reclaim_delegation(state->inode, |
| 1067 | data->owner->so_cred, |
| 1068 | &data->o_res); |
| 1069 | } |
| 1070 | |
| 1071 | /* |
| 1072 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1073 | * and update the nfs4_state. |
| 1074 | */ |
| 1075 | static struct nfs4_state * |
| 1076 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1077 | { |
| 1078 | struct inode *inode = data->state->inode; |
| 1079 | struct nfs4_state *state = data->state; |
| 1080 | int ret; |
| 1081 | |
| 1082 | if (!data->rpc_done) { |
| 1083 | ret = data->rpc_status; |
| 1084 | goto err; |
| 1085 | } |
| 1086 | |
| 1087 | ret = -ESTALE; |
| 1088 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1089 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1090 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1091 | goto err; |
| 1092 | |
| 1093 | ret = -ENOMEM; |
| 1094 | state = nfs4_get_open_state(inode, data->owner); |
| 1095 | if (state == NULL) |
| 1096 | goto err; |
| 1097 | |
| 1098 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1099 | if (ret) |
| 1100 | goto err; |
| 1101 | |
| 1102 | if (data->o_res.delegation_type != 0) |
| 1103 | nfs4_opendata_check_deleg(data, state); |
| 1104 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1105 | data->o_arg.fmode); |
| 1106 | |
| 1107 | return state; |
| 1108 | err: |
| 1109 | return ERR_PTR(ret); |
| 1110 | |
| 1111 | } |
| 1112 | |
| 1113 | static struct nfs4_state * |
| 1114 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1115 | { |
| 1116 | struct inode *inode; |
| 1117 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1118 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1119 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1120 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1121 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1122 | goto out; |
| 1123 | } |
| 1124 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1125 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1126 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1127 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1128 | 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] | 1129 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1130 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1131 | goto err; |
| 1132 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1133 | state = nfs4_get_open_state(inode, data->owner); |
| 1134 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1135 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1136 | if (data->o_res.delegation_type != 0) |
| 1137 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1138 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1139 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1140 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1141 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1142 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1143 | err_put_inode: |
| 1144 | iput(inode); |
| 1145 | err: |
| 1146 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1149 | static struct nfs4_state * |
| 1150 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1151 | { |
| 1152 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1153 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1154 | return _nfs4_opendata_to_nfs4_state(data); |
| 1155 | } |
| 1156 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1157 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1158 | { |
| 1159 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1160 | struct nfs_open_context *ctx; |
| 1161 | |
| 1162 | spin_lock(&state->inode->i_lock); |
| 1163 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1164 | if (ctx->state != state) |
| 1165 | continue; |
| 1166 | get_nfs_open_context(ctx); |
| 1167 | spin_unlock(&state->inode->i_lock); |
| 1168 | return ctx; |
| 1169 | } |
| 1170 | spin_unlock(&state->inode->i_lock); |
| 1171 | return ERR_PTR(-ENOENT); |
| 1172 | } |
| 1173 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1174 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1175 | { |
| 1176 | struct nfs4_opendata *opendata; |
| 1177 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1178 | 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] | 1179 | if (opendata == NULL) |
| 1180 | return ERR_PTR(-ENOMEM); |
| 1181 | opendata->state = state; |
| 1182 | atomic_inc(&state->count); |
| 1183 | return opendata; |
| 1184 | } |
| 1185 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1186 | 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] | 1187 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1188 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1189 | int ret; |
| 1190 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1191 | opendata->o_arg.open_flags = 0; |
| 1192 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1193 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1194 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1195 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1196 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1197 | if (ret != 0) |
| 1198 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1199 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1200 | if (IS_ERR(newstate)) |
| 1201 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1202 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1203 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1208 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1209 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | int ret; |
| 1211 | |
| 1212 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1213 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1214 | smp_rmb(); |
| 1215 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1216 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1217 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | if (ret != 0) |
| 1219 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1220 | if (newstate != state) |
| 1221 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | } |
| 1223 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1224 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1225 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1226 | if (ret != 0) |
| 1227 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1228 | if (newstate != state) |
| 1229 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1230 | } |
| 1231 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1232 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1233 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | if (ret != 0) |
| 1235 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1236 | if (newstate != state) |
| 1237 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1238 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1239 | /* |
| 1240 | * We may have performed cached opens for all three recoveries. |
| 1241 | * Check if we need to update the current stateid. |
| 1242 | */ |
| 1243 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1244 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1245 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1246 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1247 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1248 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1249 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1250 | return 0; |
| 1251 | } |
| 1252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | /* |
| 1254 | * OPEN_RECLAIM: |
| 1255 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1257 | 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] | 1258 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1259 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1260 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1261 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | int status; |
| 1263 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1264 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1265 | if (IS_ERR(opendata)) |
| 1266 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1267 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1268 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1269 | rcu_read_lock(); |
| 1270 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1271 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1272 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1273 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1274 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1275 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1276 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | return status; |
| 1278 | } |
| 1279 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1280 | 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] | 1281 | { |
| 1282 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1283 | struct nfs4_exception exception = { }; |
| 1284 | int err; |
| 1285 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1286 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1287 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1288 | break; |
| 1289 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | } while (exception.retry); |
| 1291 | return err; |
| 1292 | } |
| 1293 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1294 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1295 | { |
| 1296 | struct nfs_open_context *ctx; |
| 1297 | int ret; |
| 1298 | |
| 1299 | ctx = nfs4_state_find_open_context(state); |
| 1300 | if (IS_ERR(ctx)) |
| 1301 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1302 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1303 | put_nfs_open_context(ctx); |
| 1304 | return ret; |
| 1305 | } |
| 1306 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1307 | 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] | 1308 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1309 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1310 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1312 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1313 | if (IS_ERR(opendata)) |
| 1314 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1315 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1316 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1317 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1318 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1319 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1322 | 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] | 1323 | { |
| 1324 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1325 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | int err; |
| 1327 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1328 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | switch (err) { |
| 1330 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1331 | case -ENOENT: |
| 1332 | case -ESTALE: |
| 1333 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1334 | case -NFS4ERR_BADSESSION: |
| 1335 | case -NFS4ERR_BADSLOT: |
| 1336 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1337 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1338 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1339 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1340 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | case -NFS4ERR_STALE_CLIENTID: |
| 1342 | case -NFS4ERR_STALE_STATEID: |
| 1343 | case -NFS4ERR_EXPIRED: |
| 1344 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1345 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1346 | goto out; |
| 1347 | case -ERESTARTSYS: |
| 1348 | /* |
| 1349 | * The show must go on: exit, but mark the |
| 1350 | * stateid as needing recovery. |
| 1351 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1352 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1353 | case -NFS4ERR_ADMIN_REVOKED: |
| 1354 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1355 | nfs_inode_find_state_and_recover(state->inode, |
| 1356 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1357 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1358 | case -EKEYEXPIRED: |
| 1359 | /* |
| 1360 | * User RPCSEC_GSS context has expired. |
| 1361 | * We cannot recover this stateid now, so |
| 1362 | * skip it and allow recovery thread to |
| 1363 | * proceed. |
| 1364 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1365 | case -ENOMEM: |
| 1366 | err = 0; |
| 1367 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | } |
| 1369 | err = nfs4_handle_exception(server, err, &exception); |
| 1370 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1371 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | return err; |
| 1373 | } |
| 1374 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1375 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1376 | { |
| 1377 | struct nfs4_opendata *data = calldata; |
| 1378 | |
| 1379 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1380 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1381 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1382 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1383 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1384 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1385 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static void nfs4_open_confirm_release(void *calldata) |
| 1389 | { |
| 1390 | struct nfs4_opendata *data = calldata; |
| 1391 | struct nfs4_state *state = NULL; |
| 1392 | |
| 1393 | /* If this request hasn't been cancelled, do nothing */ |
| 1394 | if (data->cancelled == 0) |
| 1395 | goto out_free; |
| 1396 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1397 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1399 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1400 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1401 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1402 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1403 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1407 | .rpc_call_done = nfs4_open_confirm_done, |
| 1408 | .rpc_release = nfs4_open_confirm_release, |
| 1409 | }; |
| 1410 | |
| 1411 | /* |
| 1412 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1413 | */ |
| 1414 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1415 | { |
| 1416 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1417 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1418 | struct rpc_message msg = { |
| 1419 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1420 | .rpc_argp = &data->c_arg, |
| 1421 | .rpc_resp = &data->c_res, |
| 1422 | .rpc_cred = data->owner->so_cred, |
| 1423 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1424 | struct rpc_task_setup task_setup_data = { |
| 1425 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1426 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1427 | .callback_ops = &nfs4_open_confirm_ops, |
| 1428 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1429 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1430 | .flags = RPC_TASK_ASYNC, |
| 1431 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | int status; |
| 1433 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1434 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1435 | data->rpc_done = 0; |
| 1436 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1437 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1438 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1439 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1440 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1441 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1442 | if (status != 0) { |
| 1443 | data->cancelled = 1; |
| 1444 | smp_wmb(); |
| 1445 | } else |
| 1446 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1447 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | return status; |
| 1449 | } |
| 1450 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1451 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1453 | struct nfs4_opendata *data = calldata; |
| 1454 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1455 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1456 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1457 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1458 | /* |
| 1459 | * Check if we still need to send an OPEN call, or if we can use |
| 1460 | * a delegation instead. |
| 1461 | */ |
| 1462 | if (data->state != NULL) { |
| 1463 | struct nfs_delegation *delegation; |
| 1464 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1465 | 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] | 1466 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1467 | rcu_read_lock(); |
| 1468 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1469 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1470 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1471 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1472 | rcu_read_unlock(); |
| 1473 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1474 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1475 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1476 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1477 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1478 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1479 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1480 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1481 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1482 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1483 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 1484 | &data->o_res.seq_res, |
| 1485 | task) != 0) |
| 1486 | nfs_release_seqid(data->o_arg.seqid); |
| 1487 | else |
| 1488 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1489 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1490 | unlock_no_action: |
| 1491 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1492 | out_no_action: |
| 1493 | task->tk_action = NULL; |
| 1494 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1497 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1498 | { |
| 1499 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1500 | nfs4_open_prepare(task, calldata); |
| 1501 | } |
| 1502 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1503 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1504 | { |
| 1505 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1507 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1508 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1509 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1510 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1511 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1512 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1513 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1514 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1515 | case S_IFREG: |
| 1516 | break; |
| 1517 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1518 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1519 | break; |
| 1520 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1522 | break; |
| 1523 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1524 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1525 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1526 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1527 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1528 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1529 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1530 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1531 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1532 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1533 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1534 | static void nfs4_open_release(void *calldata) |
| 1535 | { |
| 1536 | struct nfs4_opendata *data = calldata; |
| 1537 | struct nfs4_state *state = NULL; |
| 1538 | |
| 1539 | /* If this request hasn't been cancelled, do nothing */ |
| 1540 | if (data->cancelled == 0) |
| 1541 | goto out_free; |
| 1542 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1543 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | goto out_free; |
| 1545 | /* In case we need an open_confirm, no cleanup! */ |
| 1546 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1547 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1548 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1549 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1550 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1551 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1552 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1556 | .rpc_call_prepare = nfs4_open_prepare, |
| 1557 | .rpc_call_done = nfs4_open_done, |
| 1558 | .rpc_release = nfs4_open_release, |
| 1559 | }; |
| 1560 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1561 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1562 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1563 | .rpc_call_done = nfs4_open_done, |
| 1564 | .rpc_release = nfs4_open_release, |
| 1565 | }; |
| 1566 | |
| 1567 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1568 | { |
| 1569 | struct inode *dir = data->dir->d_inode; |
| 1570 | struct nfs_server *server = NFS_SERVER(dir); |
| 1571 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1572 | struct nfs_openres *o_res = &data->o_res; |
| 1573 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1574 | struct rpc_message msg = { |
| 1575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1576 | .rpc_argp = o_arg, |
| 1577 | .rpc_resp = o_res, |
| 1578 | .rpc_cred = data->owner->so_cred, |
| 1579 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1580 | struct rpc_task_setup task_setup_data = { |
| 1581 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1582 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1583 | .callback_ops = &nfs4_open_ops, |
| 1584 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1585 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1586 | .flags = RPC_TASK_ASYNC, |
| 1587 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1588 | int status; |
| 1589 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1590 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1591 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1592 | data->rpc_done = 0; |
| 1593 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1594 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1595 | if (isrecover) |
| 1596 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1597 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1598 | if (IS_ERR(task)) |
| 1599 | return PTR_ERR(task); |
| 1600 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1601 | if (status != 0) { |
| 1602 | data->cancelled = 1; |
| 1603 | smp_wmb(); |
| 1604 | } else |
| 1605 | status = data->rpc_status; |
| 1606 | rpc_put_task(task); |
| 1607 | |
| 1608 | return status; |
| 1609 | } |
| 1610 | |
| 1611 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1612 | { |
| 1613 | struct inode *dir = data->dir->d_inode; |
| 1614 | struct nfs_openres *o_res = &data->o_res; |
| 1615 | int status; |
| 1616 | |
| 1617 | status = nfs4_run_open_task(data, 1); |
| 1618 | if (status != 0 || !data->rpc_done) |
| 1619 | return status; |
| 1620 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1621 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1622 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1623 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1624 | status = _nfs4_proc_open_confirm(data); |
| 1625 | if (status != 0) |
| 1626 | return status; |
| 1627 | } |
| 1628 | |
| 1629 | return status; |
| 1630 | } |
| 1631 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1632 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1633 | struct nfs4_opendata *opendata, |
| 1634 | struct nfs4_state *state, fmode_t fmode) |
| 1635 | { |
| 1636 | struct nfs_access_entry cache; |
| 1637 | u32 mask; |
| 1638 | |
| 1639 | /* access call failed or for some reason the server doesn't |
| 1640 | * support any access modes -- defer access call until later */ |
| 1641 | if (opendata->o_res.access_supported == 0) |
| 1642 | return 0; |
| 1643 | |
| 1644 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1645 | /* don't check MAY_WRITE - a newly created file may not have |
| 1646 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1647 | if (fmode & FMODE_READ) |
| 1648 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1649 | if (fmode & FMODE_EXEC) |
| 1650 | mask |= MAY_EXEC; |
| 1651 | |
| 1652 | cache.cred = cred; |
| 1653 | cache.jiffies = jiffies; |
| 1654 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1655 | nfs_access_add_cache(state->inode, &cache); |
| 1656 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1657 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1658 | return 0; |
| 1659 | |
| 1660 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1661 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 1662 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1665 | /* |
| 1666 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1667 | */ |
| 1668 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1669 | { |
| 1670 | struct inode *dir = data->dir->d_inode; |
| 1671 | struct nfs_server *server = NFS_SERVER(dir); |
| 1672 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1673 | struct nfs_openres *o_res = &data->o_res; |
| 1674 | int status; |
| 1675 | |
| 1676 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1677 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1679 | if (status != 0) { |
| 1680 | if (status == -NFS4ERR_BADNAME && |
| 1681 | !(o_arg->open_flags & O_CREAT)) |
| 1682 | return -ENOENT; |
| 1683 | return status; |
| 1684 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1685 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1686 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1687 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1688 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1689 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1690 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1691 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1693 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1695 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1698 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1699 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1702 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1703 | { |
| 1704 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1705 | } |
| 1706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | /* |
| 1708 | * OPEN_EXPIRED: |
| 1709 | * reclaim state on the server after a network partition. |
| 1710 | * Assumes caller holds the appropriate lock |
| 1711 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1712 | 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] | 1713 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1714 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1715 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1717 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1718 | if (IS_ERR(opendata)) |
| 1719 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1720 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1721 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1722 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1723 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1724 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1727 | 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] | 1728 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1729 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1730 | struct nfs4_exception exception = { }; |
| 1731 | int err; |
| 1732 | |
| 1733 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1734 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1735 | switch (err) { |
| 1736 | default: |
| 1737 | goto out; |
| 1738 | case -NFS4ERR_GRACE: |
| 1739 | case -NFS4ERR_DELAY: |
| 1740 | nfs4_handle_exception(server, err, &exception); |
| 1741 | err = 0; |
| 1742 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1743 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1744 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1745 | return err; |
| 1746 | } |
| 1747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1749 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1751 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1753 | ctx = nfs4_state_find_open_context(state); |
| 1754 | if (IS_ERR(ctx)) |
| 1755 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1756 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1757 | put_nfs_open_context(ctx); |
| 1758 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1761 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1762 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1763 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1764 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1765 | nfs4_stateid *stateid = &state->stateid; |
| 1766 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1767 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1768 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1769 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1770 | return; |
| 1771 | |
| 1772 | status = nfs41_test_stateid(server, stateid); |
| 1773 | if (status != NFS_OK) { |
| 1774 | /* Free the stateid unless the server explicitly |
| 1775 | * informs us the stateid is unrecognized. */ |
| 1776 | if (status != -NFS4ERR_BAD_STATEID) |
| 1777 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1778 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1779 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1780 | write_seqlock(&state->seqlock); |
| 1781 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1782 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1783 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1789 | * |
| 1790 | * @state: NFSv4 state for an inode |
| 1791 | * |
| 1792 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1793 | * Otherwise a negative NFS4ERR value is returned. |
| 1794 | */ |
| 1795 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1796 | { |
| 1797 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1798 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1799 | int status; |
| 1800 | |
| 1801 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1802 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1803 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1804 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1805 | return -NFS4ERR_BAD_STATEID; |
| 1806 | |
| 1807 | status = nfs41_test_stateid(server, stateid); |
| 1808 | if (status != NFS_OK) { |
| 1809 | /* Free the stateid unless the server explicitly |
| 1810 | * informs us the stateid is unrecognized. */ |
| 1811 | if (status != -NFS4ERR_BAD_STATEID) |
| 1812 | nfs41_free_stateid(server, stateid); |
| 1813 | |
| 1814 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1815 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1816 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1817 | } |
| 1818 | return status; |
| 1819 | } |
| 1820 | |
| 1821 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1822 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1823 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1824 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1825 | nfs41_clear_delegation_stateid(state); |
| 1826 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1827 | if (status != NFS_OK) |
| 1828 | status = nfs4_open_expired(sp, state); |
| 1829 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1830 | } |
| 1831 | #endif |
| 1832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1834 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1835 | * fields corresponding to attributes that were used to store the verifier. |
| 1836 | * Make sure we clobber those fields in the later setattr call |
| 1837 | */ |
| 1838 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1839 | { |
| 1840 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1841 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1842 | sattr->ia_valid |= ATTR_ATIME; |
| 1843 | |
| 1844 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1845 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1846 | sattr->ia_valid |= ATTR_MTIME; |
| 1847 | } |
| 1848 | |
| 1849 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1850 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1852 | static int _nfs4_do_open(struct inode *dir, |
| 1853 | struct dentry *dentry, |
| 1854 | fmode_t fmode, |
| 1855 | int flags, |
| 1856 | struct iattr *sattr, |
| 1857 | struct rpc_cred *cred, |
| 1858 | struct nfs4_state **res, |
| 1859 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | { |
| 1861 | struct nfs4_state_owner *sp; |
| 1862 | struct nfs4_state *state = NULL; |
| 1863 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1864 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1865 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
| 1867 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1869 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1870 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1872 | goto out_err; |
| 1873 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1874 | status = nfs4_recover_expired_lease(server); |
| 1875 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1876 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1877 | if (dentry->d_inode != NULL) |
| 1878 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1879 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1880 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1881 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1882 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1884 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1885 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1886 | if (!opendata->f_attr.mdsthreshold) |
| 1887 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1888 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1889 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1890 | if (dentry->d_inode != NULL) |
| 1891 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1892 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1893 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1895 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1897 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1898 | status = PTR_ERR(state); |
| 1899 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1900 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1901 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1902 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1903 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1904 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 1905 | if (status != 0) |
| 1906 | goto err_opendata_put; |
| 1907 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1908 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1909 | nfs4_exclusive_attrset(opendata, sattr); |
| 1910 | |
| 1911 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1912 | status = nfs4_do_setattr(state->inode, cred, |
| 1913 | opendata->o_res.f_attr, sattr, |
| 1914 | state); |
| 1915 | if (status == 0) |
| 1916 | nfs_setattr_update_inode(state->inode, sattr); |
| 1917 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1918 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1919 | |
| 1920 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1921 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1922 | else |
| 1923 | kfree(opendata->f_attr.mdsthreshold); |
| 1924 | opendata->f_attr.mdsthreshold = NULL; |
| 1925 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1926 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | *res = state; |
| 1929 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1930 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1931 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1932 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1933 | err_put_state_owner: |
| 1934 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | *res = NULL; |
| 1937 | return status; |
| 1938 | } |
| 1939 | |
| 1940 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1941 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1942 | struct dentry *dentry, |
| 1943 | fmode_t fmode, |
| 1944 | int flags, |
| 1945 | struct iattr *sattr, |
| 1946 | struct rpc_cred *cred, |
| 1947 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | { |
| 1949 | struct nfs4_exception exception = { }; |
| 1950 | struct nfs4_state *res; |
| 1951 | int status; |
| 1952 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1953 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1955 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1956 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | if (status == 0) |
| 1958 | break; |
| 1959 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1960 | * book-keeping w.r.t. state-changing operations |
| 1961 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1962 | * It is actually a sign of a bug on the client or on the server. |
| 1963 | * |
| 1964 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1965 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | * have unhashed the old state_owner for us, and that we can |
| 1967 | * therefore safely retry using a new one. We should still warn |
| 1968 | * the user though... |
| 1969 | */ |
| 1970 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1971 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1972 | " returned a bad sequence-id error!\n", |
| 1973 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | exception.retry = 1; |
| 1975 | continue; |
| 1976 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1977 | /* |
| 1978 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1979 | * state before it received the OPEN_CONFIRM. |
| 1980 | * Recover by retrying the request as per the discussion |
| 1981 | * on Page 181 of RFC3530. |
| 1982 | */ |
| 1983 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1984 | exception.retry = 1; |
| 1985 | continue; |
| 1986 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1987 | if (status == -EAGAIN) { |
| 1988 | /* We must have found a delegation */ |
| 1989 | exception.retry = 1; |
| 1990 | continue; |
| 1991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1993 | status, &exception)); |
| 1994 | } while (exception.retry); |
| 1995 | return res; |
| 1996 | } |
| 1997 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1998 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1999 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2000 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2002 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2004 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | .iap = sattr, |
| 2006 | .server = server, |
| 2007 | .bitmask = server->attr_bitmask, |
| 2008 | }; |
| 2009 | struct nfs_setattrres res = { |
| 2010 | .fattr = fattr, |
| 2011 | .server = server, |
| 2012 | }; |
| 2013 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2015 | .rpc_argp = &arg, |
| 2016 | .rpc_resp = &res, |
| 2017 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2019 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2020 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2022 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2024 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2025 | struct nfs_lockowner lockowner = { |
| 2026 | .l_owner = current->files, |
| 2027 | .l_pid = current->tgid, |
| 2028 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2029 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2030 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2031 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2032 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2033 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2034 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2035 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2037 | 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] | 2038 | if (status == 0 && state != NULL) |
| 2039 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2040 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2043 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2044 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2045 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2047 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2048 | struct nfs4_exception exception = { |
| 2049 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2050 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2051 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | int err; |
| 2053 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2054 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2055 | switch (err) { |
| 2056 | case -NFS4ERR_OPENMODE: |
| 2057 | if (state && !(state->state & FMODE_WRITE)) { |
| 2058 | err = -EBADF; |
| 2059 | if (sattr->ia_valid & ATTR_OPEN) |
| 2060 | err = -EACCES; |
| 2061 | goto out; |
| 2062 | } |
| 2063 | } |
| 2064 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2066 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | return err; |
| 2068 | } |
| 2069 | |
| 2070 | struct nfs4_closedata { |
| 2071 | struct inode *inode; |
| 2072 | struct nfs4_state *state; |
| 2073 | struct nfs_closeargs arg; |
| 2074 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2075 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2076 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2077 | bool roc; |
| 2078 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | }; |
| 2080 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2081 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2082 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2083 | struct nfs4_closedata *calldata = data; |
| 2084 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2085 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2086 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2087 | if (calldata->roc) |
| 2088 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2089 | nfs4_put_open_state(calldata->state); |
| 2090 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2091 | nfs4_put_state_owner(sp); |
Weston Andros Adamson | 324d003 | 2012-10-30 17:01:39 -0400 | [diff] [blame] | 2092 | nfs_sb_deactive_async(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2093 | kfree(calldata); |
| 2094 | } |
| 2095 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2096 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2097 | fmode_t fmode) |
| 2098 | { |
| 2099 | spin_lock(&state->owner->so_lock); |
| 2100 | if (!(fmode & FMODE_READ)) |
| 2101 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2102 | if (!(fmode & FMODE_WRITE)) |
| 2103 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2104 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2105 | spin_unlock(&state->owner->so_lock); |
| 2106 | } |
| 2107 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2108 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2110 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2113 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2114 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2115 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2116 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | /* hmm. we are done with the inode, and in the process of freeing |
| 2118 | * the state_owner. we keep this around to process errors |
| 2119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | switch (task->tk_status) { |
| 2121 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2122 | if (calldata->roc) |
| 2123 | pnfs_roc_set_barrier(state->inode, |
| 2124 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2125 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2126 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2127 | nfs4_close_clear_stateid_flags(state, |
| 2128 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | break; |
| 2130 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2131 | case -NFS4ERR_OLD_STATEID: |
| 2132 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2134 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2135 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2137 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2138 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2140 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2141 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2142 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2145 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2147 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2148 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2149 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2150 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2151 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2152 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2153 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2154 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2155 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2156 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2157 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2158 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2159 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2160 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2161 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2162 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2163 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2164 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2165 | } |
| 2166 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2167 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2168 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2169 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2170 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2171 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2172 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2173 | |
| 2174 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2175 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2176 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2177 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2178 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2179 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2180 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2181 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2182 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2183 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2184 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2185 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2186 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2187 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2188 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2189 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2190 | &calldata->arg.seq_args, |
| 2191 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2192 | task) != 0) |
| 2193 | nfs_release_seqid(calldata->arg.seqid); |
| 2194 | else |
| 2195 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2196 | out: |
| 2197 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2200 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2201 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2202 | .rpc_call_done = nfs4_close_done, |
| 2203 | .rpc_release = nfs4_free_closedata, |
| 2204 | }; |
| 2205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | /* |
| 2207 | * It is possible for data to be read/written from a mem-mapped file |
| 2208 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2209 | * This means that we can't safely call nfsv4 close on a file until |
| 2210 | * the inode is cleared. This in turn means that we are not good |
| 2211 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2212 | * share state even when we are done with one of the three share |
| 2213 | * stateid's in the inode. |
| 2214 | * |
| 2215 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2216 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2217 | 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] | 2218 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2219 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2221 | struct nfs4_state_owner *sp = state->owner; |
| 2222 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2223 | struct rpc_message msg = { |
| 2224 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2225 | .rpc_cred = state->owner->so_cred, |
| 2226 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2227 | struct rpc_task_setup task_setup_data = { |
| 2228 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2229 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2230 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2231 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2232 | .flags = RPC_TASK_ASYNC, |
| 2233 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2234 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2236 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2238 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2239 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2240 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2242 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2243 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2245 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2246 | if (calldata->arg.seqid == NULL) |
| 2247 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2248 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2249 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2250 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2251 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2252 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2253 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2254 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2255 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2256 | msg.rpc_argp = &calldata->arg; |
| 2257 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2258 | task_setup_data.callback_data = calldata; |
| 2259 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2260 | if (IS_ERR(task)) |
| 2261 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2262 | status = 0; |
| 2263 | if (wait) |
| 2264 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2265 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2266 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2267 | out_free_calldata: |
| 2268 | kfree(calldata); |
| 2269 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2270 | nfs4_put_open_state(state); |
| 2271 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2272 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2275 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2276 | 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] | 2277 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | struct nfs4_state *state; |
| 2279 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2280 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2281 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2282 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2283 | if (IS_ERR(state)) |
| 2284 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2285 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2286 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2289 | 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] | 2290 | { |
| 2291 | if (ctx->state == NULL) |
| 2292 | return; |
| 2293 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2294 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2295 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2296 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
| 2299 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2300 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2301 | struct nfs4_server_caps_arg args = { |
| 2302 | .fhandle = fhandle, |
| 2303 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | struct nfs4_server_caps_res res = {}; |
| 2305 | struct rpc_message msg = { |
| 2306 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2307 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | .rpc_resp = &res, |
| 2309 | }; |
| 2310 | int status; |
| 2311 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2312 | 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] | 2313 | if (status == 0) { |
| 2314 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2315 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2316 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2317 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2318 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2319 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2321 | server->caps |= NFS_CAP_ACLS; |
| 2322 | if (res.has_links != 0) |
| 2323 | server->caps |= NFS_CAP_HARDLINKS; |
| 2324 | if (res.has_symlinks != 0) |
| 2325 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2326 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2327 | server->caps |= NFS_CAP_FILEID; |
| 2328 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2329 | server->caps |= NFS_CAP_MODE; |
| 2330 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2331 | server->caps |= NFS_CAP_NLINK; |
| 2332 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2333 | server->caps |= NFS_CAP_OWNER; |
| 2334 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2335 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2336 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2337 | server->caps |= NFS_CAP_ATIME; |
| 2338 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2339 | server->caps |= NFS_CAP_CTIME; |
| 2340 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2341 | server->caps |= NFS_CAP_MTIME; |
| 2342 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2343 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2344 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2345 | 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] | 2346 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2347 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | return status; |
| 2351 | } |
| 2352 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2353 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | { |
| 2355 | struct nfs4_exception exception = { }; |
| 2356 | int err; |
| 2357 | do { |
| 2358 | err = nfs4_handle_exception(server, |
| 2359 | _nfs4_server_capabilities(server, fhandle), |
| 2360 | &exception); |
| 2361 | } while (exception.retry); |
| 2362 | return err; |
| 2363 | } |
| 2364 | |
| 2365 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2366 | struct nfs_fsinfo *info) |
| 2367 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | struct nfs4_lookup_root_arg args = { |
| 2369 | .bitmask = nfs4_fattr_bitmap, |
| 2370 | }; |
| 2371 | struct nfs4_lookup_res res = { |
| 2372 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2373 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | .fh = fhandle, |
| 2375 | }; |
| 2376 | struct rpc_message msg = { |
| 2377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2378 | .rpc_argp = &args, |
| 2379 | .rpc_resp = &res, |
| 2380 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2381 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2382 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2383 | 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] | 2384 | } |
| 2385 | |
| 2386 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2387 | struct nfs_fsinfo *info) |
| 2388 | { |
| 2389 | struct nfs4_exception exception = { }; |
| 2390 | int err; |
| 2391 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2392 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2393 | switch (err) { |
| 2394 | case 0: |
| 2395 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2396 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2397 | default: |
| 2398 | err = nfs4_handle_exception(server, err, &exception); |
| 2399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2401 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | return err; |
| 2403 | } |
| 2404 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2405 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2406 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2407 | { |
| 2408 | struct rpc_auth *auth; |
| 2409 | int ret; |
| 2410 | |
| 2411 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2412 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2413 | ret = -EIO; |
| 2414 | goto out; |
| 2415 | } |
| 2416 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2417 | out: |
| 2418 | return ret; |
| 2419 | } |
| 2420 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2421 | 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] | 2422 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2424 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2425 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2427 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 2428 | if (len < 0) |
| 2429 | return len; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2430 | |
| 2431 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2432 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2433 | * thus has already been tried. */ |
| 2434 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2435 | continue; |
| 2436 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2437 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2438 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2439 | continue; |
| 2440 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2441 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2442 | /* |
| 2443 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2444 | * to access the mount. It could also mean that we tried to mount |
| 2445 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2446 | * existing mount programs don't handle -EACCES very well so it should |
| 2447 | * be mapped to -EPERM instead. |
| 2448 | */ |
| 2449 | if (status == -EACCES) |
| 2450 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2451 | return status; |
| 2452 | } |
| 2453 | |
| 2454 | /* |
| 2455 | * get the file handle for the "/" directory on the server |
| 2456 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2457 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2458 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2459 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2460 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2461 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2462 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2463 | /* |
| 2464 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2465 | * by nfs4_map_errors() as this function exits. |
| 2466 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2467 | 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] | 2468 | if (status == 0) |
| 2469 | status = nfs4_server_capabilities(server, fhandle); |
| 2470 | if (status == 0) |
| 2471 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2472 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2475 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2476 | struct nfs_fsinfo *info) |
| 2477 | { |
| 2478 | int error; |
| 2479 | struct nfs_fattr *fattr = info->fattr; |
| 2480 | |
| 2481 | error = nfs4_server_capabilities(server, mntfh); |
| 2482 | if (error < 0) { |
| 2483 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2484 | return error; |
| 2485 | } |
| 2486 | |
| 2487 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2488 | if (error < 0) { |
| 2489 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2490 | return error; |
| 2491 | } |
| 2492 | |
| 2493 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2494 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2495 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2496 | |
| 2497 | return error; |
| 2498 | } |
| 2499 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2500 | /* |
| 2501 | * Get locations and (maybe) other attributes of a referral. |
| 2502 | * Note that we'll actually follow the referral later when |
| 2503 | * we detect fsid mismatch in inode revalidation |
| 2504 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2505 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2506 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2507 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2508 | { |
| 2509 | int status = -ENOMEM; |
| 2510 | struct page *page = NULL; |
| 2511 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2512 | |
| 2513 | page = alloc_page(GFP_KERNEL); |
| 2514 | if (page == NULL) |
| 2515 | goto out; |
| 2516 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2517 | if (locations == NULL) |
| 2518 | goto out; |
| 2519 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2520 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2521 | if (status != 0) |
| 2522 | goto out; |
| 2523 | /* Make sure server returned a different fsid for the referral */ |
| 2524 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2525 | dprintk("%s: server did not return a different fsid for" |
| 2526 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2527 | status = -EIO; |
| 2528 | goto out; |
| 2529 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2530 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2531 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2532 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2533 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2534 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2535 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2536 | out: |
| 2537 | if (page) |
| 2538 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2539 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2540 | return status; |
| 2541 | } |
| 2542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2544 | { |
| 2545 | struct nfs4_getattr_arg args = { |
| 2546 | .fh = fhandle, |
| 2547 | .bitmask = server->attr_bitmask, |
| 2548 | }; |
| 2549 | struct nfs4_getattr_res res = { |
| 2550 | .fattr = fattr, |
| 2551 | .server = server, |
| 2552 | }; |
| 2553 | struct rpc_message msg = { |
| 2554 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2555 | .rpc_argp = &args, |
| 2556 | .rpc_resp = &res, |
| 2557 | }; |
| 2558 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2559 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2560 | 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] | 2561 | } |
| 2562 | |
| 2563 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2564 | { |
| 2565 | struct nfs4_exception exception = { }; |
| 2566 | int err; |
| 2567 | do { |
| 2568 | err = nfs4_handle_exception(server, |
| 2569 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2570 | &exception); |
| 2571 | } while (exception.retry); |
| 2572 | return err; |
| 2573 | } |
| 2574 | |
| 2575 | /* |
| 2576 | * The file is not closed if it is opened due to the a request to change |
| 2577 | * the size of the file. The open call will not be needed once the |
| 2578 | * VFS layer lookup-intents are implemented. |
| 2579 | * |
| 2580 | * Close is called when the inode is destroyed. |
| 2581 | * If we haven't opened the file for O_WRONLY, we |
| 2582 | * need to in the size_change case to obtain a stateid. |
| 2583 | * |
| 2584 | * Got race? |
| 2585 | * Because OPEN is always done by name in nfsv4, it is |
| 2586 | * possible that we opened a different file by the same |
| 2587 | * name. We can recognize this race condition, but we |
| 2588 | * can't do anything about it besides returning an error. |
| 2589 | * |
| 2590 | * This will be fixed with VFS changes (lookup-intent). |
| 2591 | */ |
| 2592 | static int |
| 2593 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2594 | struct iattr *sattr) |
| 2595 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2596 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2597 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2598 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | int status; |
| 2600 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2601 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2602 | pnfs_return_layout(inode); |
| 2603 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2604 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2606 | /* Deal with open(O_TRUNC) */ |
| 2607 | if (sattr->ia_valid & ATTR_OPEN) |
| 2608 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2609 | |
| 2610 | /* Optimization: if the end result is no change, don't RPC */ |
| 2611 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2612 | return 0; |
| 2613 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2614 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2615 | if (sattr->ia_valid & ATTR_FILE) { |
| 2616 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2617 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2618 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2619 | if (ctx) { |
| 2620 | cred = ctx->cred; |
| 2621 | state = ctx->state; |
| 2622 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2626 | if (status == 0) |
| 2627 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | return status; |
| 2629 | } |
| 2630 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2631 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2632 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2633 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2634 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2635 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2636 | int status; |
| 2637 | struct nfs4_lookup_arg args = { |
| 2638 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2639 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2640 | .name = name, |
| 2641 | }; |
| 2642 | struct nfs4_lookup_res res = { |
| 2643 | .server = server, |
| 2644 | .fattr = fattr, |
| 2645 | .fh = fhandle, |
| 2646 | }; |
| 2647 | struct rpc_message msg = { |
| 2648 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2649 | .rpc_argp = &args, |
| 2650 | .rpc_resp = &res, |
| 2651 | }; |
| 2652 | |
| 2653 | nfs_fattr_init(fattr); |
| 2654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2656 | 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] | 2657 | dprintk("NFS reply lookup: %d\n", status); |
| 2658 | return status; |
| 2659 | } |
| 2660 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2661 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2662 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2663 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2664 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2665 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2666 | fattr->nlink = 2; |
| 2667 | } |
| 2668 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2669 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2670 | struct qstr *name, struct nfs_fh *fhandle, |
| 2671 | struct nfs_fattr *fattr) |
| 2672 | { |
| 2673 | struct nfs4_exception exception = { }; |
| 2674 | struct rpc_clnt *client = *clnt; |
| 2675 | int err; |
| 2676 | do { |
| 2677 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2678 | switch (err) { |
| 2679 | case -NFS4ERR_BADNAME: |
| 2680 | err = -ENOENT; |
| 2681 | goto out; |
| 2682 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2683 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2684 | goto out; |
| 2685 | case -NFS4ERR_WRONGSEC: |
| 2686 | err = -EPERM; |
| 2687 | if (client != *clnt) |
| 2688 | goto out; |
| 2689 | |
| 2690 | client = nfs4_create_sec_client(client, dir, name); |
| 2691 | if (IS_ERR(client)) |
| 2692 | return PTR_ERR(client); |
| 2693 | |
| 2694 | exception.retry = 1; |
| 2695 | break; |
| 2696 | default: |
| 2697 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2698 | } |
| 2699 | } while (exception.retry); |
| 2700 | |
| 2701 | out: |
| 2702 | if (err == 0) |
| 2703 | *clnt = client; |
| 2704 | else if (client != *clnt) |
| 2705 | rpc_shutdown_client(client); |
| 2706 | |
| 2707 | return err; |
| 2708 | } |
| 2709 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2710 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2711 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2713 | int status; |
| 2714 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2715 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2716 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2717 | if (client != NFS_CLIENT(dir)) { |
| 2718 | rpc_shutdown_client(client); |
| 2719 | nfs_fixup_secinfo_attributes(fattr); |
| 2720 | } |
| 2721 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2724 | struct rpc_clnt * |
| 2725 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2726 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2727 | { |
| 2728 | int status; |
| 2729 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2730 | |
| 2731 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2732 | if (status < 0) { |
| 2733 | rpc_shutdown_client(client); |
| 2734 | return ERR_PTR(status); |
| 2735 | } |
| 2736 | return client; |
| 2737 | } |
| 2738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2740 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2741 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | struct nfs4_accessargs args = { |
| 2743 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2744 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2746 | struct nfs4_accessres res = { |
| 2747 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2748 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | struct rpc_message msg = { |
| 2750 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2751 | .rpc_argp = &args, |
| 2752 | .rpc_resp = &res, |
| 2753 | .rpc_cred = entry->cred, |
| 2754 | }; |
| 2755 | int mode = entry->mask; |
| 2756 | int status; |
| 2757 | |
| 2758 | /* |
| 2759 | * Determine which access bits we want to ask for... |
| 2760 | */ |
| 2761 | if (mode & MAY_READ) |
| 2762 | args.access |= NFS4_ACCESS_READ; |
| 2763 | if (S_ISDIR(inode->i_mode)) { |
| 2764 | if (mode & MAY_WRITE) |
| 2765 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2766 | if (mode & MAY_EXEC) |
| 2767 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2768 | } else { |
| 2769 | if (mode & MAY_WRITE) |
| 2770 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2771 | if (mode & MAY_EXEC) |
| 2772 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2773 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2774 | |
| 2775 | res.fattr = nfs_alloc_fattr(); |
| 2776 | if (res.fattr == NULL) |
| 2777 | return -ENOMEM; |
| 2778 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2779 | 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] | 2780 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2781 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2782 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2784 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | return status; |
| 2786 | } |
| 2787 | |
| 2788 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2789 | { |
| 2790 | struct nfs4_exception exception = { }; |
| 2791 | int err; |
| 2792 | do { |
| 2793 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2794 | _nfs4_proc_access(inode, entry), |
| 2795 | &exception); |
| 2796 | } while (exception.retry); |
| 2797 | return err; |
| 2798 | } |
| 2799 | |
| 2800 | /* |
| 2801 | * TODO: For the time being, we don't try to get any attributes |
| 2802 | * along with any of the zero-copy operations READ, READDIR, |
| 2803 | * READLINK, WRITE. |
| 2804 | * |
| 2805 | * In the case of the first three, we want to put the GETATTR |
| 2806 | * after the read-type operation -- this is because it is hard |
| 2807 | * to predict the length of a GETATTR response in v4, and thus |
| 2808 | * align the READ data correctly. This means that the GETATTR |
| 2809 | * may end up partially falling into the page cache, and we should |
| 2810 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2811 | * To do this efficiently, we need to know the total length |
| 2812 | * of data received, which doesn't seem to be available outside |
| 2813 | * of the RPC layer. |
| 2814 | * |
| 2815 | * In the case of WRITE, we also want to put the GETATTR after |
| 2816 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2817 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | * |
| 2819 | * Both of these changes to the XDR layer would in fact be quite |
| 2820 | * minor, but I decided to leave them for a subsequent patch. |
| 2821 | */ |
| 2822 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2823 | unsigned int pgbase, unsigned int pglen) |
| 2824 | { |
| 2825 | struct nfs4_readlink args = { |
| 2826 | .fh = NFS_FH(inode), |
| 2827 | .pgbase = pgbase, |
| 2828 | .pglen = pglen, |
| 2829 | .pages = &page, |
| 2830 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2831 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | struct rpc_message msg = { |
| 2833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2834 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2835 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | }; |
| 2837 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2838 | 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] | 2839 | } |
| 2840 | |
| 2841 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2842 | unsigned int pgbase, unsigned int pglen) |
| 2843 | { |
| 2844 | struct nfs4_exception exception = { }; |
| 2845 | int err; |
| 2846 | do { |
| 2847 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2848 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2849 | &exception); |
| 2850 | } while (exception.retry); |
| 2851 | return err; |
| 2852 | } |
| 2853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2855 | * 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] | 2856 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | static int |
| 2858 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2859 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2861 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | int status = 0; |
| 2864 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2865 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2866 | if (IS_ERR(ctx)) |
| 2867 | return PTR_ERR(ctx); |
| 2868 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2869 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2870 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2871 | flags, sattr, ctx->cred, |
| 2872 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2873 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | if (IS_ERR(state)) { |
| 2875 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2876 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2878 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2879 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2880 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2882 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | return status; |
| 2884 | } |
| 2885 | |
| 2886 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2887 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2888 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2889 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2891 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2893 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2894 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2895 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2897 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2898 | .rpc_argp = &args, |
| 2899 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2901 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2902 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2903 | 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] | 2904 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2905 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | return status; |
| 2907 | } |
| 2908 | |
| 2909 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2910 | { |
| 2911 | struct nfs4_exception exception = { }; |
| 2912 | int err; |
| 2913 | do { |
| 2914 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2915 | _nfs4_proc_remove(dir, name), |
| 2916 | &exception); |
| 2917 | } while (exception.retry); |
| 2918 | return err; |
| 2919 | } |
| 2920 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2921 | 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] | 2922 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2923 | struct nfs_server *server = NFS_SERVER(dir); |
| 2924 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2925 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2927 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2929 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2932 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2933 | { |
| 2934 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2935 | &data->args.seq_args, |
| 2936 | &data->res.seq_res, |
| 2937 | task)) |
| 2938 | return; |
| 2939 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2942 | 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] | 2943 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2944 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2945 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2946 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2947 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2948 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2949 | return 0; |
| 2950 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2951 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2954 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2955 | { |
| 2956 | struct nfs_server *server = NFS_SERVER(dir); |
| 2957 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2958 | struct nfs_renameres *res = msg->rpc_resp; |
| 2959 | |
| 2960 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2961 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2962 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2963 | } |
| 2964 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2965 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2966 | { |
| 2967 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2968 | &data->args.seq_args, |
| 2969 | &data->res.seq_res, |
| 2970 | task)) |
| 2971 | return; |
| 2972 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2976 | struct inode *new_dir) |
| 2977 | { |
| 2978 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2979 | |
| 2980 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2981 | return 0; |
| 2982 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2983 | return 0; |
| 2984 | |
| 2985 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2986 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2987 | return 1; |
| 2988 | } |
| 2989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2991 | struct inode *new_dir, struct qstr *new_name) |
| 2992 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2993 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2994 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | .old_dir = NFS_FH(old_dir), |
| 2996 | .new_dir = NFS_FH(new_dir), |
| 2997 | .old_name = old_name, |
| 2998 | .new_name = new_name, |
| 2999 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3000 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3001 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3002 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | struct rpc_message msg = { |
| 3004 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3005 | .rpc_argp = &arg, |
| 3006 | .rpc_resp = &res, |
| 3007 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3008 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3010 | 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] | 3011 | if (!status) { |
| 3012 | update_changeattr(old_dir, &res.old_cinfo); |
| 3013 | update_changeattr(new_dir, &res.new_cinfo); |
| 3014 | } |
| 3015 | return status; |
| 3016 | } |
| 3017 | |
| 3018 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3019 | struct inode *new_dir, struct qstr *new_name) |
| 3020 | { |
| 3021 | struct nfs4_exception exception = { }; |
| 3022 | int err; |
| 3023 | do { |
| 3024 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3025 | _nfs4_proc_rename(old_dir, old_name, |
| 3026 | new_dir, new_name), |
| 3027 | &exception); |
| 3028 | } while (exception.retry); |
| 3029 | return err; |
| 3030 | } |
| 3031 | |
| 3032 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3033 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3034 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | struct nfs4_link_arg arg = { |
| 3036 | .fh = NFS_FH(inode), |
| 3037 | .dir_fh = NFS_FH(dir), |
| 3038 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3039 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3041 | struct nfs4_link_res res = { |
| 3042 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3043 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | struct rpc_message msg = { |
| 3045 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3046 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3047 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3049 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3051 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3052 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3053 | goto out; |
| 3054 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3055 | 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] | 3056 | if (!status) { |
| 3057 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3058 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3059 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3060 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3061 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | return status; |
| 3063 | } |
| 3064 | |
| 3065 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3066 | { |
| 3067 | struct nfs4_exception exception = { }; |
| 3068 | int err; |
| 3069 | do { |
| 3070 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3071 | _nfs4_proc_link(inode, dir, name), |
| 3072 | &exception); |
| 3073 | } while (exception.retry); |
| 3074 | return err; |
| 3075 | } |
| 3076 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3077 | struct nfs4_createdata { |
| 3078 | struct rpc_message msg; |
| 3079 | struct nfs4_create_arg arg; |
| 3080 | struct nfs4_create_res res; |
| 3081 | struct nfs_fh fh; |
| 3082 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3083 | }; |
| 3084 | |
| 3085 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3086 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3087 | { |
| 3088 | struct nfs4_createdata *data; |
| 3089 | |
| 3090 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3091 | if (data != NULL) { |
| 3092 | struct nfs_server *server = NFS_SERVER(dir); |
| 3093 | |
| 3094 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3095 | data->msg.rpc_argp = &data->arg; |
| 3096 | data->msg.rpc_resp = &data->res; |
| 3097 | data->arg.dir_fh = NFS_FH(dir); |
| 3098 | data->arg.server = server; |
| 3099 | data->arg.name = name; |
| 3100 | data->arg.attrs = sattr; |
| 3101 | data->arg.ftype = ftype; |
| 3102 | data->arg.bitmask = server->attr_bitmask; |
| 3103 | data->res.server = server; |
| 3104 | data->res.fh = &data->fh; |
| 3105 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3106 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3107 | } |
| 3108 | return data; |
| 3109 | } |
| 3110 | |
| 3111 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3112 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3113 | 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] | 3114 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3115 | if (status == 0) { |
| 3116 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3117 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3118 | } |
| 3119 | return status; |
| 3120 | } |
| 3121 | |
| 3122 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3123 | { |
| 3124 | kfree(data); |
| 3125 | } |
| 3126 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3127 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3128 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3130 | struct nfs4_createdata *data; |
| 3131 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3133 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3134 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3135 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3136 | status = -ENOMEM; |
| 3137 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3138 | if (data == NULL) |
| 3139 | goto out; |
| 3140 | |
| 3141 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3142 | data->arg.u.symlink.pages = &page; |
| 3143 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3145 | status = nfs4_do_create(dir, dentry, data); |
| 3146 | |
| 3147 | nfs4_free_createdata(data); |
| 3148 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | return status; |
| 3150 | } |
| 3151 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3152 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3153 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | { |
| 3155 | struct nfs4_exception exception = { }; |
| 3156 | int err; |
| 3157 | do { |
| 3158 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3159 | _nfs4_proc_symlink(dir, dentry, page, |
| 3160 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | &exception); |
| 3162 | } while (exception.retry); |
| 3163 | return err; |
| 3164 | } |
| 3165 | |
| 3166 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3167 | struct iattr *sattr) |
| 3168 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3169 | struct nfs4_createdata *data; |
| 3170 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3172 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3173 | if (data == NULL) |
| 3174 | goto out; |
| 3175 | |
| 3176 | status = nfs4_do_create(dir, dentry, data); |
| 3177 | |
| 3178 | nfs4_free_createdata(data); |
| 3179 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | return status; |
| 3181 | } |
| 3182 | |
| 3183 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3184 | struct iattr *sattr) |
| 3185 | { |
| 3186 | struct nfs4_exception exception = { }; |
| 3187 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3188 | |
| 3189 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | do { |
| 3191 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3192 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3193 | &exception); |
| 3194 | } while (exception.retry); |
| 3195 | return err; |
| 3196 | } |
| 3197 | |
| 3198 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3199 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | { |
| 3201 | struct inode *dir = dentry->d_inode; |
| 3202 | struct nfs4_readdir_arg args = { |
| 3203 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3204 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | .pgbase = 0, |
| 3206 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3207 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3208 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | }; |
| 3210 | struct nfs4_readdir_res res; |
| 3211 | struct rpc_message msg = { |
| 3212 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3213 | .rpc_argp = &args, |
| 3214 | .rpc_resp = &res, |
| 3215 | .rpc_cred = cred, |
| 3216 | }; |
| 3217 | int status; |
| 3218 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3219 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3220 | dentry->d_parent->d_name.name, |
| 3221 | dentry->d_name.name, |
| 3222 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3223 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3225 | 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] | 3226 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3227 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3228 | status += args.pgbase; |
| 3229 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3230 | |
| 3231 | nfs_invalidate_atime(dir); |
| 3232 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3233 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | return status; |
| 3235 | } |
| 3236 | |
| 3237 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3238 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | { |
| 3240 | struct nfs4_exception exception = { }; |
| 3241 | int err; |
| 3242 | do { |
| 3243 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3244 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3245 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | &exception); |
| 3247 | } while (exception.retry); |
| 3248 | return err; |
| 3249 | } |
| 3250 | |
| 3251 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3252 | struct iattr *sattr, dev_t rdev) |
| 3253 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3254 | struct nfs4_createdata *data; |
| 3255 | int mode = sattr->ia_mode; |
| 3256 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3258 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3259 | if (data == NULL) |
| 3260 | goto out; |
| 3261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3263 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3265 | data->arg.ftype = NF4BLK; |
| 3266 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3267 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | } |
| 3269 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3270 | data->arg.ftype = NF4CHR; |
| 3271 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3272 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3273 | } else if (!S_ISSOCK(mode)) { |
| 3274 | status = -EINVAL; |
| 3275 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3278 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 3279 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3280 | nfs4_free_createdata(data); |
| 3281 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | return status; |
| 3283 | } |
| 3284 | |
| 3285 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3286 | struct iattr *sattr, dev_t rdev) |
| 3287 | { |
| 3288 | struct nfs4_exception exception = { }; |
| 3289 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3290 | |
| 3291 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | do { |
| 3293 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3294 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3295 | &exception); |
| 3296 | } while (exception.retry); |
| 3297 | return err; |
| 3298 | } |
| 3299 | |
| 3300 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3301 | struct nfs_fsstat *fsstat) |
| 3302 | { |
| 3303 | struct nfs4_statfs_arg args = { |
| 3304 | .fh = fhandle, |
| 3305 | .bitmask = server->attr_bitmask, |
| 3306 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3307 | struct nfs4_statfs_res res = { |
| 3308 | .fsstat = fsstat, |
| 3309 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | struct rpc_message msg = { |
| 3311 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3312 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3313 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | }; |
| 3315 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3316 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3317 | 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] | 3318 | } |
| 3319 | |
| 3320 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3321 | { |
| 3322 | struct nfs4_exception exception = { }; |
| 3323 | int err; |
| 3324 | do { |
| 3325 | err = nfs4_handle_exception(server, |
| 3326 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3327 | &exception); |
| 3328 | } while (exception.retry); |
| 3329 | return err; |
| 3330 | } |
| 3331 | |
| 3332 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3333 | struct nfs_fsinfo *fsinfo) |
| 3334 | { |
| 3335 | struct nfs4_fsinfo_arg args = { |
| 3336 | .fh = fhandle, |
| 3337 | .bitmask = server->attr_bitmask, |
| 3338 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3339 | struct nfs4_fsinfo_res res = { |
| 3340 | .fsinfo = fsinfo, |
| 3341 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | struct rpc_message msg = { |
| 3343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3344 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3345 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | }; |
| 3347 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3348 | 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] | 3349 | } |
| 3350 | |
| 3351 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3352 | { |
| 3353 | struct nfs4_exception exception = { }; |
| 3354 | int err; |
| 3355 | |
| 3356 | do { |
| 3357 | err = nfs4_handle_exception(server, |
| 3358 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3359 | &exception); |
| 3360 | } while (exception.retry); |
| 3361 | return err; |
| 3362 | } |
| 3363 | |
| 3364 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3365 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3366 | int error; |
| 3367 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3368 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3369 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3370 | if (error == 0) { |
| 3371 | /* block layout checks this! */ |
| 3372 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3373 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3374 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3375 | |
| 3376 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3380 | struct nfs_pathconf *pathconf) |
| 3381 | { |
| 3382 | struct nfs4_pathconf_arg args = { |
| 3383 | .fh = fhandle, |
| 3384 | .bitmask = server->attr_bitmask, |
| 3385 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3386 | struct nfs4_pathconf_res res = { |
| 3387 | .pathconf = pathconf, |
| 3388 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | struct rpc_message msg = { |
| 3390 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3391 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3392 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | }; |
| 3394 | |
| 3395 | /* None of the pathconf attributes are mandatory to implement */ |
| 3396 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3397 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3398 | return 0; |
| 3399 | } |
| 3400 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3401 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3402 | 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] | 3403 | } |
| 3404 | |
| 3405 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3406 | struct nfs_pathconf *pathconf) |
| 3407 | { |
| 3408 | struct nfs4_exception exception = { }; |
| 3409 | int err; |
| 3410 | |
| 3411 | do { |
| 3412 | err = nfs4_handle_exception(server, |
| 3413 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3414 | &exception); |
| 3415 | } while (exception.retry); |
| 3416 | return err; |
| 3417 | } |
| 3418 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3419 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3420 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3421 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3422 | } |
| 3423 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3424 | 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] | 3425 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3426 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3428 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3429 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3430 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3432 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3433 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3435 | renew_lease(server, data->timestamp); |
| 3436 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3439 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3440 | { |
| 3441 | |
| 3442 | dprintk("--> %s\n", __func__); |
| 3443 | |
| 3444 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3445 | return -EAGAIN; |
| 3446 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3447 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3448 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3451 | 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] | 3452 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3454 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3455 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3456 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3459 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3460 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3461 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3462 | &data->args.seq_args, |
| 3463 | &data->res.seq_res, |
| 3464 | task)) |
| 3465 | return; |
| 3466 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3469 | 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] | 3470 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3471 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3473 | 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] | 3474 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3475 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3477 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3479 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3480 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3481 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3484 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3485 | { |
| 3486 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3487 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3488 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3489 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3492 | static |
| 3493 | 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] | 3494 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3495 | const struct nfs_pgio_header *hdr = data->header; |
| 3496 | |
| 3497 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3498 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3499 | return false; |
| 3500 | /* Otherwise, request attributes if and only if we don't hold |
| 3501 | * a delegation |
| 3502 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3503 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3504 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3505 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3506 | 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] | 3507 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3508 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3509 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3510 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3511 | data->args.bitmask = NULL; |
| 3512 | data->res.fattr = NULL; |
| 3513 | } else |
| 3514 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3515 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3516 | if (!data->write_done_cb) |
| 3517 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3518 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | data->timestamp = jiffies; |
| 3520 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3521 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3522 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3525 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3526 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3527 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3528 | &data->args.seq_args, |
| 3529 | &data->res.seq_res, |
| 3530 | task)) |
| 3531 | return; |
| 3532 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3535 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3536 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3538 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3539 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | return; |
| 3542 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3543 | } |
| 3544 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3545 | 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] | 3546 | { |
| 3547 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3548 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3549 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3550 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3551 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3553 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3556 | 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] | 3557 | { |
| 3558 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3559 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3560 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3563 | 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] | 3564 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3565 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3566 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3567 | if (data->commit_done_cb == NULL) |
| 3568 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3569 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3570 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3571 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3574 | struct nfs4_renewdata { |
| 3575 | struct nfs_client *client; |
| 3576 | unsigned long timestamp; |
| 3577 | }; |
| 3578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | /* |
| 3580 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3581 | * standalone procedure for queueing an asynchronous RENEW. |
| 3582 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3583 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3584 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3585 | struct nfs4_renewdata *data = calldata; |
| 3586 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3587 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3588 | if (atomic_read(&clp->cl_count) > 1) |
| 3589 | nfs4_schedule_state_renewal(clp); |
| 3590 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3591 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3592 | } |
| 3593 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3594 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3596 | struct nfs4_renewdata *data = calldata; |
| 3597 | struct nfs_client *clp = data->client; |
| 3598 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | |
| 3600 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3601 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3602 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3603 | return; |
| 3604 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3605 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3606 | return; |
| 3607 | } |
| 3608 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3610 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3613 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3614 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3615 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3616 | }; |
| 3617 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3618 | 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] | 3619 | { |
| 3620 | struct rpc_message msg = { |
| 3621 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3622 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3623 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3625 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3627 | if (renew_flags == 0) |
| 3628 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3629 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3630 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3631 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3632 | if (data == NULL) |
| 3633 | return -ENOMEM; |
| 3634 | data->client = clp; |
| 3635 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3637 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3640 | 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] | 3641 | { |
| 3642 | struct rpc_message msg = { |
| 3643 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3644 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3645 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | }; |
| 3647 | unsigned long now = jiffies; |
| 3648 | int status; |
| 3649 | |
| 3650 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3651 | if (status < 0) |
| 3652 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3653 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | return 0; |
| 3655 | } |
| 3656 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3657 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3658 | { |
| 3659 | return (server->caps & NFS_CAP_ACLS) |
| 3660 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3661 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3662 | } |
| 3663 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3664 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3665 | * 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] | 3666 | * the stack. |
| 3667 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3668 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3669 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3670 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3671 | struct page **pages, unsigned int *pgbase) |
| 3672 | { |
| 3673 | struct page *newpage, **spages; |
| 3674 | int rc = 0; |
| 3675 | size_t len; |
| 3676 | spages = pages; |
| 3677 | |
| 3678 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3679 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3680 | newpage = alloc_page(GFP_KERNEL); |
| 3681 | |
| 3682 | if (newpage == NULL) |
| 3683 | goto unwind; |
| 3684 | memcpy(page_address(newpage), buf, len); |
| 3685 | buf += len; |
| 3686 | buflen -= len; |
| 3687 | *pages++ = newpage; |
| 3688 | rc++; |
| 3689 | } while (buflen != 0); |
| 3690 | |
| 3691 | return rc; |
| 3692 | |
| 3693 | unwind: |
| 3694 | for(; rc > 0; rc--) |
| 3695 | __free_page(spages[rc-1]); |
| 3696 | return -ENOMEM; |
| 3697 | } |
| 3698 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3699 | struct nfs4_cached_acl { |
| 3700 | int cached; |
| 3701 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3702 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3703 | }; |
| 3704 | |
| 3705 | 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] | 3706 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3707 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3708 | |
| 3709 | spin_lock(&inode->i_lock); |
| 3710 | kfree(nfsi->nfs4_acl); |
| 3711 | nfsi->nfs4_acl = acl; |
| 3712 | spin_unlock(&inode->i_lock); |
| 3713 | } |
| 3714 | |
| 3715 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3716 | { |
| 3717 | nfs4_set_cached_acl(inode, NULL); |
| 3718 | } |
| 3719 | |
| 3720 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3721 | { |
| 3722 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3723 | struct nfs4_cached_acl *acl; |
| 3724 | int ret = -ENOENT; |
| 3725 | |
| 3726 | spin_lock(&inode->i_lock); |
| 3727 | acl = nfsi->nfs4_acl; |
| 3728 | if (acl == NULL) |
| 3729 | goto out; |
| 3730 | if (buf == NULL) /* user is just asking for length */ |
| 3731 | goto out_len; |
| 3732 | if (acl->cached == 0) |
| 3733 | goto out; |
| 3734 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3735 | if (acl->len > buflen) |
| 3736 | goto out; |
| 3737 | memcpy(buf, acl->data, acl->len); |
| 3738 | out_len: |
| 3739 | ret = acl->len; |
| 3740 | out: |
| 3741 | spin_unlock(&inode->i_lock); |
| 3742 | return ret; |
| 3743 | } |
| 3744 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3745 | 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] | 3746 | { |
| 3747 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3748 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3749 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3750 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3751 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3752 | if (acl == NULL) |
| 3753 | goto out; |
| 3754 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3755 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3756 | } else { |
| 3757 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3758 | if (acl == NULL) |
| 3759 | goto out; |
| 3760 | acl->cached = 0; |
| 3761 | } |
| 3762 | acl->len = acl_len; |
| 3763 | out: |
| 3764 | nfs4_set_cached_acl(inode, acl); |
| 3765 | } |
| 3766 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3767 | /* |
| 3768 | * The getxattr API returns the required buffer length when called with a |
| 3769 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3770 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3771 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3772 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3773 | * the cache. If not so, we throw away the page, and cache the required |
| 3774 | * length. The next getxattr call will then produce another round trip to |
| 3775 | * the server, this time with the input buf of the required size. |
| 3776 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3777 | 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] | 3778 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3779 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3780 | struct nfs_getaclargs args = { |
| 3781 | .fh = NFS_FH(inode), |
| 3782 | .acl_pages = pages, |
| 3783 | .acl_len = buflen, |
| 3784 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3785 | struct nfs_getaclres res = { |
| 3786 | .acl_len = buflen, |
| 3787 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3788 | struct rpc_message msg = { |
| 3789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3790 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3791 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3792 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3793 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3794 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3795 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3796 | /* As long as we're doing a round trip to the server anyway, |
| 3797 | * let's be prepared for a page of acl data. */ |
| 3798 | if (npages == 0) |
| 3799 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3800 | if (npages > ARRAY_SIZE(pages)) |
| 3801 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3802 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3803 | for (i = 0; i < npages; i++) { |
| 3804 | pages[i] = alloc_page(GFP_KERNEL); |
| 3805 | if (!pages[i]) |
| 3806 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3807 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3808 | |
| 3809 | /* for decoding across pages */ |
| 3810 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3811 | if (!res.acl_scratch) |
| 3812 | goto out_free; |
| 3813 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3814 | args.acl_len = npages * PAGE_SIZE; |
| 3815 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3816 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3817 | 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] | 3818 | __func__, buf, buflen, npages, args.acl_len); |
| 3819 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3820 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3821 | if (ret) |
| 3822 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3823 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3824 | /* Handle the case where the passed-in buffer is too short */ |
| 3825 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3826 | /* Did the user only issue a request for the acl length? */ |
| 3827 | if (buf == NULL) |
| 3828 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3829 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3830 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3831 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3832 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3833 | if (buf) |
| 3834 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3835 | out_ok: |
| 3836 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3837 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3838 | for (i = 0; i < npages; i++) |
| 3839 | if (pages[i]) |
| 3840 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3841 | if (res.acl_scratch) |
| 3842 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3843 | return ret; |
| 3844 | } |
| 3845 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3846 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3847 | { |
| 3848 | struct nfs4_exception exception = { }; |
| 3849 | ssize_t ret; |
| 3850 | do { |
| 3851 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3852 | if (ret >= 0) |
| 3853 | break; |
| 3854 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3855 | } while (exception.retry); |
| 3856 | return ret; |
| 3857 | } |
| 3858 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3859 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3860 | { |
| 3861 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3862 | int ret; |
| 3863 | |
| 3864 | if (!nfs4_server_supports_acls(server)) |
| 3865 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3866 | ret = nfs_revalidate_inode(server, inode); |
| 3867 | if (ret < 0) |
| 3868 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3869 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3870 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3871 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3872 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3873 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3874 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3875 | return ret; |
| 3876 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3879 | 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] | 3880 | { |
| 3881 | struct nfs_server *server = NFS_SERVER(inode); |
| 3882 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3883 | struct nfs_setaclargs arg = { |
| 3884 | .fh = NFS_FH(inode), |
| 3885 | .acl_pages = pages, |
| 3886 | .acl_len = buflen, |
| 3887 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3888 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3889 | struct rpc_message msg = { |
| 3890 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3891 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3892 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3893 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3894 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3895 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3896 | |
| 3897 | if (!nfs4_server_supports_acls(server)) |
| 3898 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3899 | if (npages > ARRAY_SIZE(pages)) |
| 3900 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3901 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3902 | if (i < 0) |
| 3903 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3904 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3905 | 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] | 3906 | |
| 3907 | /* |
| 3908 | * Free each page after tx, so the only ref left is |
| 3909 | * held by the network stack |
| 3910 | */ |
| 3911 | for (; i > 0; i--) |
| 3912 | put_page(pages[i-1]); |
| 3913 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3914 | /* |
| 3915 | * Acl update can result in inode attribute update. |
| 3916 | * so mark the attribute cache invalid. |
| 3917 | */ |
| 3918 | spin_lock(&inode->i_lock); |
| 3919 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3920 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3921 | nfs_access_zap_cache(inode); |
| 3922 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3923 | return ret; |
| 3924 | } |
| 3925 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3926 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3927 | { |
| 3928 | struct nfs4_exception exception = { }; |
| 3929 | int err; |
| 3930 | do { |
| 3931 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3932 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3933 | &exception); |
| 3934 | } while (exception.retry); |
| 3935 | return err; |
| 3936 | } |
| 3937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3939 | 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] | 3940 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3941 | struct nfs_client *clp = server->nfs_client; |
| 3942 | |
| 3943 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | return 0; |
| 3945 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3946 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3947 | case -NFS4ERR_ADMIN_REVOKED: |
| 3948 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3949 | if (state == NULL) |
| 3950 | break; |
| 3951 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3952 | case -NFS4ERR_OPENMODE: |
| 3953 | if (state == NULL) |
| 3954 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3955 | nfs4_schedule_stateid_recovery(server, state); |
| 3956 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3957 | case -NFS4ERR_EXPIRED: |
| 3958 | if (state != NULL) |
| 3959 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3961 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3962 | nfs4_schedule_lease_recovery(clp); |
| 3963 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3964 | #if defined(CONFIG_NFS_V4_1) |
| 3965 | case -NFS4ERR_BADSESSION: |
| 3966 | case -NFS4ERR_BADSLOT: |
| 3967 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3968 | case -NFS4ERR_DEADSESSION: |
| 3969 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3970 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3971 | case -NFS4ERR_SEQ_MISORDERED: |
| 3972 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3973 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3974 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3975 | task->tk_status = 0; |
| 3976 | return -EAGAIN; |
| 3977 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3979 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3980 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3981 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3983 | task->tk_status = 0; |
| 3984 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3985 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | case -NFS4ERR_OLD_STATEID: |
| 3987 | task->tk_status = 0; |
| 3988 | return -EAGAIN; |
| 3989 | } |
| 3990 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3991 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3992 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3993 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3994 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3995 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3996 | task->tk_status = 0; |
| 3997 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4000 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4001 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4002 | { |
| 4003 | __be32 verf[2]; |
| 4004 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4005 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4006 | /* An impossible timestamp guarantees this value |
| 4007 | * will never match a generated boot time. */ |
| 4008 | verf[0] = 0; |
| 4009 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4010 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4011 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4012 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4013 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4014 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4015 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4016 | } |
| 4017 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4018 | static unsigned int |
| 4019 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4020 | char *buf, size_t len) |
| 4021 | { |
| 4022 | unsigned int result; |
| 4023 | |
| 4024 | rcu_read_lock(); |
| 4025 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4026 | clp->cl_ipaddr, |
| 4027 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4028 | RPC_DISPLAY_ADDR), |
| 4029 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4030 | RPC_DISPLAY_PROTO)); |
| 4031 | rcu_read_unlock(); |
| 4032 | return result; |
| 4033 | } |
| 4034 | |
| 4035 | static unsigned int |
| 4036 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4037 | char *buf, size_t len) |
| 4038 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4039 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4040 | |
| 4041 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4042 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4043 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4044 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4045 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4046 | } |
| 4047 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4048 | /** |
| 4049 | * nfs4_proc_setclientid - Negotiate client ID |
| 4050 | * @clp: state data structure |
| 4051 | * @program: RPC program for NFSv4 callback service |
| 4052 | * @port: IP port number for NFS4 callback service |
| 4053 | * @cred: RPC credential to use for this call |
| 4054 | * @res: where to place the result |
| 4055 | * |
| 4056 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4057 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4058 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4059 | unsigned short port, struct rpc_cred *cred, |
| 4060 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | { |
| 4062 | nfs4_verifier sc_verifier; |
| 4063 | struct nfs4_setclientid setclientid = { |
| 4064 | .sc_verifier = &sc_verifier, |
| 4065 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4066 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | }; |
| 4068 | struct rpc_message msg = { |
| 4069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4070 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4071 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4072 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4074 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4076 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4077 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4078 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4079 | setclientid.sc_name_len = |
| 4080 | nfs4_init_uniform_client_string(clp, |
| 4081 | setclientid.sc_name, |
| 4082 | sizeof(setclientid.sc_name)); |
| 4083 | else |
| 4084 | setclientid.sc_name_len = |
| 4085 | nfs4_init_nonuniform_client_string(clp, |
| 4086 | setclientid.sc_name, |
| 4087 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4088 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4089 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4090 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4091 | sizeof(setclientid.sc_netid), |
| 4092 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4093 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4094 | rcu_read_unlock(); |
| 4095 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4096 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4098 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4099 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4100 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4101 | setclientid.sc_name_len, setclientid.sc_name); |
| 4102 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4103 | dprintk("NFS reply setclientid: %d\n", status); |
| 4104 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4107 | /** |
| 4108 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4109 | * @clp: state data structure |
| 4110 | * @res: result of a previous SETCLIENTID |
| 4111 | * @cred: RPC credential to use for this call |
| 4112 | * |
| 4113 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4114 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4115 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4116 | struct nfs4_setclientid_res *arg, |
| 4117 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | { |
| 4119 | struct nfs_fsinfo fsinfo; |
| 4120 | struct rpc_message msg = { |
| 4121 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4122 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4124 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | }; |
| 4126 | unsigned long now; |
| 4127 | int status; |
| 4128 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4129 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4130 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4131 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4133 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | if (status == 0) { |
| 4135 | spin_lock(&clp->cl_lock); |
| 4136 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4137 | clp->cl_last_renewal = now; |
| 4138 | spin_unlock(&clp->cl_lock); |
| 4139 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4140 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | return status; |
| 4142 | } |
| 4143 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4144 | struct nfs4_delegreturndata { |
| 4145 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4146 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4147 | struct nfs_fh fh; |
| 4148 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4149 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4150 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4151 | int rpc_status; |
| 4152 | }; |
| 4153 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4154 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4155 | { |
| 4156 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4157 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4158 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4159 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4160 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4161 | switch (task->tk_status) { |
| 4162 | case -NFS4ERR_STALE_STATEID: |
| 4163 | case -NFS4ERR_EXPIRED: |
| 4164 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4165 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4166 | break; |
| 4167 | default: |
| 4168 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4169 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4170 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4171 | return; |
| 4172 | } |
| 4173 | } |
| 4174 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | static void nfs4_delegreturn_release(void *calldata) |
| 4178 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4179 | kfree(calldata); |
| 4180 | } |
| 4181 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4182 | #if defined(CONFIG_NFS_V4_1) |
| 4183 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4184 | { |
| 4185 | struct nfs4_delegreturndata *d_data; |
| 4186 | |
| 4187 | d_data = (struct nfs4_delegreturndata *)data; |
| 4188 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4189 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4190 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4191 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4192 | return; |
| 4193 | rpc_call_start(task); |
| 4194 | } |
| 4195 | #endif /* CONFIG_NFS_V4_1 */ |
| 4196 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4197 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4198 | #if defined(CONFIG_NFS_V4_1) |
| 4199 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4200 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4201 | .rpc_call_done = nfs4_delegreturn_done, |
| 4202 | .rpc_release = nfs4_delegreturn_release, |
| 4203 | }; |
| 4204 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4205 | 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] | 4206 | { |
| 4207 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4208 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4209 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4210 | struct rpc_message msg = { |
| 4211 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4212 | .rpc_cred = cred, |
| 4213 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4214 | struct rpc_task_setup task_setup_data = { |
| 4215 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4216 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4217 | .callback_ops = &nfs4_delegreturn_ops, |
| 4218 | .flags = RPC_TASK_ASYNC, |
| 4219 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4220 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4221 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4222 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4223 | if (data == NULL) |
| 4224 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4225 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4226 | data->args.fhandle = &data->fh; |
| 4227 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4228 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4229 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4230 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4231 | data->res.fattr = &data->fattr; |
| 4232 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4233 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4234 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4235 | data->rpc_status = 0; |
| 4236 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4237 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4238 | msg.rpc_argp = &data->args; |
| 4239 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4240 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4241 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4242 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4243 | if (!issync) |
| 4244 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4245 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4246 | if (status != 0) |
| 4247 | goto out; |
| 4248 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4249 | if (status == 0) |
| 4250 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4251 | else |
| 4252 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4253 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4254 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4255 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4258 | 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] | 4259 | { |
| 4260 | struct nfs_server *server = NFS_SERVER(inode); |
| 4261 | struct nfs4_exception exception = { }; |
| 4262 | int err; |
| 4263 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4264 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | switch (err) { |
| 4266 | case -NFS4ERR_STALE_STATEID: |
| 4267 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | case 0: |
| 4269 | return 0; |
| 4270 | } |
| 4271 | err = nfs4_handle_exception(server, err, &exception); |
| 4272 | } while (exception.retry); |
| 4273 | return err; |
| 4274 | } |
| 4275 | |
| 4276 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4277 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4278 | |
| 4279 | /* |
| 4280 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4281 | */ |
| 4282 | static unsigned long |
| 4283 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4284 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4285 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | timeout <<= 1; |
| 4287 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4288 | return NFS4_LOCK_MAXTIMEOUT; |
| 4289 | return timeout; |
| 4290 | } |
| 4291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4293 | { |
| 4294 | struct inode *inode = state->inode; |
| 4295 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4296 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4297 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4299 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4301 | struct nfs_lockt_res res = { |
| 4302 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | }; |
| 4304 | struct rpc_message msg = { |
| 4305 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4306 | .rpc_argp = &arg, |
| 4307 | .rpc_resp = &res, |
| 4308 | .rpc_cred = state->owner->so_cred, |
| 4309 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | struct nfs4_lock_state *lsp; |
| 4311 | int status; |
| 4312 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4313 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4314 | status = nfs4_set_lock_state(state, request); |
| 4315 | if (status != 0) |
| 4316 | goto out; |
| 4317 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4318 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4319 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4320 | 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] | 4321 | switch (status) { |
| 4322 | case 0: |
| 4323 | request->fl_type = F_UNLCK; |
| 4324 | break; |
| 4325 | case -NFS4ERR_DENIED: |
| 4326 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4328 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4329 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | return status; |
| 4331 | } |
| 4332 | |
| 4333 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4334 | { |
| 4335 | struct nfs4_exception exception = { }; |
| 4336 | int err; |
| 4337 | |
| 4338 | do { |
| 4339 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4340 | _nfs4_proc_getlk(state, cmd, request), |
| 4341 | &exception); |
| 4342 | } while (exception.retry); |
| 4343 | return err; |
| 4344 | } |
| 4345 | |
| 4346 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4347 | { |
| 4348 | int res = 0; |
| 4349 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4350 | case FL_POSIX: |
| 4351 | res = posix_lock_file_wait(file, fl); |
| 4352 | break; |
| 4353 | case FL_FLOCK: |
| 4354 | res = flock_lock_file_wait(file, fl); |
| 4355 | break; |
| 4356 | default: |
| 4357 | BUG(); |
| 4358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | return res; |
| 4360 | } |
| 4361 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4362 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4363 | struct nfs_locku_args arg; |
| 4364 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4365 | struct nfs4_lock_state *lsp; |
| 4366 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4367 | struct file_lock fl; |
| 4368 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4369 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4370 | }; |
| 4371 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4372 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4373 | struct nfs_open_context *ctx, |
| 4374 | struct nfs4_lock_state *lsp, |
| 4375 | struct nfs_seqid *seqid) |
| 4376 | { |
| 4377 | struct nfs4_unlockdata *p; |
| 4378 | struct inode *inode = lsp->ls_state->inode; |
| 4379 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4380 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4381 | if (p == NULL) |
| 4382 | return NULL; |
| 4383 | p->arg.fh = NFS_FH(inode); |
| 4384 | p->arg.fl = &p->fl; |
| 4385 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4386 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4387 | p->arg.stateid = &lsp->ls_stateid; |
| 4388 | p->lsp = lsp; |
| 4389 | atomic_inc(&lsp->ls_count); |
| 4390 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4391 | p->ctx = get_nfs_open_context(ctx); |
| 4392 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4393 | p->server = NFS_SERVER(inode); |
| 4394 | return p; |
| 4395 | } |
| 4396 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4397 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4398 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4399 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4400 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4401 | nfs4_put_lock_state(calldata->lsp); |
| 4402 | put_nfs_open_context(calldata->ctx); |
| 4403 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4406 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4407 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4408 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4409 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4410 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4411 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4412 | switch (task->tk_status) { |
| 4413 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4414 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4415 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4416 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4417 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4418 | case -NFS4ERR_BAD_STATEID: |
| 4419 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4420 | case -NFS4ERR_STALE_STATEID: |
| 4421 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4422 | break; |
| 4423 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4424 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4425 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4426 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 4427 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4428 | } |
| 4429 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4430 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4431 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4432 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4434 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4435 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4436 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4437 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4438 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4439 | return; |
| 4440 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4441 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4442 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4443 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4444 | &calldata->res.seq_res, |
| 4445 | task) != 0) |
| 4446 | nfs_release_seqid(calldata->arg.seqid); |
| 4447 | else |
| 4448 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | } |
| 4450 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4451 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4452 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4453 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4454 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4455 | }; |
| 4456 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4457 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4458 | struct nfs_open_context *ctx, |
| 4459 | struct nfs4_lock_state *lsp, |
| 4460 | struct nfs_seqid *seqid) |
| 4461 | { |
| 4462 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4463 | struct rpc_message msg = { |
| 4464 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4465 | .rpc_cred = ctx->cred, |
| 4466 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4467 | struct rpc_task_setup task_setup_data = { |
| 4468 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4469 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4470 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4471 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4472 | .flags = RPC_TASK_ASYNC, |
| 4473 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4474 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4475 | /* Ensure this is an unlock - when canceling a lock, the |
| 4476 | * canceled lock is passed in, and it won't be an unlock. |
| 4477 | */ |
| 4478 | fl->fl_type = F_UNLCK; |
| 4479 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4480 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4481 | if (data == NULL) { |
| 4482 | nfs_free_seqid(seqid); |
| 4483 | return ERR_PTR(-ENOMEM); |
| 4484 | } |
| 4485 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4486 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4487 | msg.rpc_argp = &data->arg; |
| 4488 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4489 | task_setup_data.callback_data = data; |
| 4490 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4494 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4495 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4496 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4497 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4498 | struct rpc_task *task; |
| 4499 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4500 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4502 | status = nfs4_set_lock_state(state, request); |
| 4503 | /* Unlock _before_ we do the RPC call */ |
| 4504 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4505 | down_read(&nfsi->rwsem); |
| 4506 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4507 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4508 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4509 | } |
| 4510 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4511 | if (status != 0) |
| 4512 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4513 | /* Is this a delegated lock? */ |
| 4514 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4515 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4516 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4517 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4518 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4519 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4520 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4521 | 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] | 4522 | status = PTR_ERR(task); |
| 4523 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4524 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4525 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4526 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4527 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4528 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4529 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4532 | struct nfs4_lockdata { |
| 4533 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4534 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4535 | struct nfs4_lock_state *lsp; |
| 4536 | struct nfs_open_context *ctx; |
| 4537 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4538 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4539 | int rpc_status; |
| 4540 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4541 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4542 | }; |
| 4543 | |
| 4544 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4545 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4546 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4547 | { |
| 4548 | struct nfs4_lockdata *p; |
| 4549 | struct inode *inode = lsp->ls_state->inode; |
| 4550 | struct nfs_server *server = NFS_SERVER(inode); |
| 4551 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4552 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4553 | if (p == NULL) |
| 4554 | return NULL; |
| 4555 | |
| 4556 | p->arg.fh = NFS_FH(inode); |
| 4557 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4558 | 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] | 4559 | if (p->arg.open_seqid == NULL) |
| 4560 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4561 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4562 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4563 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4564 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4565 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4566 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4567 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4568 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4569 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4570 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4571 | atomic_inc(&lsp->ls_count); |
| 4572 | p->ctx = get_nfs_open_context(ctx); |
| 4573 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4574 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4575 | out_free_seqid: |
| 4576 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4577 | out_free: |
| 4578 | kfree(p); |
| 4579 | return NULL; |
| 4580 | } |
| 4581 | |
| 4582 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4583 | { |
| 4584 | struct nfs4_lockdata *data = calldata; |
| 4585 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4587 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4588 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4589 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4590 | /* Do we need to do an open_to_lock_owner? */ |
| 4591 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4592 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4593 | goto out_release_lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4594 | data->arg.open_stateid = &state->stateid; |
| 4595 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4596 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4597 | } else |
| 4598 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4599 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4600 | if (nfs4_setup_sequence(data->server, |
| 4601 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4602 | &data->res.seq_res, |
| 4603 | task) == 0) { |
| 4604 | rpc_call_start(task); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4605 | return; |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 4606 | } |
| 4607 | nfs_release_seqid(data->arg.open_seqid); |
| 4608 | out_release_lock_seqid: |
| 4609 | nfs_release_seqid(data->arg.lock_seqid); |
| 4610 | dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4611 | } |
| 4612 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4613 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4614 | { |
| 4615 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4616 | nfs4_lock_prepare(task, calldata); |
| 4617 | } |
| 4618 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4619 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4620 | { |
| 4621 | struct nfs4_lockdata *data = calldata; |
| 4622 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4623 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4624 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4625 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4626 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4627 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4628 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4629 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4630 | if (data->rpc_status == 0) |
| 4631 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4632 | else |
| 4633 | goto out; |
| 4634 | } |
| 4635 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4636 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4637 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4638 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4639 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4640 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4641 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | static void nfs4_lock_release(void *calldata) |
| 4645 | { |
| 4646 | struct nfs4_lockdata *data = calldata; |
| 4647 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4648 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4649 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4650 | if (data->cancelled != 0) { |
| 4651 | struct rpc_task *task; |
| 4652 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4653 | data->arg.lock_seqid); |
| 4654 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4655 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4656 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4657 | } else |
| 4658 | nfs_free_seqid(data->arg.lock_seqid); |
| 4659 | nfs4_put_lock_state(data->lsp); |
| 4660 | put_nfs_open_context(data->ctx); |
| 4661 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4662 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4666 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4667 | .rpc_call_done = nfs4_lock_done, |
| 4668 | .rpc_release = nfs4_lock_release, |
| 4669 | }; |
| 4670 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4671 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4672 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4673 | .rpc_call_done = nfs4_lock_done, |
| 4674 | .rpc_release = nfs4_lock_release, |
| 4675 | }; |
| 4676 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4677 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4678 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4679 | switch (error) { |
| 4680 | case -NFS4ERR_ADMIN_REVOKED: |
| 4681 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4682 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4683 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4684 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4685 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4686 | break; |
| 4687 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4688 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4689 | case -NFS4ERR_EXPIRED: |
| 4690 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4691 | }; |
| 4692 | } |
| 4693 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4694 | 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] | 4695 | { |
| 4696 | struct nfs4_lockdata *data; |
| 4697 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4698 | struct rpc_message msg = { |
| 4699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4700 | .rpc_cred = state->owner->so_cred, |
| 4701 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4702 | struct rpc_task_setup task_setup_data = { |
| 4703 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4704 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4705 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4706 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4707 | .flags = RPC_TASK_ASYNC, |
| 4708 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4709 | int ret; |
| 4710 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4711 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4712 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4713 | fl->fl_u.nfs4_fl.owner, |
| 4714 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4715 | if (data == NULL) |
| 4716 | return -ENOMEM; |
| 4717 | if (IS_SETLKW(cmd)) |
| 4718 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4719 | if (recovery_type > NFS_LOCK_NEW) { |
| 4720 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4721 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4722 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4723 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4724 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4725 | msg.rpc_argp = &data->arg; |
| 4726 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4727 | task_setup_data.callback_data = data; |
| 4728 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4729 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4730 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4731 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4732 | if (ret == 0) { |
| 4733 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4734 | if (ret) |
| 4735 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4736 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4737 | } else |
| 4738 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4739 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4740 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4741 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4745 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4746 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4747 | struct nfs4_exception exception = { |
| 4748 | .inode = state->inode, |
| 4749 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4750 | int err; |
| 4751 | |
| 4752 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4753 | /* Cache the lock if possible... */ |
| 4754 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4755 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4756 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4757 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4758 | break; |
| 4759 | nfs4_handle_exception(server, err, &exception); |
| 4760 | } while (exception.retry); |
| 4761 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4765 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4766 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4767 | struct nfs4_exception exception = { |
| 4768 | .inode = state->inode, |
| 4769 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4770 | int err; |
| 4771 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4772 | err = nfs4_set_lock_state(state, request); |
| 4773 | if (err != 0) |
| 4774 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4775 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4776 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4777 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4778 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4779 | switch (err) { |
| 4780 | default: |
| 4781 | goto out; |
| 4782 | case -NFS4ERR_GRACE: |
| 4783 | case -NFS4ERR_DELAY: |
| 4784 | nfs4_handle_exception(server, err, &exception); |
| 4785 | err = 0; |
| 4786 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4787 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4788 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4789 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | } |
| 4791 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4792 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4793 | /** |
| 4794 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4795 | * |
| 4796 | * @state: NFSv4 state for an inode |
| 4797 | * |
| 4798 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4799 | * Otherwise a negative NFS4ERR value is returned. |
| 4800 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4801 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4802 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4803 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4804 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4805 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4806 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4807 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4808 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4809 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4810 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4811 | /* Free the stateid unless the server |
| 4812 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4813 | if (status != -NFS4ERR_BAD_STATEID) |
| 4814 | nfs41_free_stateid(server, |
| 4815 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4816 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4817 | ret = status; |
| 4818 | } |
| 4819 | } |
| 4820 | }; |
| 4821 | |
| 4822 | return ret; |
| 4823 | } |
| 4824 | |
| 4825 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4826 | { |
| 4827 | int status = NFS_OK; |
| 4828 | |
| 4829 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4830 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4831 | if (status != NFS_OK) |
| 4832 | status = nfs4_lock_expired(state, request); |
| 4833 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4834 | } |
| 4835 | #endif |
| 4836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4838 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4839 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4840 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4841 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4843 | if ((fl_flags & FL_POSIX) && |
| 4844 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4845 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4846 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4847 | status = nfs4_set_lock_state(state, request); |
| 4848 | if (status != 0) |
| 4849 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4850 | request->fl_flags |= FL_ACCESS; |
| 4851 | status = do_vfs_lock(request->fl_file, request); |
| 4852 | if (status < 0) |
| 4853 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4854 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4855 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4856 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4857 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4858 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4859 | status = do_vfs_lock(request->fl_file, request); |
| 4860 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4861 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4862 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4863 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4864 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4865 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4866 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4867 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4868 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4869 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4870 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4871 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4872 | out: |
| 4873 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | return status; |
| 4875 | } |
| 4876 | |
| 4877 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4878 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4879 | struct nfs4_exception exception = { |
| 4880 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4881 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4882 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | int err; |
| 4884 | |
| 4885 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4886 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4887 | if (err == -NFS4ERR_DENIED) |
| 4888 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4890 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | } while (exception.retry); |
| 4892 | return err; |
| 4893 | } |
| 4894 | |
| 4895 | static int |
| 4896 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4897 | { |
| 4898 | struct nfs_open_context *ctx; |
| 4899 | struct nfs4_state *state; |
| 4900 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4901 | int status; |
| 4902 | |
| 4903 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4904 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | state = ctx->state; |
| 4906 | |
| 4907 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4908 | return -EINVAL; |
| 4909 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4910 | if (IS_GETLK(cmd)) { |
| 4911 | if (state != NULL) |
| 4912 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4913 | return 0; |
| 4914 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | |
| 4916 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4917 | return -EINVAL; |
| 4918 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4919 | if (request->fl_type == F_UNLCK) { |
| 4920 | if (state != NULL) |
| 4921 | return nfs4_proc_unlck(state, cmd, request); |
| 4922 | return 0; |
| 4923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4925 | if (state == NULL) |
| 4926 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4927 | /* |
| 4928 | * Don't rely on the VFS having checked the file open mode, |
| 4929 | * since it won't do this for flock() locks. |
| 4930 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4931 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4932 | case F_RDLCK: |
| 4933 | if (!(filp->f_mode & FMODE_READ)) |
| 4934 | return -EBADF; |
| 4935 | break; |
| 4936 | case F_WRLCK: |
| 4937 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4938 | return -EBADF; |
| 4939 | } |
| 4940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | do { |
| 4942 | status = nfs4_proc_setlk(state, cmd, request); |
| 4943 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4944 | break; |
| 4945 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4946 | status = -ERESTARTSYS; |
| 4947 | if (signalled()) |
| 4948 | break; |
| 4949 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | return status; |
| 4951 | } |
| 4952 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4953 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4954 | { |
| 4955 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4956 | struct nfs4_exception exception = { }; |
| 4957 | int err; |
| 4958 | |
| 4959 | err = nfs4_set_lock_state(state, fl); |
| 4960 | if (err != 0) |
| 4961 | goto out; |
| 4962 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4963 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4964 | switch (err) { |
| 4965 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4966 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4967 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4968 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4969 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4970 | goto out; |
| 4971 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4972 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4973 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4974 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4975 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4976 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4977 | case -NFS4ERR_BADSESSION: |
| 4978 | case -NFS4ERR_BADSLOT: |
| 4979 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4980 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4981 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4982 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4983 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4984 | case -ERESTARTSYS: |
| 4985 | /* |
| 4986 | * The show must go on: exit, but mark the |
| 4987 | * stateid as needing recovery. |
| 4988 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4989 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4990 | case -NFS4ERR_ADMIN_REVOKED: |
| 4991 | case -NFS4ERR_BAD_STATEID: |
| 4992 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4993 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4994 | err = 0; |
| 4995 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4996 | case -EKEYEXPIRED: |
| 4997 | /* |
| 4998 | * User RPCSEC_GSS context has expired. |
| 4999 | * We cannot recover this stateid now, so |
| 5000 | * skip it and allow recovery thread to |
| 5001 | * proceed. |
| 5002 | */ |
| 5003 | err = 0; |
| 5004 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5005 | case -ENOMEM: |
| 5006 | case -NFS4ERR_DENIED: |
| 5007 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5008 | err = 0; |
| 5009 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5010 | case -NFS4ERR_DELAY: |
| 5011 | break; |
| 5012 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5013 | err = nfs4_handle_exception(server, err, &exception); |
| 5014 | } while (exception.retry); |
| 5015 | out: |
| 5016 | return err; |
| 5017 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5018 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5019 | struct nfs_release_lockowner_data { |
| 5020 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5021 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5022 | struct nfs_release_lockowner_args args; |
| 5023 | }; |
| 5024 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5025 | static void nfs4_release_lockowner_release(void *calldata) |
| 5026 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5027 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5028 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5029 | kfree(calldata); |
| 5030 | } |
| 5031 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5032 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5033 | .rpc_release = nfs4_release_lockowner_release, |
| 5034 | }; |
| 5035 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5036 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5037 | { |
| 5038 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5039 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5040 | struct rpc_message msg = { |
| 5041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5042 | }; |
| 5043 | |
| 5044 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5045 | return -EINVAL; |
| 5046 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5047 | if (!data) |
| 5048 | return -ENOMEM; |
| 5049 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5050 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5051 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5052 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5053 | data->args.lock_owner.s_dev = server->s_dev; |
| 5054 | msg.rpc_argp = &data->args; |
| 5055 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5056 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5057 | } |
| 5058 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5059 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5060 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5061 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5062 | const void *buf, size_t buflen, |
| 5063 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5064 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5065 | if (strcmp(key, "") != 0) |
| 5066 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5067 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5068 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5071 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5072 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5073 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5074 | if (strcmp(key, "") != 0) |
| 5075 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5076 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5077 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5080 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5081 | size_t list_len, const char *name, |
| 5082 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5083 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5084 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5085 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5086 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5087 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5088 | |
| 5089 | if (list && len <= list_len) |
| 5090 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5091 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5094 | /* |
| 5095 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5096 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5097 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5098 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5099 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5100 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5101 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5102 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5103 | return; |
| 5104 | |
| 5105 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5106 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5107 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5108 | fattr->nlink = 2; |
| 5109 | } |
| 5110 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5111 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5112 | const struct qstr *name, |
| 5113 | struct nfs4_fs_locations *fs_locations, |
| 5114 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5115 | { |
| 5116 | struct nfs_server *server = NFS_SERVER(dir); |
| 5117 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5118 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5119 | }; |
| 5120 | struct nfs4_fs_locations_arg args = { |
| 5121 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5122 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5123 | .page = page, |
| 5124 | .bitmask = bitmask, |
| 5125 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5126 | struct nfs4_fs_locations_res res = { |
| 5127 | .fs_locations = fs_locations, |
| 5128 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5129 | struct rpc_message msg = { |
| 5130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5131 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5132 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5133 | }; |
| 5134 | int status; |
| 5135 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5136 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5137 | |
| 5138 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5139 | * is not supported */ |
| 5140 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5141 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5142 | else |
| 5143 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5144 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5145 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5146 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5147 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5148 | 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] | 5149 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5150 | return status; |
| 5151 | } |
| 5152 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5153 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5154 | const struct qstr *name, |
| 5155 | struct nfs4_fs_locations *fs_locations, |
| 5156 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5157 | { |
| 5158 | struct nfs4_exception exception = { }; |
| 5159 | int err; |
| 5160 | do { |
| 5161 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5162 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5163 | &exception); |
| 5164 | } while (exception.retry); |
| 5165 | return err; |
| 5166 | } |
| 5167 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5168 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5169 | { |
| 5170 | int status; |
| 5171 | struct nfs4_secinfo_arg args = { |
| 5172 | .dir_fh = NFS_FH(dir), |
| 5173 | .name = name, |
| 5174 | }; |
| 5175 | struct nfs4_secinfo_res res = { |
| 5176 | .flavors = flavors, |
| 5177 | }; |
| 5178 | struct rpc_message msg = { |
| 5179 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5180 | .rpc_argp = &args, |
| 5181 | .rpc_resp = &res, |
| 5182 | }; |
| 5183 | |
| 5184 | dprintk("NFS call secinfo %s\n", name->name); |
| 5185 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5186 | dprintk("NFS reply secinfo: %d\n", status); |
| 5187 | return status; |
| 5188 | } |
| 5189 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5190 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5191 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5192 | { |
| 5193 | struct nfs4_exception exception = { }; |
| 5194 | int err; |
| 5195 | do { |
| 5196 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5197 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5198 | &exception); |
| 5199 | } while (exception.retry); |
| 5200 | return err; |
| 5201 | } |
| 5202 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5203 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5204 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5205 | * Check the exchange flags returned by the server for invalid flags, having |
| 5206 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5207 | * DS flags set. |
| 5208 | */ |
| 5209 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5210 | { |
| 5211 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5212 | goto out_inval; |
| 5213 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5214 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5215 | goto out_inval; |
| 5216 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5217 | goto out_inval; |
| 5218 | return NFS_OK; |
| 5219 | out_inval: |
| 5220 | return -NFS4ERR_INVAL; |
| 5221 | } |
| 5222 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5223 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5224 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5225 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5226 | { |
| 5227 | if (a->server_scope_sz == b->server_scope_sz && |
| 5228 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5229 | return true; |
| 5230 | |
| 5231 | return false; |
| 5232 | } |
| 5233 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5234 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5235 | * nfs4_proc_bind_conn_to_session() |
| 5236 | * |
| 5237 | * The 4.1 client currently uses the same TCP connection for the |
| 5238 | * fore and backchannel. |
| 5239 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5240 | 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] | 5241 | { |
| 5242 | int status; |
| 5243 | struct nfs41_bind_conn_to_session_res res; |
| 5244 | struct rpc_message msg = { |
| 5245 | .rpc_proc = |
| 5246 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5247 | .rpc_argp = clp, |
| 5248 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5249 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5250 | }; |
| 5251 | |
| 5252 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5253 | |
| 5254 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5255 | if (unlikely(res.session == NULL)) { |
| 5256 | status = -ENOMEM; |
| 5257 | goto out; |
| 5258 | } |
| 5259 | |
| 5260 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5261 | if (status == 0) { |
| 5262 | if (memcmp(res.session->sess_id.data, |
| 5263 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5264 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5265 | status = -EIO; |
| 5266 | goto out_session; |
| 5267 | } |
| 5268 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5269 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5270 | __func__); |
| 5271 | status = -EIO; |
| 5272 | goto out_session; |
| 5273 | } |
| 5274 | if (res.use_conn_in_rdma_mode) { |
| 5275 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5276 | __func__); |
| 5277 | status = -EIO; |
| 5278 | goto out_session; |
| 5279 | } |
| 5280 | } |
| 5281 | out_session: |
| 5282 | kfree(res.session); |
| 5283 | out: |
| 5284 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5285 | return status; |
| 5286 | } |
| 5287 | |
| 5288 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5289 | * nfs4_proc_exchange_id() |
| 5290 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5291 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5292 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5293 | * Since the clientid has expired, all compounds using sessions |
| 5294 | * associated with the stale clientid will be returning |
| 5295 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5296 | * be in some phase of session reset. |
| 5297 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5298 | 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] | 5299 | { |
| 5300 | nfs4_verifier verifier; |
| 5301 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5302 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5303 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5304 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5305 | }; |
| 5306 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5307 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5308 | }; |
| 5309 | int status; |
| 5310 | struct rpc_message msg = { |
| 5311 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5312 | .rpc_argp = &args, |
| 5313 | .rpc_resp = &res, |
| 5314 | .rpc_cred = cred, |
| 5315 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5316 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5317 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5318 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5319 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5320 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5321 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5322 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5323 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5324 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5325 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5326 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5327 | status = -ENOMEM; |
| 5328 | goto out; |
| 5329 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5330 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5331 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5332 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5333 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5334 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5335 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5336 | } |
| 5337 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5338 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5339 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5340 | status = -ENOMEM; |
| 5341 | goto out_server_scope; |
| 5342 | } |
| 5343 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5344 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5345 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5346 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5347 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5348 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5349 | clp->cl_clientid = res.clientid; |
| 5350 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5351 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5352 | clp->cl_seqid = res.seqid; |
| 5353 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5354 | kfree(clp->cl_serverowner); |
| 5355 | clp->cl_serverowner = res.server_owner; |
| 5356 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5357 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5358 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5359 | kfree(clp->cl_implid); |
| 5360 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5361 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5362 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5363 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5364 | res.server_scope)) { |
| 5365 | dprintk("%s: server_scope mismatch detected\n", |
| 5366 | __func__); |
| 5367 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5368 | kfree(clp->cl_serverscope); |
| 5369 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5370 | } |
| 5371 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5372 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5373 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5374 | goto out; |
| 5375 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5376 | } else |
| 5377 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5378 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5379 | out_server_owner: |
| 5380 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5381 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5382 | kfree(res.server_scope); |
| 5383 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5384 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5385 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5386 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5387 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5388 | clp->cl_implid->date.seconds, |
| 5389 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5390 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5391 | return status; |
| 5392 | } |
| 5393 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5394 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5395 | struct rpc_cred *cred) |
| 5396 | { |
| 5397 | struct rpc_message msg = { |
| 5398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5399 | .rpc_argp = clp, |
| 5400 | .rpc_cred = cred, |
| 5401 | }; |
| 5402 | int status; |
| 5403 | |
| 5404 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5405 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5406 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5407 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5408 | return status; |
| 5409 | } |
| 5410 | |
| 5411 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5412 | struct rpc_cred *cred) |
| 5413 | { |
| 5414 | unsigned int loop; |
| 5415 | int ret; |
| 5416 | |
| 5417 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5418 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5419 | switch (ret) { |
| 5420 | case -NFS4ERR_DELAY: |
| 5421 | case -NFS4ERR_CLIENTID_BUSY: |
| 5422 | ssleep(1); |
| 5423 | break; |
| 5424 | default: |
| 5425 | return ret; |
| 5426 | } |
| 5427 | } |
| 5428 | return 0; |
| 5429 | } |
| 5430 | |
| 5431 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5432 | { |
| 5433 | struct rpc_cred *cred; |
| 5434 | int ret = 0; |
| 5435 | |
| 5436 | if (clp->cl_mvops->minor_version < 1) |
| 5437 | goto out; |
| 5438 | if (clp->cl_exchange_flags == 0) |
| 5439 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5440 | if (clp->cl_preserve_clid) |
| 5441 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5442 | cred = nfs4_get_exchange_id_cred(clp); |
| 5443 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5444 | if (cred) |
| 5445 | put_rpccred(cred); |
| 5446 | switch (ret) { |
| 5447 | case 0: |
| 5448 | case -NFS4ERR_STALE_CLIENTID: |
| 5449 | clp->cl_exchange_flags = 0; |
| 5450 | } |
| 5451 | out: |
| 5452 | return ret; |
| 5453 | } |
| 5454 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5455 | struct nfs4_get_lease_time_data { |
| 5456 | struct nfs4_get_lease_time_args *args; |
| 5457 | struct nfs4_get_lease_time_res *res; |
| 5458 | struct nfs_client *clp; |
| 5459 | }; |
| 5460 | |
| 5461 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5462 | void *calldata) |
| 5463 | { |
| 5464 | int ret; |
| 5465 | struct nfs4_get_lease_time_data *data = |
| 5466 | (struct nfs4_get_lease_time_data *)calldata; |
| 5467 | |
| 5468 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5469 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5470 | /* just setup sequence, do not trigger session recovery |
| 5471 | since we're invoked within one */ |
| 5472 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5473 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5474 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5475 | |
Trond Myklebust | d3edcf9 | 2012-10-15 13:14:43 -0400 | [diff] [blame] | 5476 | if (ret != -EAGAIN) |
| 5477 | rpc_call_start(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5478 | dprintk("<-- %s\n", __func__); |
| 5479 | } |
| 5480 | |
| 5481 | /* |
| 5482 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5483 | * from sequence operation or clientid errors. |
| 5484 | */ |
| 5485 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5486 | { |
| 5487 | struct nfs4_get_lease_time_data *data = |
| 5488 | (struct nfs4_get_lease_time_data *)calldata; |
| 5489 | |
| 5490 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5491 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5492 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5493 | switch (task->tk_status) { |
| 5494 | case -NFS4ERR_DELAY: |
| 5495 | case -NFS4ERR_GRACE: |
| 5496 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5497 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5498 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5499 | /* fall through */ |
| 5500 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5501 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5502 | return; |
| 5503 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5504 | dprintk("<-- %s\n", __func__); |
| 5505 | } |
| 5506 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5507 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5508 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5509 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5510 | }; |
| 5511 | |
| 5512 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5513 | { |
| 5514 | struct rpc_task *task; |
| 5515 | struct nfs4_get_lease_time_args args; |
| 5516 | struct nfs4_get_lease_time_res res = { |
| 5517 | .lr_fsinfo = fsinfo, |
| 5518 | }; |
| 5519 | struct nfs4_get_lease_time_data data = { |
| 5520 | .args = &args, |
| 5521 | .res = &res, |
| 5522 | .clp = clp, |
| 5523 | }; |
| 5524 | struct rpc_message msg = { |
| 5525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5526 | .rpc_argp = &args, |
| 5527 | .rpc_resp = &res, |
| 5528 | }; |
| 5529 | struct rpc_task_setup task_setup = { |
| 5530 | .rpc_client = clp->cl_rpcclient, |
| 5531 | .rpc_message = &msg, |
| 5532 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5533 | .callback_data = &data, |
| 5534 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5535 | }; |
| 5536 | int status; |
| 5537 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5538 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5539 | dprintk("--> %s\n", __func__); |
| 5540 | task = rpc_run_task(&task_setup); |
| 5541 | |
| 5542 | if (IS_ERR(task)) |
| 5543 | status = PTR_ERR(task); |
| 5544 | else { |
| 5545 | status = task->tk_status; |
| 5546 | rpc_put_task(task); |
| 5547 | } |
| 5548 | dprintk("<-- %s return %d\n", __func__, status); |
| 5549 | |
| 5550 | return status; |
| 5551 | } |
| 5552 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5553 | /* |
| 5554 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5555 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5556 | * use them. |
| 5557 | * |
| 5558 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5559 | * always set csa_cachethis to FALSE because the current implementation |
| 5560 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5561 | */ |
| 5562 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5563 | { |
| 5564 | struct nfs4_session *session = args->client->cl_session; |
Trond Myklebust | ae72ae67 | 2012-11-20 11:02:55 -0500 | [diff] [blame] | 5565 | unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, |
| 5566 | mxresp_sz = session->fc_target_max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5567 | |
| 5568 | if (mxrqst_sz == 0) |
| 5569 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5570 | if (mxresp_sz == 0) |
| 5571 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5572 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5573 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5574 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5575 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5576 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5577 | |
| 5578 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5579 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5580 | __func__, |
| 5581 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5582 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5583 | |
| 5584 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5585 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5586 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5587 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5588 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5589 | args->bc_attrs.max_reqs = 1; |
| 5590 | |
| 5591 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5592 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5593 | __func__, |
| 5594 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5595 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5596 | args->bc_attrs.max_reqs); |
| 5597 | } |
| 5598 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5599 | 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] | 5600 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5601 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5602 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5603 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5604 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5605 | return -EINVAL; |
| 5606 | /* |
| 5607 | * Our requested max_ops is the minimum we need; we're not |
| 5608 | * prepared to break up compounds into smaller pieces than that. |
| 5609 | * So, no point even trying to continue if the server won't |
| 5610 | * cooperate: |
| 5611 | */ |
| 5612 | if (rcvd->max_ops < sent->max_ops) |
| 5613 | return -EINVAL; |
| 5614 | if (rcvd->max_reqs == 0) |
| 5615 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5616 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5617 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5618 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5619 | } |
| 5620 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5621 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5622 | { |
| 5623 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5624 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5625 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5626 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5627 | return -EINVAL; |
| 5628 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5629 | return -EINVAL; |
| 5630 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5631 | return -EINVAL; |
| 5632 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5633 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5634 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5635 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5636 | return -EINVAL; |
| 5637 | return 0; |
| 5638 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5639 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5640 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5641 | struct nfs4_session *session) |
| 5642 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5643 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5644 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5645 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5646 | if (ret) |
| 5647 | return ret; |
| 5648 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5649 | } |
| 5650 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5651 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5652 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5653 | { |
| 5654 | struct nfs4_session *session = clp->cl_session; |
| 5655 | struct nfs41_create_session_args args = { |
| 5656 | .client = clp, |
| 5657 | .cb_program = NFS4_CALLBACK, |
| 5658 | }; |
| 5659 | struct nfs41_create_session_res res = { |
| 5660 | .client = clp, |
| 5661 | }; |
| 5662 | struct rpc_message msg = { |
| 5663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5664 | .rpc_argp = &args, |
| 5665 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5666 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5667 | }; |
| 5668 | int status; |
| 5669 | |
| 5670 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5671 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5672 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5673 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5674 | |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 5675 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5676 | /* Verify the session's negotiated channel_attrs values */ |
| 5677 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5678 | /* Increment the clientid slot sequence id */ |
| 5679 | clp->cl_seqid++; |
| 5680 | } |
| 5681 | |
| 5682 | return status; |
| 5683 | } |
| 5684 | |
| 5685 | /* |
| 5686 | * Issues a CREATE_SESSION operation to the server. |
| 5687 | * It is the responsibility of the caller to verify the session is |
| 5688 | * expired before calling this routine. |
| 5689 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5690 | 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] | 5691 | { |
| 5692 | int status; |
| 5693 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5694 | struct nfs4_session *session = clp->cl_session; |
| 5695 | |
| 5696 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5697 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5698 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5699 | if (status) |
| 5700 | goto out; |
| 5701 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5702 | /* Init or reset the session slot tables */ |
| 5703 | status = nfs4_setup_session_slot_tables(session); |
| 5704 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5705 | if (status) |
| 5706 | goto out; |
| 5707 | |
| 5708 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5709 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5710 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5711 | out: |
| 5712 | dprintk("<-- %s\n", __func__); |
| 5713 | return status; |
| 5714 | } |
| 5715 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5716 | /* |
| 5717 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5718 | * The caller must serialize access to this routine. |
| 5719 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5720 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5721 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5722 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5723 | struct rpc_message msg = { |
| 5724 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5725 | .rpc_argp = session, |
| 5726 | .rpc_cred = cred, |
| 5727 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5728 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5729 | |
| 5730 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5731 | |
| 5732 | /* session is still being setup */ |
| 5733 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5734 | return status; |
| 5735 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5736 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5737 | |
| 5738 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5739 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5740 | "Session has been destroyed regardless...\n", status); |
| 5741 | |
| 5742 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5743 | return status; |
| 5744 | } |
| 5745 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5746 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5747 | * Renew the cl_session lease. |
| 5748 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5749 | struct nfs4_sequence_data { |
| 5750 | struct nfs_client *clp; |
| 5751 | struct nfs4_sequence_args args; |
| 5752 | struct nfs4_sequence_res res; |
| 5753 | }; |
| 5754 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5755 | static void nfs41_sequence_release(void *data) |
| 5756 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5757 | struct nfs4_sequence_data *calldata = data; |
| 5758 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5759 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5760 | if (atomic_read(&clp->cl_count) > 1) |
| 5761 | nfs4_schedule_state_renewal(clp); |
| 5762 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5763 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5764 | } |
| 5765 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5766 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5767 | { |
| 5768 | switch(task->tk_status) { |
| 5769 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5770 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5771 | return -EAGAIN; |
| 5772 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5773 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5774 | } |
| 5775 | return 0; |
| 5776 | } |
| 5777 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5778 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5779 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5780 | struct nfs4_sequence_data *calldata = data; |
| 5781 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5782 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5783 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5784 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5785 | |
| 5786 | if (task->tk_status < 0) { |
| 5787 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5788 | if (atomic_read(&clp->cl_count) == 1) |
| 5789 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5790 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5791 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5792 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5793 | return; |
| 5794 | } |
| 5795 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5796 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5797 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5798 | dprintk("<-- %s\n", __func__); |
| 5799 | } |
| 5800 | |
| 5801 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5802 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5803 | struct nfs4_sequence_data *calldata = data; |
| 5804 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5805 | struct nfs4_sequence_args *args; |
| 5806 | struct nfs4_sequence_res *res; |
| 5807 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5808 | args = task->tk_msg.rpc_argp; |
| 5809 | res = task->tk_msg.rpc_resp; |
| 5810 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5811 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5812 | return; |
| 5813 | rpc_call_start(task); |
| 5814 | } |
| 5815 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5816 | static void nfs41_sequence_prepare_privileged(struct rpc_task *task, void *data) |
| 5817 | { |
| 5818 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 5819 | nfs41_sequence_prepare(task, data); |
| 5820 | } |
| 5821 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5822 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5823 | .rpc_call_done = nfs41_sequence_call_done, |
| 5824 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5825 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5826 | }; |
| 5827 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5828 | static const struct rpc_call_ops nfs41_sequence_privileged_ops = { |
| 5829 | .rpc_call_done = nfs41_sequence_call_done, |
| 5830 | .rpc_call_prepare = nfs41_sequence_prepare_privileged, |
| 5831 | .rpc_release = nfs41_sequence_release, |
| 5832 | }; |
| 5833 | |
| 5834 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred, |
| 5835 | const struct rpc_call_ops *seq_ops) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5836 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5837 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5838 | struct rpc_message msg = { |
| 5839 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5840 | .rpc_cred = cred, |
| 5841 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5842 | struct rpc_task_setup task_setup_data = { |
| 5843 | .rpc_client = clp->cl_rpcclient, |
| 5844 | .rpc_message = &msg, |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5845 | .callback_ops = seq_ops, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5846 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5847 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5848 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5849 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5850 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5851 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5852 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5853 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5854 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5855 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5856 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5857 | msg.rpc_argp = &calldata->args; |
| 5858 | msg.rpc_resp = &calldata->res; |
| 5859 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5860 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5861 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5862 | return rpc_run_task(&task_setup_data); |
| 5863 | } |
| 5864 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5865 | 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] | 5866 | { |
| 5867 | struct rpc_task *task; |
| 5868 | int ret = 0; |
| 5869 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5870 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5871 | return 0; |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5872 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5873 | if (IS_ERR(task)) |
| 5874 | ret = PTR_ERR(task); |
| 5875 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5876 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5877 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5878 | return ret; |
| 5879 | } |
| 5880 | |
| 5881 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5882 | { |
| 5883 | struct rpc_task *task; |
| 5884 | int ret; |
| 5885 | |
Bryan Schumaker | 6bdb5f2 | 2012-11-12 16:55:38 -0500 | [diff] [blame] | 5886 | task = _nfs41_proc_sequence(clp, cred, &nfs41_sequence_privileged_ops); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5887 | if (IS_ERR(task)) { |
| 5888 | ret = PTR_ERR(task); |
| 5889 | goto out; |
| 5890 | } |
| 5891 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5892 | if (!ret) { |
| 5893 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5894 | |
| 5895 | if (task->tk_status == 0) |
| 5896 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5897 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5898 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5899 | rpc_put_task(task); |
| 5900 | out: |
| 5901 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5902 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5903 | } |
| 5904 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5905 | struct nfs4_reclaim_complete_data { |
| 5906 | struct nfs_client *clp; |
| 5907 | struct nfs41_reclaim_complete_args arg; |
| 5908 | struct nfs41_reclaim_complete_res res; |
| 5909 | }; |
| 5910 | |
| 5911 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5912 | { |
| 5913 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5914 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5915 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5916 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5917 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5918 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5919 | return; |
| 5920 | |
| 5921 | rpc_call_start(task); |
| 5922 | } |
| 5923 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5924 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5925 | { |
| 5926 | switch(task->tk_status) { |
| 5927 | case 0: |
| 5928 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5929 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5930 | break; |
| 5931 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5932 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5933 | /* fall through */ |
| 5934 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5935 | return -EAGAIN; |
| 5936 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5937 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5938 | } |
| 5939 | return 0; |
| 5940 | } |
| 5941 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5942 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5943 | { |
| 5944 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5945 | struct nfs_client *clp = calldata->clp; |
| 5946 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5947 | |
| 5948 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5949 | if (!nfs41_sequence_done(task, res)) |
| 5950 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5951 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5952 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5953 | rpc_restart_call_prepare(task); |
| 5954 | return; |
| 5955 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5956 | dprintk("<-- %s\n", __func__); |
| 5957 | } |
| 5958 | |
| 5959 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5960 | { |
| 5961 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5962 | |
| 5963 | kfree(calldata); |
| 5964 | } |
| 5965 | |
| 5966 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5967 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5968 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5969 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5970 | }; |
| 5971 | |
| 5972 | /* |
| 5973 | * Issue a global reclaim complete. |
| 5974 | */ |
| 5975 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5976 | { |
| 5977 | struct nfs4_reclaim_complete_data *calldata; |
| 5978 | struct rpc_task *task; |
| 5979 | struct rpc_message msg = { |
| 5980 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5981 | }; |
| 5982 | struct rpc_task_setup task_setup_data = { |
| 5983 | .rpc_client = clp->cl_rpcclient, |
| 5984 | .rpc_message = &msg, |
| 5985 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5986 | .flags = RPC_TASK_ASYNC, |
| 5987 | }; |
| 5988 | int status = -ENOMEM; |
| 5989 | |
| 5990 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5991 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5992 | if (calldata == NULL) |
| 5993 | goto out; |
| 5994 | calldata->clp = clp; |
| 5995 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5996 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5997 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5998 | msg.rpc_argp = &calldata->arg; |
| 5999 | msg.rpc_resp = &calldata->res; |
| 6000 | task_setup_data.callback_data = calldata; |
| 6001 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6002 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6003 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6004 | goto out; |
| 6005 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6006 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6007 | if (status == 0) |
| 6008 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6009 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6010 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6011 | out: |
| 6012 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6013 | return status; |
| 6014 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6015 | |
| 6016 | static void |
| 6017 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6018 | { |
| 6019 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6020 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6021 | |
| 6022 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6023 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6024 | * right now covering the LAYOUTGET we are about to send. |
| 6025 | * However, that is not so catastrophic, and there seems |
| 6026 | * to be no way to prevent it completely. |
| 6027 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6028 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6029 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6030 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6031 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6032 | NFS_I(lgp->args.inode)->layout, |
| 6033 | lgp->args.ctx->state)) { |
| 6034 | rpc_exit(task, NFS4_OK); |
| 6035 | return; |
| 6036 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6037 | rpc_call_start(task); |
| 6038 | } |
| 6039 | |
| 6040 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6041 | { |
| 6042 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6043 | struct inode *inode = lgp->args.inode; |
| 6044 | struct nfs_server *server = NFS_SERVER(inode); |
| 6045 | struct pnfs_layout_hdr *lo; |
| 6046 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6047 | |
| 6048 | dprintk("--> %s\n", __func__); |
| 6049 | |
| 6050 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6051 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6052 | |
| 6053 | switch (task->tk_status) { |
| 6054 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6055 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6056 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6057 | case -NFS4ERR_RECALLCONFLICT: |
| 6058 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6059 | break; |
| 6060 | case -NFS4ERR_EXPIRED: |
| 6061 | case -NFS4ERR_BAD_STATEID: |
| 6062 | spin_lock(&inode->i_lock); |
| 6063 | lo = NFS_I(inode)->layout; |
| 6064 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6065 | spin_unlock(&inode->i_lock); |
| 6066 | /* If the open stateid was bad, then recover it. */ |
| 6067 | state = lgp->args.ctx->state; |
| 6068 | } else { |
| 6069 | LIST_HEAD(head); |
| 6070 | |
| 6071 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6072 | spin_unlock(&inode->i_lock); |
| 6073 | /* Mark the bad layout state as invalid, then |
| 6074 | * retry using the open stateid. */ |
| 6075 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6076 | } |
| 6077 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6078 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6079 | rpc_restart_call_prepare(task); |
| 6080 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6081 | dprintk("<-- %s\n", __func__); |
| 6082 | } |
| 6083 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6084 | static size_t max_response_pages(struct nfs_server *server) |
| 6085 | { |
| 6086 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6087 | return nfs_page_array_len(0, max_resp_sz); |
| 6088 | } |
| 6089 | |
| 6090 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6091 | { |
| 6092 | int i; |
| 6093 | |
| 6094 | if (!pages) |
| 6095 | return; |
| 6096 | |
| 6097 | for (i = 0; i < size; i++) { |
| 6098 | if (!pages[i]) |
| 6099 | break; |
| 6100 | __free_page(pages[i]); |
| 6101 | } |
| 6102 | kfree(pages); |
| 6103 | } |
| 6104 | |
| 6105 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6106 | { |
| 6107 | struct page **pages; |
| 6108 | int i; |
| 6109 | |
| 6110 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6111 | if (!pages) { |
| 6112 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6113 | return NULL; |
| 6114 | } |
| 6115 | |
| 6116 | for (i = 0; i < size; i++) { |
| 6117 | pages[i] = alloc_page(gfp_flags); |
| 6118 | if (!pages[i]) { |
| 6119 | dprintk("%s: failed to allocate page\n", __func__); |
| 6120 | nfs4_free_pages(pages, size); |
| 6121 | return NULL; |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | return pages; |
| 6126 | } |
| 6127 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6128 | static void nfs4_layoutget_release(void *calldata) |
| 6129 | { |
| 6130 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6131 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6132 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6133 | |
| 6134 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6135 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6136 | put_nfs_open_context(lgp->args.ctx); |
| 6137 | kfree(calldata); |
| 6138 | dprintk("<-- %s\n", __func__); |
| 6139 | } |
| 6140 | |
| 6141 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6142 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6143 | .rpc_call_done = nfs4_layoutget_done, |
| 6144 | .rpc_release = nfs4_layoutget_release, |
| 6145 | }; |
| 6146 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6147 | struct pnfs_layout_segment * |
| 6148 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6149 | { |
| 6150 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6151 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6152 | struct rpc_task *task; |
| 6153 | struct rpc_message msg = { |
| 6154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6155 | .rpc_argp = &lgp->args, |
| 6156 | .rpc_resp = &lgp->res, |
| 6157 | }; |
| 6158 | struct rpc_task_setup task_setup_data = { |
| 6159 | .rpc_client = server->client, |
| 6160 | .rpc_message = &msg, |
| 6161 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6162 | .callback_data = lgp, |
| 6163 | .flags = RPC_TASK_ASYNC, |
| 6164 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6165 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6166 | int status = 0; |
| 6167 | |
| 6168 | dprintk("--> %s\n", __func__); |
| 6169 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6170 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6171 | if (!lgp->args.layout.pages) { |
| 6172 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6173 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6174 | } |
| 6175 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6176 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6177 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6178 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6179 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6180 | task = rpc_run_task(&task_setup_data); |
| 6181 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6182 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6183 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6184 | if (status == 0) |
| 6185 | status = task->tk_status; |
| 6186 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6187 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6188 | rpc_put_task(task); |
| 6189 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6190 | if (status) |
| 6191 | return ERR_PTR(status); |
| 6192 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6193 | } |
| 6194 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6195 | static void |
| 6196 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6197 | { |
| 6198 | struct nfs4_layoutreturn *lrp = calldata; |
| 6199 | |
| 6200 | dprintk("--> %s\n", __func__); |
| 6201 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6202 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6203 | return; |
| 6204 | rpc_call_start(task); |
| 6205 | } |
| 6206 | |
| 6207 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6208 | { |
| 6209 | struct nfs4_layoutreturn *lrp = calldata; |
| 6210 | struct nfs_server *server; |
| 6211 | |
| 6212 | dprintk("--> %s\n", __func__); |
| 6213 | |
| 6214 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6215 | return; |
| 6216 | |
| 6217 | server = NFS_SERVER(lrp->args.inode); |
| 6218 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6219 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6220 | return; |
| 6221 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6222 | dprintk("<-- %s\n", __func__); |
| 6223 | } |
| 6224 | |
| 6225 | static void nfs4_layoutreturn_release(void *calldata) |
| 6226 | { |
| 6227 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6228 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6229 | |
| 6230 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6231 | spin_lock(&lo->plh_inode->i_lock); |
| 6232 | if (lrp->res.lrs_present) |
| 6233 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6234 | lo->plh_block_lgets--; |
| 6235 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6236 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6237 | kfree(calldata); |
| 6238 | dprintk("<-- %s\n", __func__); |
| 6239 | } |
| 6240 | |
| 6241 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6242 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6243 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6244 | .rpc_release = nfs4_layoutreturn_release, |
| 6245 | }; |
| 6246 | |
| 6247 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6248 | { |
| 6249 | struct rpc_task *task; |
| 6250 | struct rpc_message msg = { |
| 6251 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6252 | .rpc_argp = &lrp->args, |
| 6253 | .rpc_resp = &lrp->res, |
| 6254 | }; |
| 6255 | struct rpc_task_setup task_setup_data = { |
| 6256 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6257 | .rpc_message = &msg, |
| 6258 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6259 | .callback_data = lrp, |
| 6260 | }; |
| 6261 | int status; |
| 6262 | |
| 6263 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6264 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6265 | task = rpc_run_task(&task_setup_data); |
| 6266 | if (IS_ERR(task)) |
| 6267 | return PTR_ERR(task); |
| 6268 | status = task->tk_status; |
| 6269 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6270 | rpc_put_task(task); |
| 6271 | return status; |
| 6272 | } |
| 6273 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6274 | /* |
| 6275 | * Retrieve the list of Data Server devices from the MDS. |
| 6276 | */ |
| 6277 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6278 | const struct nfs_fh *fh, |
| 6279 | struct pnfs_devicelist *devlist) |
| 6280 | { |
| 6281 | struct nfs4_getdevicelist_args args = { |
| 6282 | .fh = fh, |
| 6283 | .layoutclass = server->pnfs_curr_ld->id, |
| 6284 | }; |
| 6285 | struct nfs4_getdevicelist_res res = { |
| 6286 | .devlist = devlist, |
| 6287 | }; |
| 6288 | struct rpc_message msg = { |
| 6289 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6290 | .rpc_argp = &args, |
| 6291 | .rpc_resp = &res, |
| 6292 | }; |
| 6293 | int status; |
| 6294 | |
| 6295 | dprintk("--> %s\n", __func__); |
| 6296 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6297 | &res.seq_res, 0); |
| 6298 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6299 | return status; |
| 6300 | } |
| 6301 | |
| 6302 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6303 | const struct nfs_fh *fh, |
| 6304 | struct pnfs_devicelist *devlist) |
| 6305 | { |
| 6306 | struct nfs4_exception exception = { }; |
| 6307 | int err; |
| 6308 | |
| 6309 | do { |
| 6310 | err = nfs4_handle_exception(server, |
| 6311 | _nfs4_getdevicelist(server, fh, devlist), |
| 6312 | &exception); |
| 6313 | } while (exception.retry); |
| 6314 | |
| 6315 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6316 | err, devlist->num_devs); |
| 6317 | |
| 6318 | return err; |
| 6319 | } |
| 6320 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6321 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6322 | static int |
| 6323 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6324 | { |
| 6325 | struct nfs4_getdeviceinfo_args args = { |
| 6326 | .pdev = pdev, |
| 6327 | }; |
| 6328 | struct nfs4_getdeviceinfo_res res = { |
| 6329 | .pdev = pdev, |
| 6330 | }; |
| 6331 | struct rpc_message msg = { |
| 6332 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6333 | .rpc_argp = &args, |
| 6334 | .rpc_resp = &res, |
| 6335 | }; |
| 6336 | int status; |
| 6337 | |
| 6338 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6339 | 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] | 6340 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6341 | |
| 6342 | return status; |
| 6343 | } |
| 6344 | |
| 6345 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6346 | { |
| 6347 | struct nfs4_exception exception = { }; |
| 6348 | int err; |
| 6349 | |
| 6350 | do { |
| 6351 | err = nfs4_handle_exception(server, |
| 6352 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6353 | &exception); |
| 6354 | } while (exception.retry); |
| 6355 | return err; |
| 6356 | } |
| 6357 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6358 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6359 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6360 | { |
| 6361 | struct nfs4_layoutcommit_data *data = calldata; |
| 6362 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6363 | |
| 6364 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6365 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6366 | return; |
| 6367 | rpc_call_start(task); |
| 6368 | } |
| 6369 | |
| 6370 | static void |
| 6371 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6372 | { |
| 6373 | struct nfs4_layoutcommit_data *data = calldata; |
| 6374 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6375 | |
| 6376 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6377 | return; |
| 6378 | |
| 6379 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6380 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6381 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6382 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6383 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6384 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6385 | break; |
| 6386 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6387 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6388 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6389 | break; |
| 6390 | default: |
| 6391 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6392 | rpc_restart_call_prepare(task); |
| 6393 | return; |
| 6394 | } |
| 6395 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | static void nfs4_layoutcommit_release(void *calldata) |
| 6399 | { |
| 6400 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6401 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6402 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6403 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6404 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6405 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6406 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6407 | list_del_init(&lseg->pls_lc_list); |
| 6408 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6409 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6410 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6411 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6412 | |
| 6413 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6414 | smp_mb__after_clear_bit(); |
| 6415 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6416 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6417 | put_rpccred(data->cred); |
| 6418 | kfree(data); |
| 6419 | } |
| 6420 | |
| 6421 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6422 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6423 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6424 | .rpc_release = nfs4_layoutcommit_release, |
| 6425 | }; |
| 6426 | |
| 6427 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6428 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6429 | { |
| 6430 | struct rpc_message msg = { |
| 6431 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6432 | .rpc_argp = &data->args, |
| 6433 | .rpc_resp = &data->res, |
| 6434 | .rpc_cred = data->cred, |
| 6435 | }; |
| 6436 | struct rpc_task_setup task_setup_data = { |
| 6437 | .task = &data->task, |
| 6438 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6439 | .rpc_message = &msg, |
| 6440 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6441 | .callback_data = data, |
| 6442 | .flags = RPC_TASK_ASYNC, |
| 6443 | }; |
| 6444 | struct rpc_task *task; |
| 6445 | int status = 0; |
| 6446 | |
| 6447 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6448 | "lbw: %llu inode %lu\n", |
| 6449 | data->task.tk_pid, sync, |
| 6450 | data->args.lastbytewritten, |
| 6451 | data->args.inode->i_ino); |
| 6452 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6453 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6454 | task = rpc_run_task(&task_setup_data); |
| 6455 | if (IS_ERR(task)) |
| 6456 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6457 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6458 | goto out; |
| 6459 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6460 | if (status != 0) |
| 6461 | goto out; |
| 6462 | status = task->tk_status; |
| 6463 | out: |
| 6464 | dprintk("%s: status %d\n", __func__, status); |
| 6465 | rpc_put_task(task); |
| 6466 | return status; |
| 6467 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6468 | |
| 6469 | static int |
| 6470 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6471 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6472 | { |
| 6473 | struct nfs41_secinfo_no_name_args args = { |
| 6474 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6475 | }; |
| 6476 | struct nfs4_secinfo_res res = { |
| 6477 | .flavors = flavors, |
| 6478 | }; |
| 6479 | struct rpc_message msg = { |
| 6480 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6481 | .rpc_argp = &args, |
| 6482 | .rpc_resp = &res, |
| 6483 | }; |
| 6484 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6485 | } |
| 6486 | |
| 6487 | static int |
| 6488 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6489 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6490 | { |
| 6491 | struct nfs4_exception exception = { }; |
| 6492 | int err; |
| 6493 | do { |
| 6494 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6495 | switch (err) { |
| 6496 | case 0: |
| 6497 | case -NFS4ERR_WRONGSEC: |
| 6498 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6499 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6500 | default: |
| 6501 | err = nfs4_handle_exception(server, err, &exception); |
| 6502 | } |
| 6503 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6504 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6505 | return err; |
| 6506 | } |
| 6507 | |
| 6508 | static int |
| 6509 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6510 | struct nfs_fsinfo *info) |
| 6511 | { |
| 6512 | int err; |
| 6513 | struct page *page; |
| 6514 | rpc_authflavor_t flavor; |
| 6515 | struct nfs4_secinfo_flavors *flavors; |
| 6516 | |
| 6517 | page = alloc_page(GFP_KERNEL); |
| 6518 | if (!page) { |
| 6519 | err = -ENOMEM; |
| 6520 | goto out; |
| 6521 | } |
| 6522 | |
| 6523 | flavors = page_address(page); |
| 6524 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6525 | |
| 6526 | /* |
| 6527 | * Fall back on "guess and check" method if |
| 6528 | * the server doesn't support SECINFO_NO_NAME |
| 6529 | */ |
| 6530 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6531 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6532 | goto out_freepage; |
| 6533 | } |
| 6534 | if (err) |
| 6535 | goto out_freepage; |
| 6536 | |
| 6537 | flavor = nfs_find_best_sec(flavors); |
| 6538 | if (err == 0) |
| 6539 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6540 | |
| 6541 | out_freepage: |
| 6542 | put_page(page); |
| 6543 | if (err == -EACCES) |
| 6544 | return -EPERM; |
| 6545 | out: |
| 6546 | return err; |
| 6547 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6548 | |
| 6549 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6550 | { |
| 6551 | int status; |
| 6552 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6553 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6554 | }; |
| 6555 | struct nfs41_test_stateid_res res; |
| 6556 | struct rpc_message msg = { |
| 6557 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6558 | .rpc_argp = &args, |
| 6559 | .rpc_resp = &res, |
| 6560 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6561 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6562 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6563 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6564 | 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] | 6565 | if (status != NFS_OK) { |
| 6566 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6567 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6568 | } |
| 6569 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6570 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6571 | } |
| 6572 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6573 | /** |
| 6574 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6575 | * |
| 6576 | * @server: server / transport on which to perform the operation |
| 6577 | * @stateid: state ID to test |
| 6578 | * |
| 6579 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6580 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6581 | * failed or the state ID is not currently valid. |
| 6582 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6583 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6584 | { |
| 6585 | struct nfs4_exception exception = { }; |
| 6586 | int err; |
| 6587 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6588 | err = _nfs41_test_stateid(server, stateid); |
| 6589 | if (err != -NFS4ERR_DELAY) |
| 6590 | break; |
| 6591 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6592 | } while (exception.retry); |
| 6593 | return err; |
| 6594 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6595 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6596 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6597 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6598 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6599 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6600 | }; |
| 6601 | struct nfs41_free_stateid_res res; |
| 6602 | struct rpc_message msg = { |
| 6603 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6604 | .rpc_argp = &args, |
| 6605 | .rpc_resp = &res, |
| 6606 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6607 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6608 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6609 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6610 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6611 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6612 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6613 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6614 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6615 | } |
| 6616 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6617 | /** |
| 6618 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6619 | * |
| 6620 | * @server: server / transport on which to perform the operation |
| 6621 | * @stateid: state ID to release |
| 6622 | * |
| 6623 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6624 | * negative NFS4ERR value is returned. |
| 6625 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6626 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6627 | { |
| 6628 | struct nfs4_exception exception = { }; |
| 6629 | int err; |
| 6630 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6631 | err = _nfs4_free_stateid(server, stateid); |
| 6632 | if (err != -NFS4ERR_DELAY) |
| 6633 | break; |
| 6634 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6635 | } while (exception.retry); |
| 6636 | return err; |
| 6637 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6638 | |
| 6639 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6640 | const nfs4_stateid *s2) |
| 6641 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6642 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6643 | return false; |
| 6644 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6645 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6646 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6647 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6648 | return true; |
| 6649 | |
| 6650 | return false; |
| 6651 | } |
| 6652 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6653 | #endif /* CONFIG_NFS_V4_1 */ |
| 6654 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6655 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6656 | const nfs4_stateid *s2) |
| 6657 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6658 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6659 | } |
| 6660 | |
| 6661 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6662 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6663 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6664 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6665 | .recover_open = nfs4_open_reclaim, |
| 6666 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6667 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6668 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6669 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6670 | }; |
| 6671 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6672 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6673 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6674 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6675 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6676 | .recover_open = nfs4_open_reclaim, |
| 6677 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6678 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6679 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6680 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6681 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6682 | }; |
| 6683 | #endif /* CONFIG_NFS_V4_1 */ |
| 6684 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6685 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6686 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6687 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6688 | .recover_open = nfs4_open_expired, |
| 6689 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6690 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6691 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6692 | }; |
| 6693 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6694 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6695 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6696 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6697 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6698 | .recover_open = nfs41_open_expired, |
| 6699 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6700 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6701 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6702 | }; |
| 6703 | #endif /* CONFIG_NFS_V4_1 */ |
| 6704 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6705 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6706 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6707 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6708 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6709 | }; |
| 6710 | |
| 6711 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6712 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6713 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6714 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6715 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6716 | }; |
| 6717 | #endif |
| 6718 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6719 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6720 | .minor_version = 0, |
| 6721 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6722 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6723 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6724 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6725 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6726 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6727 | }; |
| 6728 | |
| 6729 | #if defined(CONFIG_NFS_V4_1) |
| 6730 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6731 | .minor_version = 1, |
| 6732 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6733 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6734 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6735 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6736 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6737 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6738 | }; |
| 6739 | #endif |
| 6740 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6741 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6742 | [0] = &nfs_v4_0_minor_ops, |
| 6743 | #if defined(CONFIG_NFS_V4_1) |
| 6744 | [1] = &nfs_v4_1_minor_ops, |
| 6745 | #endif |
| 6746 | }; |
| 6747 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6748 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6749 | .create = nfs_create, |
| 6750 | .lookup = nfs_lookup, |
| 6751 | .atomic_open = nfs_atomic_open, |
| 6752 | .link = nfs_link, |
| 6753 | .unlink = nfs_unlink, |
| 6754 | .symlink = nfs_symlink, |
| 6755 | .mkdir = nfs_mkdir, |
| 6756 | .rmdir = nfs_rmdir, |
| 6757 | .mknod = nfs_mknod, |
| 6758 | .rename = nfs_rename, |
| 6759 | .permission = nfs_permission, |
| 6760 | .getattr = nfs_getattr, |
| 6761 | .setattr = nfs_setattr, |
| 6762 | .getxattr = generic_getxattr, |
| 6763 | .setxattr = generic_setxattr, |
| 6764 | .listxattr = generic_listxattr, |
| 6765 | .removexattr = generic_removexattr, |
| 6766 | }; |
| 6767 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6768 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6769 | .permission = nfs_permission, |
| 6770 | .getattr = nfs_getattr, |
| 6771 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6772 | .getxattr = generic_getxattr, |
| 6773 | .setxattr = generic_setxattr, |
| 6774 | .listxattr = generic_listxattr, |
| 6775 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6776 | }; |
| 6777 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6778 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6779 | .version = 4, /* protocol version */ |
| 6780 | .dentry_ops = &nfs4_dentry_operations, |
| 6781 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6782 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6783 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6784 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6785 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6786 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6787 | .getattr = nfs4_proc_getattr, |
| 6788 | .setattr = nfs4_proc_setattr, |
| 6789 | .lookup = nfs4_proc_lookup, |
| 6790 | .access = nfs4_proc_access, |
| 6791 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6792 | .create = nfs4_proc_create, |
| 6793 | .remove = nfs4_proc_remove, |
| 6794 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6795 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6796 | .unlink_done = nfs4_proc_unlink_done, |
| 6797 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6798 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6799 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6800 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6801 | .link = nfs4_proc_link, |
| 6802 | .symlink = nfs4_proc_symlink, |
| 6803 | .mkdir = nfs4_proc_mkdir, |
| 6804 | .rmdir = nfs4_proc_remove, |
| 6805 | .readdir = nfs4_proc_readdir, |
| 6806 | .mknod = nfs4_proc_mknod, |
| 6807 | .statfs = nfs4_proc_statfs, |
| 6808 | .fsinfo = nfs4_proc_fsinfo, |
| 6809 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6810 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6811 | .decode_dirent = nfs4_decode_dirent, |
| 6812 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6813 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6814 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6815 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6817 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6818 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6819 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6821 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6822 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6823 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6824 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6825 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6826 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6827 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6828 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6829 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6830 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6831 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 6832 | .create_server = nfs4_create_server, |
| 6833 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6834 | }; |
| 6835 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6836 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6837 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6838 | .list = nfs4_xattr_list_nfs4_acl, |
| 6839 | .get = nfs4_xattr_get_nfs4_acl, |
| 6840 | .set = nfs4_xattr_set_nfs4_acl, |
| 6841 | }; |
| 6842 | |
| 6843 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6844 | &nfs4_xattr_nfs4_acl_handler, |
| 6845 | NULL |
| 6846 | }; |
| 6847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | /* |
| 6849 | * Local variables: |
| 6850 | * c-basic-offset: 8 |
| 6851 | * End: |
| 6852 | */ |