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> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 46 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 55 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 56 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 57 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 58 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 59 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 61 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 63 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 64 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 65 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 66 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 67 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 74 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 75 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 76 | static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE; |
| 77 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 78 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 79 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 80 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 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] | 82 | 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] | 83 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 84 | 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] | 85 | 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] | 86 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 87 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 88 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 90 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 92 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 94 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 96 | if (err >= -1000) |
| 97 | return err; |
| 98 | switch (err) { |
| 99 | case -NFS4ERR_RESOURCE: |
| 100 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 101 | case -NFS4ERR_WRONGSEC: |
| 102 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 103 | case -NFS4ERR_BADOWNER: |
| 104 | case -NFS4ERR_BADNAME: |
| 105 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 106 | case -NFS4ERR_SHARE_DENIED: |
| 107 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 108 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 109 | return -EPROTONOSUPPORT; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 110 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 112 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 113 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 115 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
| 119 | * This is our standard bitmap for GETATTR requests. |
| 120 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 121 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | FATTR4_WORD0_TYPE |
| 123 | | FATTR4_WORD0_CHANGE |
| 124 | | FATTR4_WORD0_SIZE |
| 125 | | FATTR4_WORD0_FSID |
| 126 | | FATTR4_WORD0_FILEID, |
| 127 | FATTR4_WORD1_MODE |
| 128 | | FATTR4_WORD1_NUMLINKS |
| 129 | | FATTR4_WORD1_OWNER |
| 130 | | FATTR4_WORD1_OWNER_GROUP |
| 131 | | FATTR4_WORD1_RAWDEV |
| 132 | | FATTR4_WORD1_SPACE_USED |
| 133 | | FATTR4_WORD1_TIME_ACCESS |
| 134 | | FATTR4_WORD1_TIME_METADATA |
| 135 | | FATTR4_WORD1_TIME_MODIFY |
| 136 | }; |
| 137 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 138 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 139 | FATTR4_WORD0_TYPE |
| 140 | | FATTR4_WORD0_CHANGE |
| 141 | | FATTR4_WORD0_SIZE |
| 142 | | FATTR4_WORD0_FSID |
| 143 | | FATTR4_WORD0_FILEID, |
| 144 | FATTR4_WORD1_MODE |
| 145 | | FATTR4_WORD1_NUMLINKS |
| 146 | | FATTR4_WORD1_OWNER |
| 147 | | FATTR4_WORD1_OWNER_GROUP |
| 148 | | FATTR4_WORD1_RAWDEV |
| 149 | | FATTR4_WORD1_SPACE_USED |
| 150 | | FATTR4_WORD1_TIME_ACCESS |
| 151 | | FATTR4_WORD1_TIME_METADATA |
| 152 | | FATTR4_WORD1_TIME_MODIFY, |
| 153 | FATTR4_WORD2_MDSTHRESHOLD |
| 154 | }; |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | const u32 nfs4_statfs_bitmap[2] = { |
| 157 | FATTR4_WORD0_FILES_AVAIL |
| 158 | | FATTR4_WORD0_FILES_FREE |
| 159 | | FATTR4_WORD0_FILES_TOTAL, |
| 160 | FATTR4_WORD1_SPACE_AVAIL |
| 161 | | FATTR4_WORD1_SPACE_FREE |
| 162 | | FATTR4_WORD1_SPACE_TOTAL |
| 163 | }; |
| 164 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 165 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | FATTR4_WORD0_MAXLINK |
| 167 | | FATTR4_WORD0_MAXNAME, |
| 168 | 0 |
| 169 | }; |
| 170 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 171 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | | FATTR4_WORD0_MAXREAD |
| 173 | | FATTR4_WORD0_MAXWRITE |
| 174 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 175 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 176 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 177 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 180 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 181 | FATTR4_WORD0_TYPE |
| 182 | | FATTR4_WORD0_CHANGE |
| 183 | | FATTR4_WORD0_SIZE |
| 184 | | FATTR4_WORD0_FSID |
| 185 | | FATTR4_WORD0_FILEID |
| 186 | | FATTR4_WORD0_FS_LOCATIONS, |
| 187 | FATTR4_WORD1_MODE |
| 188 | | FATTR4_WORD1_NUMLINKS |
| 189 | | FATTR4_WORD1_OWNER |
| 190 | | FATTR4_WORD1_OWNER_GROUP |
| 191 | | FATTR4_WORD1_RAWDEV |
| 192 | | FATTR4_WORD1_SPACE_USED |
| 193 | | FATTR4_WORD1_TIME_ACCESS |
| 194 | | FATTR4_WORD1_TIME_METADATA |
| 195 | | FATTR4_WORD1_TIME_MODIFY |
| 196 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 197 | }; |
| 198 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 199 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | struct nfs4_readdir_arg *readdir) |
| 201 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 202 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | BUG_ON(readdir->count < 80); |
| 205 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 206 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | readdir->cookie = 0; |
| 212 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 213 | if (cookie == 2) |
| 214 | return; |
| 215 | |
| 216 | /* |
| 217 | * NFSv4 servers do not return entries for '.' and '..' |
| 218 | * Therefore, we fake these entries here. We let '.' |
| 219 | * have cookie 0 and '..' have cookie 1. Note that |
| 220 | * when talking to the server, we always send cookie 0 |
| 221 | * instead of 1 or 2. |
| 222 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 223 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | if (cookie == 0) { |
| 226 | *p++ = xdr_one; /* next */ |
| 227 | *p++ = xdr_zero; /* cookie, first word */ |
| 228 | *p++ = xdr_one; /* cookie, second word */ |
| 229 | *p++ = xdr_one; /* entry len */ |
| 230 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 231 | p++; |
| 232 | *p++ = xdr_one; /* bitmap length */ |
| 233 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 234 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 235 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | *p++ = xdr_one; /* next */ |
| 239 | *p++ = xdr_zero; /* cookie, first word */ |
| 240 | *p++ = xdr_two; /* cookie, second word */ |
| 241 | *p++ = xdr_two; /* entry len */ |
| 242 | memcpy(p, "..\0\0", 4); /* entry */ |
| 243 | p++; |
| 244 | *p++ = xdr_one; /* bitmap length */ |
| 245 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 246 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 247 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | readdir->pgbase = (char *)p - (char *)start; |
| 250 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 251 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 254 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 255 | { |
| 256 | int res; |
| 257 | |
| 258 | might_sleep(); |
| 259 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 260 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 261 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 262 | return res; |
| 263 | } |
| 264 | |
| 265 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 266 | { |
| 267 | int res = 0; |
| 268 | |
| 269 | might_sleep(); |
| 270 | |
| 271 | if (*timeout <= 0) |
| 272 | *timeout = NFS4_POLL_RETRY_MIN; |
| 273 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 274 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 275 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 276 | if (fatal_signal_pending(current)) |
| 277 | res = -ERESTARTSYS; |
| 278 | *timeout <<= 1; |
| 279 | return res; |
| 280 | } |
| 281 | |
| 282 | /* This is the error handling routine for processes that are allowed |
| 283 | * to sleep. |
| 284 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 285 | 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] | 286 | { |
| 287 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 288 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 289 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 290 | int ret = errorcode; |
| 291 | |
| 292 | exception->retry = 0; |
| 293 | switch(errorcode) { |
| 294 | case 0: |
| 295 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 296 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 297 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 298 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 299 | exception->retry = 1; |
| 300 | return 0; |
| 301 | } |
| 302 | if (state == NULL) |
| 303 | break; |
| 304 | nfs4_schedule_stateid_recovery(server, state); |
| 305 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 306 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 307 | case -NFS4ERR_ADMIN_REVOKED: |
| 308 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 309 | if (state == NULL) |
| 310 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 311 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 312 | nfs4_schedule_stateid_recovery(server, state); |
| 313 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 314 | case -NFS4ERR_EXPIRED: |
| 315 | if (state != NULL) |
| 316 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 317 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 318 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 319 | nfs4_schedule_lease_recovery(clp); |
| 320 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 321 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 322 | case -NFS4ERR_BADSESSION: |
| 323 | case -NFS4ERR_BADSLOT: |
| 324 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 325 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 326 | case -NFS4ERR_DEADSESSION: |
| 327 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 328 | case -NFS4ERR_SEQ_MISORDERED: |
| 329 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 330 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 331 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 332 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 333 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 334 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 335 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 336 | if (exception->timeout > HZ) { |
| 337 | /* We have retried a decent amount, time to |
| 338 | * fail |
| 339 | */ |
| 340 | ret = -EBUSY; |
| 341 | break; |
| 342 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | case -NFS4ERR_GRACE: |
| 344 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 345 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 346 | ret = nfs4_delay(server->client, &exception->timeout); |
| 347 | if (ret != 0) |
| 348 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 349 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 350 | case -NFS4ERR_OLD_STATEID: |
| 351 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 352 | break; |
| 353 | case -NFS4ERR_BADOWNER: |
| 354 | /* The following works around a Linux server bug! */ |
| 355 | case -NFS4ERR_BADNAME: |
| 356 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 357 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 358 | exception->retry = 1; |
| 359 | printk(KERN_WARNING "NFS: v4 server %s " |
| 360 | "does not accept raw " |
| 361 | "uid/gids. " |
| 362 | "Reenabling the idmapper.\n", |
| 363 | server->nfs_client->cl_hostname); |
| 364 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 365 | } |
| 366 | /* We failed to handle the error */ |
| 367 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 368 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 369 | ret = nfs4_wait_clnt_recover(clp); |
| 370 | if (ret == 0) |
| 371 | exception->retry = 1; |
| 372 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 376 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | spin_lock(&clp->cl_lock); |
| 379 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 380 | clp->cl_last_renewal = timestamp; |
| 381 | spin_unlock(&clp->cl_lock); |
| 382 | } |
| 383 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 384 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 385 | { |
| 386 | do_renew_lease(server->nfs_client, timestamp); |
| 387 | } |
| 388 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 389 | #if defined(CONFIG_NFS_V4_1) |
| 390 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 391 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 392 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 393 | * |
| 394 | * freeing a slot is trivially done by clearing its respective bit |
| 395 | * in the bitmap. |
| 396 | * If the freed slotid equals highest_used_slotid we want to update it |
| 397 | * so that the server would be able to size down the slot table if needed, |
| 398 | * otherwise we know that the highest_used_slotid is still in use. |
| 399 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 400 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 401 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 402 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 403 | * |
| 404 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 405 | */ |
| 406 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 407 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 408 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 409 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 410 | /* clear used bit in bitmap */ |
| 411 | __clear_bit(slotid, tbl->used_slots); |
| 412 | |
| 413 | /* update highest_used_slotid when it is freed */ |
| 414 | if (slotid == tbl->highest_used_slotid) { |
| 415 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 416 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 417 | tbl->highest_used_slotid = slotid; |
| 418 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 419 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 420 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 421 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 422 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 423 | } |
| 424 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 425 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 426 | { |
| 427 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 428 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 431 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 432 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 433 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 434 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 435 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 436 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 437 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 438 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 442 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 443 | return; |
| 444 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 445 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 446 | complete(&ses->fc_slot_table.complete); |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | * Signal state manager thread if session back channel is drained |
| 451 | */ |
| 452 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 453 | { |
| 454 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 455 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 456 | return; |
| 457 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 458 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 461 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 462 | { |
| 463 | struct nfs4_slot_table *tbl; |
| 464 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 465 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 466 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 467 | /* just wake up the next guy waiting since |
| 468 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 469 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 470 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 471 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 472 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 473 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 474 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 475 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 476 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 477 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 478 | } |
| 479 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 480 | 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] | 481 | { |
| 482 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 483 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 484 | |
| 485 | /* |
| 486 | * sr_status remains 1 if an RPC level error occurred. The server |
| 487 | * may or may not have processed the sequence operation.. |
| 488 | * Proceed as if the server received and processed the sequence |
| 489 | * operation. |
| 490 | */ |
| 491 | if (res->sr_status == 1) |
| 492 | res->sr_status = NFS_OK; |
| 493 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 494 | /* don't increment the sequence number if the task wasn't sent */ |
| 495 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 496 | goto out; |
| 497 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 498 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 499 | switch (res->sr_status) { |
| 500 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 501 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 502 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 503 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 504 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 505 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 506 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 507 | if (res->sr_status_flags != 0) |
| 508 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 509 | break; |
| 510 | case -NFS4ERR_DELAY: |
| 511 | /* The server detected a resend of the RPC call and |
| 512 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 513 | * of RFC5661. |
| 514 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 515 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 516 | __func__, |
| 517 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 518 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 519 | goto out_retry; |
| 520 | default: |
| 521 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 522 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 523 | } |
| 524 | out: |
| 525 | /* The session may be reset by one of the error handlers. */ |
| 526 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 527 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 528 | return 1; |
| 529 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 530 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 531 | goto out; |
| 532 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 533 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 536 | static int nfs4_sequence_done(struct rpc_task *task, |
| 537 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 538 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 539 | if (res->sr_session == NULL) |
| 540 | return 1; |
| 541 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 542 | } |
| 543 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 544 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 545 | * nfs4_find_slot - efficiently look for a free slot |
| 546 | * |
| 547 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 548 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 549 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 550 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 551 | * |
| 552 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 553 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 554 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 555 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 556 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 557 | u32 slotid; |
| 558 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 559 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 560 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 561 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 562 | tbl->max_slots); |
| 563 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 564 | if (slotid >= tbl->max_slots) |
| 565 | goto out; |
| 566 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 567 | if (slotid > tbl->highest_used_slotid || |
| 568 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 569 | tbl->highest_used_slotid = slotid; |
| 570 | ret_id = slotid; |
| 571 | out: |
| 572 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 573 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 574 | return ret_id; |
| 575 | } |
| 576 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 577 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 578 | struct nfs4_sequence_res *res, int cache_reply) |
| 579 | { |
| 580 | args->sa_session = NULL; |
| 581 | args->sa_cache_this = 0; |
| 582 | if (cache_reply) |
| 583 | args->sa_cache_this = 1; |
| 584 | res->sr_session = NULL; |
| 585 | res->sr_slot = NULL; |
| 586 | } |
| 587 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 588 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 589 | struct nfs4_sequence_args *args, |
| 590 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 591 | struct rpc_task *task) |
| 592 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 593 | struct nfs4_slot *slot; |
| 594 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 595 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 596 | |
| 597 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 599 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 600 | return 0; |
| 601 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 602 | tbl = &session->fc_slot_table; |
| 603 | |
| 604 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 606 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 607 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 608 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 609 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 610 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 611 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 612 | } |
| 613 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 614 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 615 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 616 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 617 | spin_unlock(&tbl->slot_tbl_lock); |
| 618 | dprintk("%s enforce FIFO order\n", __func__); |
| 619 | return -EAGAIN; |
| 620 | } |
| 621 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 622 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 623 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 624 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 625 | spin_unlock(&tbl->slot_tbl_lock); |
| 626 | dprintk("<-- %s: no free slots\n", __func__); |
| 627 | return -EAGAIN; |
| 628 | } |
| 629 | spin_unlock(&tbl->slot_tbl_lock); |
| 630 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 631 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 632 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 633 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 634 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 635 | |
| 636 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 637 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 638 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 639 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 640 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 641 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 642 | /* |
| 643 | * sr_status is only set in decode_sequence, and so will remain |
| 644 | * set to 1 if an rpc level failure occurs. |
| 645 | */ |
| 646 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 647 | return 0; |
| 648 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 649 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 650 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 651 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 652 | struct nfs4_sequence_args *args, |
| 653 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | struct rpc_task *task) |
| 655 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 656 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 657 | int ret = 0; |
| 658 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 659 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 661 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 662 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 663 | __func__, session->clp, session, res->sr_slot ? |
| 664 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 665 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 666 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | out: |
| 668 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 669 | return ret; |
| 670 | } |
| 671 | |
| 672 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 673 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 674 | struct nfs4_sequence_args *seq_args; |
| 675 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | }; |
| 677 | |
| 678 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 679 | { |
| 680 | struct nfs41_call_sync_data *data = calldata; |
| 681 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 682 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 683 | |
| 684 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 685 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | return; |
| 687 | rpc_call_start(task); |
| 688 | } |
| 689 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 690 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 691 | { |
| 692 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 693 | nfs41_call_sync_prepare(task, calldata); |
| 694 | } |
| 695 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 696 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 697 | { |
| 698 | struct nfs41_call_sync_data *data = calldata; |
| 699 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 700 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 701 | } |
| 702 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 703 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 704 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 705 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 706 | }; |
| 707 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 708 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 709 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 710 | .rpc_call_done = nfs41_call_sync_done, |
| 711 | }; |
| 712 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 713 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 714 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 715 | struct rpc_message *msg, |
| 716 | struct nfs4_sequence_args *args, |
| 717 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 718 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 719 | { |
| 720 | int ret; |
| 721 | struct rpc_task *task; |
| 722 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 723 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 724 | .seq_args = args, |
| 725 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 726 | }; |
| 727 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 728 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 729 | .rpc_message = msg, |
| 730 | .callback_ops = &nfs41_call_sync_ops, |
| 731 | .callback_data = &data |
| 732 | }; |
| 733 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 734 | if (privileged) |
| 735 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 736 | task = rpc_run_task(&task_setup); |
| 737 | if (IS_ERR(task)) |
| 738 | ret = PTR_ERR(task); |
| 739 | else { |
| 740 | ret = task->tk_status; |
| 741 | rpc_put_task(task); |
| 742 | } |
| 743 | return ret; |
| 744 | } |
| 745 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 746 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 747 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 748 | struct rpc_message *msg, |
| 749 | struct nfs4_sequence_args *args, |
| 750 | struct nfs4_sequence_res *res, |
| 751 | int cache_reply) |
| 752 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 753 | nfs41_init_sequence(args, res, cache_reply); |
| 754 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 755 | } |
| 756 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 757 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 758 | static inline |
| 759 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 760 | struct nfs4_sequence_res *res, int cache_reply) |
| 761 | { |
| 762 | } |
| 763 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 764 | static int nfs4_sequence_done(struct rpc_task *task, |
| 765 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 766 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 767 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 768 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 769 | #endif /* CONFIG_NFS_V4_1 */ |
| 770 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 771 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 772 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 773 | struct rpc_message *msg, |
| 774 | struct nfs4_sequence_args *args, |
| 775 | struct nfs4_sequence_res *res, |
| 776 | int cache_reply) |
| 777 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 778 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 779 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 780 | } |
| 781 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 782 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 783 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 784 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 785 | struct rpc_message *msg, |
| 786 | struct nfs4_sequence_args *args, |
| 787 | struct nfs4_sequence_res *res, |
| 788 | int cache_reply) |
| 789 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 790 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 791 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 792 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 793 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 794 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 796 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 798 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 799 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 800 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 801 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 802 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 803 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 806 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 807 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 808 | struct nfs_openargs o_arg; |
| 809 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 810 | struct nfs_open_confirmargs c_arg; |
| 811 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 812 | struct nfs4_string owner_name; |
| 813 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 814 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 815 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 816 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 817 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 818 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 820 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 821 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 822 | int rpc_status; |
| 823 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | }; |
| 825 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 826 | |
| 827 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 828 | { |
| 829 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 830 | p->o_res.seqid = p->o_arg.seqid; |
| 831 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 832 | p->o_res.server = p->o_arg.server; |
| 833 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 834 | 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] | 835 | } |
| 836 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 837 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 838 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 839 | const struct iattr *attrs, |
| 840 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 841 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 842 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 843 | struct inode *dir = parent->d_inode; |
| 844 | struct nfs_server *server = NFS_SERVER(dir); |
| 845 | struct nfs4_opendata *p; |
| 846 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 847 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 848 | if (p == NULL) |
| 849 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 850 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 851 | if (p->o_arg.seqid == NULL) |
| 852 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 853 | nfs_sb_active(dentry->d_sb); |
| 854 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | p->dir = parent; |
| 856 | p->owner = sp; |
| 857 | atomic_inc(&sp->so_count); |
| 858 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 859 | p->o_arg.open_flags = flags; |
| 860 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 861 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 862 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 863 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 864 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 865 | p->o_arg.server = server; |
| 866 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 867 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 868 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 869 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 870 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 871 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 872 | p->o_arg.u.attrs = &p->attrs; |
| 873 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 874 | |
| 875 | verf[0] = jiffies; |
| 876 | verf[1] = current->pid; |
| 877 | memcpy(p->o_arg.u.verifier.data, verf, |
| 878 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 879 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 880 | p->c_arg.fh = &p->o_res.fh; |
| 881 | p->c_arg.stateid = &p->o_res.stateid; |
| 882 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 883 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 884 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 885 | return p; |
| 886 | err_free: |
| 887 | kfree(p); |
| 888 | err: |
| 889 | dput(parent); |
| 890 | return NULL; |
| 891 | } |
| 892 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 893 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 894 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 895 | struct nfs4_opendata *p = container_of(kref, |
| 896 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 897 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 898 | |
| 899 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 900 | if (p->state != NULL) |
| 901 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 902 | nfs4_put_state_owner(p->owner); |
| 903 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 904 | dput(p->dentry); |
| 905 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 906 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 907 | kfree(p); |
| 908 | } |
| 909 | |
| 910 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 911 | { |
| 912 | if (p != NULL) |
| 913 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 916 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 917 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 918 | int ret; |
| 919 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 920 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | 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] | 925 | { |
| 926 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 928 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 929 | goto out; |
| 930 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 931 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 932 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 933 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 934 | break; |
| 935 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 936 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 937 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 938 | break; |
| 939 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 940 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 941 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 942 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 943 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 944 | return ret; |
| 945 | } |
| 946 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 948 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 949 | if (delegation == NULL) |
| 950 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 952 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 953 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 954 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 955 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 956 | return 1; |
| 957 | } |
| 958 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 960 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 962 | case FMODE_WRITE: |
| 963 | state->n_wronly++; |
| 964 | break; |
| 965 | case FMODE_READ: |
| 966 | state->n_rdonly++; |
| 967 | break; |
| 968 | case FMODE_READ|FMODE_WRITE: |
| 969 | state->n_rdwr++; |
| 970 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 971 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 972 | } |
| 973 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 974 | 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] | 975 | { |
| 976 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 977 | nfs4_stateid_copy(&state->stateid, stateid); |
| 978 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 979 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 980 | case FMODE_READ: |
| 981 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 982 | break; |
| 983 | case FMODE_WRITE: |
| 984 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 985 | break; |
| 986 | case FMODE_READ|FMODE_WRITE: |
| 987 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 988 | } |
| 989 | } |
| 990 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 991 | 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] | 992 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 993 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 994 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 995 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 996 | } |
| 997 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | 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] | 999 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1000 | /* |
| 1001 | * Protect the call to nfs4_state_set_mode_locked and |
| 1002 | * serialise the stateid update |
| 1003 | */ |
| 1004 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1005 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1006 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1007 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1008 | } |
| 1009 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1010 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1011 | write_sequnlock(&state->seqlock); |
| 1012 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1014 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | 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] | 1018 | { |
| 1019 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1020 | struct nfs_delegation *deleg_cur; |
| 1021 | int ret = 0; |
| 1022 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1023 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1024 | |
| 1025 | rcu_read_lock(); |
| 1026 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1027 | if (deleg_cur == NULL) |
| 1028 | goto no_delegation; |
| 1029 | |
| 1030 | spin_lock(&deleg_cur->lock); |
| 1031 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1032 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1033 | goto no_delegation_unlock; |
| 1034 | |
| 1035 | if (delegation == NULL) |
| 1036 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1037 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1038 | goto no_delegation_unlock; |
| 1039 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1040 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1041 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1042 | ret = 1; |
| 1043 | no_delegation_unlock: |
| 1044 | spin_unlock(&deleg_cur->lock); |
| 1045 | no_delegation: |
| 1046 | rcu_read_unlock(); |
| 1047 | |
| 1048 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1049 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1050 | ret = 1; |
| 1051 | } |
| 1052 | |
| 1053 | return ret; |
| 1054 | } |
| 1055 | |
| 1056 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1057 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1058 | { |
| 1059 | struct nfs_delegation *delegation; |
| 1060 | |
| 1061 | rcu_read_lock(); |
| 1062 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1063 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1064 | rcu_read_unlock(); |
| 1065 | return; |
| 1066 | } |
| 1067 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1068 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1071 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1072 | { |
| 1073 | struct nfs4_state *state = opendata->state; |
| 1074 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1075 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1076 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1077 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1078 | nfs4_stateid stateid; |
| 1079 | int ret = -EAGAIN; |
| 1080 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1081 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1082 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1083 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1084 | if (can_open_cached(state, fmode, open_mode)) { |
| 1085 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1086 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1087 | goto out_return_state; |
| 1088 | } |
| 1089 | spin_unlock(&state->owner->so_lock); |
| 1090 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1091 | rcu_read_lock(); |
| 1092 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1093 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1094 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1095 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1096 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1097 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1098 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1099 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1100 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1101 | if (ret != 0) |
| 1102 | goto out; |
| 1103 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1104 | |
| 1105 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1106 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1107 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1108 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1109 | out: |
| 1110 | return ERR_PTR(ret); |
| 1111 | out_return_state: |
| 1112 | atomic_inc(&state->count); |
| 1113 | return state; |
| 1114 | } |
| 1115 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1116 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1117 | { |
| 1118 | struct inode *inode; |
| 1119 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1120 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1121 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1122 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1123 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1124 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1125 | goto out; |
| 1126 | } |
| 1127 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1128 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1129 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1130 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1131 | 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] | 1132 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1133 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1134 | goto err; |
| 1135 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1136 | state = nfs4_get_open_state(inode, data->owner); |
| 1137 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1138 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1139 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1140 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1141 | int delegation_flags = 0; |
| 1142 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1143 | rcu_read_lock(); |
| 1144 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1145 | if (delegation) |
| 1146 | delegation_flags = delegation->flags; |
| 1147 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1148 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1149 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1150 | "returning a delegation for " |
| 1151 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1152 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1153 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1154 | nfs_inode_set_delegation(state->inode, |
| 1155 | data->owner->so_cred, |
| 1156 | &data->o_res); |
| 1157 | else |
| 1158 | nfs_inode_reclaim_delegation(state->inode, |
| 1159 | data->owner->so_cred, |
| 1160 | &data->o_res); |
| 1161 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1162 | |
| 1163 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1164 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1165 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1166 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1167 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1168 | err_put_inode: |
| 1169 | iput(inode); |
| 1170 | err: |
| 1171 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1172 | } |
| 1173 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1174 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1175 | { |
| 1176 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1177 | struct nfs_open_context *ctx; |
| 1178 | |
| 1179 | spin_lock(&state->inode->i_lock); |
| 1180 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1181 | if (ctx->state != state) |
| 1182 | continue; |
| 1183 | get_nfs_open_context(ctx); |
| 1184 | spin_unlock(&state->inode->i_lock); |
| 1185 | return ctx; |
| 1186 | } |
| 1187 | spin_unlock(&state->inode->i_lock); |
| 1188 | return ERR_PTR(-ENOENT); |
| 1189 | } |
| 1190 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1191 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1192 | { |
| 1193 | struct nfs4_opendata *opendata; |
| 1194 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1195 | 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] | 1196 | if (opendata == NULL) |
| 1197 | return ERR_PTR(-ENOMEM); |
| 1198 | opendata->state = state; |
| 1199 | atomic_inc(&state->count); |
| 1200 | return opendata; |
| 1201 | } |
| 1202 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1203 | 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] | 1204 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1205 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1206 | int ret; |
| 1207 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1208 | opendata->o_arg.open_flags = 0; |
| 1209 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1210 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1211 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1212 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1213 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1214 | if (ret != 0) |
| 1215 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1216 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1217 | if (IS_ERR(newstate)) |
| 1218 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1219 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1220 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
| 1223 | |
| 1224 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1225 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1226 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1227 | int ret; |
| 1228 | |
| 1229 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1230 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1231 | smp_rmb(); |
| 1232 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1233 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1234 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1235 | if (ret != 0) |
| 1236 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1237 | if (newstate != state) |
| 1238 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | } |
| 1240 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1241 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1242 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1243 | if (ret != 0) |
| 1244 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1245 | if (newstate != state) |
| 1246 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1247 | } |
| 1248 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1249 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1250 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | if (ret != 0) |
| 1252 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1253 | if (newstate != state) |
| 1254 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1255 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1256 | /* |
| 1257 | * We may have performed cached opens for all three recoveries. |
| 1258 | * Check if we need to update the current stateid. |
| 1259 | */ |
| 1260 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1261 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1262 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1263 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1264 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1265 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1266 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1267 | return 0; |
| 1268 | } |
| 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | /* |
| 1271 | * OPEN_RECLAIM: |
| 1272 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1274 | 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] | 1275 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1276 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1277 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1278 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | int status; |
| 1280 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1281 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1282 | if (IS_ERR(opendata)) |
| 1283 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1284 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1285 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1286 | rcu_read_lock(); |
| 1287 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1288 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1289 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1290 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1291 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1292 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1293 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | return status; |
| 1295 | } |
| 1296 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1297 | 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] | 1298 | { |
| 1299 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1300 | struct nfs4_exception exception = { }; |
| 1301 | int err; |
| 1302 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1303 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1304 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1305 | break; |
| 1306 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | } while (exception.retry); |
| 1308 | return err; |
| 1309 | } |
| 1310 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1311 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1312 | { |
| 1313 | struct nfs_open_context *ctx; |
| 1314 | int ret; |
| 1315 | |
| 1316 | ctx = nfs4_state_find_open_context(state); |
| 1317 | if (IS_ERR(ctx)) |
| 1318 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1319 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1320 | put_nfs_open_context(ctx); |
| 1321 | return ret; |
| 1322 | } |
| 1323 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1324 | 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] | 1325 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1326 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1327 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1329 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1330 | if (IS_ERR(opendata)) |
| 1331 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1332 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1333 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1334 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1335 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1336 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1339 | 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] | 1340 | { |
| 1341 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1342 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | int err; |
| 1344 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1345 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | switch (err) { |
| 1347 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1348 | case -ENOENT: |
| 1349 | case -ESTALE: |
| 1350 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1351 | case -NFS4ERR_BADSESSION: |
| 1352 | case -NFS4ERR_BADSLOT: |
| 1353 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1354 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1355 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1356 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1357 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | case -NFS4ERR_STALE_CLIENTID: |
| 1359 | case -NFS4ERR_STALE_STATEID: |
| 1360 | case -NFS4ERR_EXPIRED: |
| 1361 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1362 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1363 | goto out; |
| 1364 | case -ERESTARTSYS: |
| 1365 | /* |
| 1366 | * The show must go on: exit, but mark the |
| 1367 | * stateid as needing recovery. |
| 1368 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1369 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1370 | case -NFS4ERR_ADMIN_REVOKED: |
| 1371 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1372 | nfs_inode_find_state_and_recover(state->inode, |
| 1373 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1374 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1375 | case -EKEYEXPIRED: |
| 1376 | /* |
| 1377 | * User RPCSEC_GSS context has expired. |
| 1378 | * We cannot recover this stateid now, so |
| 1379 | * skip it and allow recovery thread to |
| 1380 | * proceed. |
| 1381 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1382 | case -ENOMEM: |
| 1383 | err = 0; |
| 1384 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | } |
| 1386 | err = nfs4_handle_exception(server, err, &exception); |
| 1387 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1388 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | return err; |
| 1390 | } |
| 1391 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1392 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1393 | { |
| 1394 | struct nfs4_opendata *data = calldata; |
| 1395 | |
| 1396 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1397 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1398 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1399 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1400 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1401 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1402 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | static void nfs4_open_confirm_release(void *calldata) |
| 1406 | { |
| 1407 | struct nfs4_opendata *data = calldata; |
| 1408 | struct nfs4_state *state = NULL; |
| 1409 | |
| 1410 | /* If this request hasn't been cancelled, do nothing */ |
| 1411 | if (data->cancelled == 0) |
| 1412 | goto out_free; |
| 1413 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1414 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1415 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1416 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1417 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1418 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1419 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1420 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1424 | .rpc_call_done = nfs4_open_confirm_done, |
| 1425 | .rpc_release = nfs4_open_confirm_release, |
| 1426 | }; |
| 1427 | |
| 1428 | /* |
| 1429 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1430 | */ |
| 1431 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1432 | { |
| 1433 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1434 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1435 | struct rpc_message msg = { |
| 1436 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1437 | .rpc_argp = &data->c_arg, |
| 1438 | .rpc_resp = &data->c_res, |
| 1439 | .rpc_cred = data->owner->so_cred, |
| 1440 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1441 | struct rpc_task_setup task_setup_data = { |
| 1442 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1443 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1444 | .callback_ops = &nfs4_open_confirm_ops, |
| 1445 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1446 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1447 | .flags = RPC_TASK_ASYNC, |
| 1448 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | int status; |
| 1450 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1451 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1452 | data->rpc_done = 0; |
| 1453 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1454 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1455 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1456 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1457 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1458 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1459 | if (status != 0) { |
| 1460 | data->cancelled = 1; |
| 1461 | smp_wmb(); |
| 1462 | } else |
| 1463 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1464 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | return status; |
| 1466 | } |
| 1467 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1470 | struct nfs4_opendata *data = calldata; |
| 1471 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1472 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1473 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1474 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1475 | /* |
| 1476 | * Check if we still need to send an OPEN call, or if we can use |
| 1477 | * a delegation instead. |
| 1478 | */ |
| 1479 | if (data->state != NULL) { |
| 1480 | struct nfs_delegation *delegation; |
| 1481 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1482 | 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] | 1483 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1484 | rcu_read_lock(); |
| 1485 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1486 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1487 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1488 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1489 | rcu_read_unlock(); |
| 1490 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1491 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1492 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1493 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1494 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1495 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1496 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1497 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1498 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1499 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1500 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1501 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1502 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1503 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1504 | unlock_no_action: |
| 1505 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1506 | out_no_action: |
| 1507 | task->tk_action = NULL; |
| 1508 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1511 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1512 | { |
| 1513 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1514 | nfs4_open_prepare(task, calldata); |
| 1515 | } |
| 1516 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1517 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1518 | { |
| 1519 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1522 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1523 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1524 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1525 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1526 | if (task->tk_status == 0) { |
| 1527 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1528 | case S_IFREG: |
| 1529 | break; |
| 1530 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1531 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1532 | break; |
| 1533 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1534 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1535 | break; |
| 1536 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1537 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1538 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1539 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1540 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1541 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1542 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1543 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1545 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1546 | static void nfs4_open_release(void *calldata) |
| 1547 | { |
| 1548 | struct nfs4_opendata *data = calldata; |
| 1549 | struct nfs4_state *state = NULL; |
| 1550 | |
| 1551 | /* If this request hasn't been cancelled, do nothing */ |
| 1552 | if (data->cancelled == 0) |
| 1553 | goto out_free; |
| 1554 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1555 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1556 | goto out_free; |
| 1557 | /* In case we need an open_confirm, no cleanup! */ |
| 1558 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1559 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1560 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1561 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1562 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1563 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1564 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1568 | .rpc_call_prepare = nfs4_open_prepare, |
| 1569 | .rpc_call_done = nfs4_open_done, |
| 1570 | .rpc_release = nfs4_open_release, |
| 1571 | }; |
| 1572 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1573 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1574 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1575 | .rpc_call_done = nfs4_open_done, |
| 1576 | .rpc_release = nfs4_open_release, |
| 1577 | }; |
| 1578 | |
| 1579 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1580 | { |
| 1581 | struct inode *dir = data->dir->d_inode; |
| 1582 | struct nfs_server *server = NFS_SERVER(dir); |
| 1583 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1584 | struct nfs_openres *o_res = &data->o_res; |
| 1585 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1586 | struct rpc_message msg = { |
| 1587 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1588 | .rpc_argp = o_arg, |
| 1589 | .rpc_resp = o_res, |
| 1590 | .rpc_cred = data->owner->so_cred, |
| 1591 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1592 | struct rpc_task_setup task_setup_data = { |
| 1593 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1594 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1595 | .callback_ops = &nfs4_open_ops, |
| 1596 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1597 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1598 | .flags = RPC_TASK_ASYNC, |
| 1599 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1600 | int status; |
| 1601 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1602 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1603 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1604 | data->rpc_done = 0; |
| 1605 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1606 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1607 | if (isrecover) |
| 1608 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1609 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1610 | if (IS_ERR(task)) |
| 1611 | return PTR_ERR(task); |
| 1612 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1613 | if (status != 0) { |
| 1614 | data->cancelled = 1; |
| 1615 | smp_wmb(); |
| 1616 | } else |
| 1617 | status = data->rpc_status; |
| 1618 | rpc_put_task(task); |
| 1619 | |
| 1620 | return status; |
| 1621 | } |
| 1622 | |
| 1623 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1624 | { |
| 1625 | struct inode *dir = data->dir->d_inode; |
| 1626 | struct nfs_openres *o_res = &data->o_res; |
| 1627 | int status; |
| 1628 | |
| 1629 | status = nfs4_run_open_task(data, 1); |
| 1630 | if (status != 0 || !data->rpc_done) |
| 1631 | return status; |
| 1632 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1633 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1634 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1635 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1636 | status = _nfs4_proc_open_confirm(data); |
| 1637 | if (status != 0) |
| 1638 | return status; |
| 1639 | } |
| 1640 | |
| 1641 | return status; |
| 1642 | } |
| 1643 | |
| 1644 | /* |
| 1645 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1646 | */ |
| 1647 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1648 | { |
| 1649 | struct inode *dir = data->dir->d_inode; |
| 1650 | struct nfs_server *server = NFS_SERVER(dir); |
| 1651 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1652 | struct nfs_openres *o_res = &data->o_res; |
| 1653 | int status; |
| 1654 | |
| 1655 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1656 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1657 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1658 | if (status != 0) { |
| 1659 | if (status == -NFS4ERR_BADNAME && |
| 1660 | !(o_arg->open_flags & O_CREAT)) |
| 1661 | return -ENOENT; |
| 1662 | return status; |
| 1663 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1664 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1665 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1666 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1667 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1668 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1669 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1670 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1672 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1674 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1677 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1681 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1682 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1683 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1684 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1685 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1686 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1687 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1688 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1689 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1690 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1691 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1692 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1693 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1694 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1695 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1696 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1697 | } |
| 1698 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1699 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1700 | { |
| 1701 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1702 | } |
| 1703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | /* |
| 1705 | * OPEN_EXPIRED: |
| 1706 | * reclaim state on the server after a network partition. |
| 1707 | * Assumes caller holds the appropriate lock |
| 1708 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1709 | 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] | 1710 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1711 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1712 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1714 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1715 | if (IS_ERR(opendata)) |
| 1716 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1717 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1718 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1719 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1720 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1721 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1724 | 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] | 1725 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1726 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1727 | struct nfs4_exception exception = { }; |
| 1728 | int err; |
| 1729 | |
| 1730 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1731 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1732 | switch (err) { |
| 1733 | default: |
| 1734 | goto out; |
| 1735 | case -NFS4ERR_GRACE: |
| 1736 | case -NFS4ERR_DELAY: |
| 1737 | nfs4_handle_exception(server, err, &exception); |
| 1738 | err = 0; |
| 1739 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1740 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1741 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1742 | return err; |
| 1743 | } |
| 1744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1746 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1748 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1750 | ctx = nfs4_state_find_open_context(state); |
| 1751 | if (IS_ERR(ctx)) |
| 1752 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1753 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1754 | put_nfs_open_context(ctx); |
| 1755 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1758 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame^] | 1759 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1760 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1761 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame^] | 1762 | nfs4_stateid *stateid = &state->stateid; |
| 1763 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1764 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame^] | 1765 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1766 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1767 | return; |
| 1768 | |
| 1769 | status = nfs41_test_stateid(server, stateid); |
| 1770 | if (status != NFS_OK) { |
| 1771 | /* Free the stateid unless the server explicitly |
| 1772 | * informs us the stateid is unrecognized. */ |
| 1773 | if (status != -NFS4ERR_BAD_STATEID) |
| 1774 | nfs41_free_stateid(server, stateid); |
| 1775 | |
| 1776 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1782 | * |
| 1783 | * @state: NFSv4 state for an inode |
| 1784 | * |
| 1785 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1786 | * Otherwise a negative NFS4ERR value is returned. |
| 1787 | */ |
| 1788 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1789 | { |
| 1790 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1791 | nfs4_stateid *stateid = &state->stateid; |
| 1792 | int status; |
| 1793 | |
| 1794 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1795 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1796 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1797 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1798 | return -NFS4ERR_BAD_STATEID; |
| 1799 | |
| 1800 | status = nfs41_test_stateid(server, stateid); |
| 1801 | if (status != NFS_OK) { |
| 1802 | /* Free the stateid unless the server explicitly |
| 1803 | * informs us the stateid is unrecognized. */ |
| 1804 | if (status != -NFS4ERR_BAD_STATEID) |
| 1805 | nfs41_free_stateid(server, stateid); |
| 1806 | |
| 1807 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1808 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1809 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1810 | } |
| 1811 | return status; |
| 1812 | } |
| 1813 | |
| 1814 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1815 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1816 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1817 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame^] | 1818 | nfs41_clear_delegation_stateid(state); |
| 1819 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1820 | if (status != NFS_OK) |
| 1821 | status = nfs4_open_expired(sp, state); |
| 1822 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1823 | } |
| 1824 | #endif |
| 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1827 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1828 | * fields corresponding to attributes that were used to store the verifier. |
| 1829 | * Make sure we clobber those fields in the later setattr call |
| 1830 | */ |
| 1831 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1832 | { |
| 1833 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1834 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1835 | sattr->ia_valid |= ATTR_ATIME; |
| 1836 | |
| 1837 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1838 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1839 | sattr->ia_valid |= ATTR_MTIME; |
| 1840 | } |
| 1841 | |
| 1842 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1843 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1845 | static int _nfs4_do_open(struct inode *dir, |
| 1846 | struct dentry *dentry, |
| 1847 | fmode_t fmode, |
| 1848 | int flags, |
| 1849 | struct iattr *sattr, |
| 1850 | struct rpc_cred *cred, |
| 1851 | struct nfs4_state **res, |
| 1852 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | { |
| 1854 | struct nfs4_state_owner *sp; |
| 1855 | struct nfs4_state *state = NULL; |
| 1856 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1857 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1858 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | |
| 1860 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1862 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1863 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1865 | goto out_err; |
| 1866 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1867 | status = nfs4_recover_expired_lease(server); |
| 1868 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1869 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1870 | if (dentry->d_inode != NULL) |
| 1871 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1872 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1873 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1874 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1875 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1877 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1878 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1879 | if (!opendata->f_attr.mdsthreshold) |
| 1880 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1881 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1882 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1883 | if (dentry->d_inode != NULL) |
| 1884 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1885 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1886 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1888 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1890 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1891 | status = PTR_ERR(state); |
| 1892 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1893 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1894 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1895 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1896 | |
| 1897 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1898 | nfs4_exclusive_attrset(opendata, sattr); |
| 1899 | |
| 1900 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1901 | status = nfs4_do_setattr(state->inode, cred, |
| 1902 | opendata->o_res.f_attr, sattr, |
| 1903 | state); |
| 1904 | if (status == 0) |
| 1905 | nfs_setattr_update_inode(state->inode, sattr); |
| 1906 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1907 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1908 | |
| 1909 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1910 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1911 | else |
| 1912 | kfree(opendata->f_attr.mdsthreshold); |
| 1913 | opendata->f_attr.mdsthreshold = NULL; |
| 1914 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1915 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | *res = state; |
| 1918 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1919 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1920 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1921 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1922 | err_put_state_owner: |
| 1923 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | *res = NULL; |
| 1926 | return status; |
| 1927 | } |
| 1928 | |
| 1929 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1930 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1931 | struct dentry *dentry, |
| 1932 | fmode_t fmode, |
| 1933 | int flags, |
| 1934 | struct iattr *sattr, |
| 1935 | struct rpc_cred *cred, |
| 1936 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | { |
| 1938 | struct nfs4_exception exception = { }; |
| 1939 | struct nfs4_state *res; |
| 1940 | int status; |
| 1941 | |
Trond Myklebust | 2d0dbc6 | 2012-06-08 10:58:09 -0400 | [diff] [blame] | 1942 | fmode &= FMODE_READ|FMODE_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1944 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1945 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | if (status == 0) |
| 1947 | break; |
| 1948 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1949 | * book-keeping w.r.t. state-changing operations |
| 1950 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1951 | * It is actually a sign of a bug on the client or on the server. |
| 1952 | * |
| 1953 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1954 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | * have unhashed the old state_owner for us, and that we can |
| 1956 | * therefore safely retry using a new one. We should still warn |
| 1957 | * the user though... |
| 1958 | */ |
| 1959 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1960 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1961 | " returned a bad sequence-id error!\n", |
| 1962 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | exception.retry = 1; |
| 1964 | continue; |
| 1965 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1966 | /* |
| 1967 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1968 | * state before it received the OPEN_CONFIRM. |
| 1969 | * Recover by retrying the request as per the discussion |
| 1970 | * on Page 181 of RFC3530. |
| 1971 | */ |
| 1972 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1973 | exception.retry = 1; |
| 1974 | continue; |
| 1975 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1976 | if (status == -EAGAIN) { |
| 1977 | /* We must have found a delegation */ |
| 1978 | exception.retry = 1; |
| 1979 | continue; |
| 1980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1982 | status, &exception)); |
| 1983 | } while (exception.retry); |
| 1984 | return res; |
| 1985 | } |
| 1986 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1987 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1988 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1989 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1991 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1993 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | .iap = sattr, |
| 1995 | .server = server, |
| 1996 | .bitmask = server->attr_bitmask, |
| 1997 | }; |
| 1998 | struct nfs_setattrres res = { |
| 1999 | .fattr = fattr, |
| 2000 | .server = server, |
| 2001 | }; |
| 2002 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2003 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2004 | .rpc_argp = &arg, |
| 2005 | .rpc_resp = &res, |
| 2006 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2008 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2009 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2011 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2013 | if (state != NULL) { |
| 2014 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2015 | current->files, current->tgid); |
| 2016 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2017 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2018 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2019 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2020 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2022 | 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] | 2023 | if (status == 0 && state != NULL) |
| 2024 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2025 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2028 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2029 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2030 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2032 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2033 | struct nfs4_exception exception = { |
| 2034 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2035 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2036 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | int err; |
| 2038 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2039 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2040 | switch (err) { |
| 2041 | case -NFS4ERR_OPENMODE: |
| 2042 | if (state && !(state->state & FMODE_WRITE)) { |
| 2043 | err = -EBADF; |
| 2044 | if (sattr->ia_valid & ATTR_OPEN) |
| 2045 | err = -EACCES; |
| 2046 | goto out; |
| 2047 | } |
| 2048 | } |
| 2049 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2051 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | return err; |
| 2053 | } |
| 2054 | |
| 2055 | struct nfs4_closedata { |
| 2056 | struct inode *inode; |
| 2057 | struct nfs4_state *state; |
| 2058 | struct nfs_closeargs arg; |
| 2059 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2060 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2061 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2062 | bool roc; |
| 2063 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | }; |
| 2065 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2066 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2067 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2068 | struct nfs4_closedata *calldata = data; |
| 2069 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2070 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2071 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2072 | if (calldata->roc) |
| 2073 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2074 | nfs4_put_open_state(calldata->state); |
| 2075 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2076 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2077 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2078 | kfree(calldata); |
| 2079 | } |
| 2080 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2081 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2082 | fmode_t fmode) |
| 2083 | { |
| 2084 | spin_lock(&state->owner->so_lock); |
| 2085 | if (!(fmode & FMODE_READ)) |
| 2086 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2087 | if (!(fmode & FMODE_WRITE)) |
| 2088 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2089 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2090 | spin_unlock(&state->owner->so_lock); |
| 2091 | } |
| 2092 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2093 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2095 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2098 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2099 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2100 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2101 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | /* hmm. we are done with the inode, and in the process of freeing |
| 2103 | * the state_owner. we keep this around to process errors |
| 2104 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | switch (task->tk_status) { |
| 2106 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2107 | if (calldata->roc) |
| 2108 | pnfs_roc_set_barrier(state->inode, |
| 2109 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2110 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2111 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2112 | nfs4_close_clear_stateid_flags(state, |
| 2113 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | break; |
| 2115 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2116 | case -NFS4ERR_OLD_STATEID: |
| 2117 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2119 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2120 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2122 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2123 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2125 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2126 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2127 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2130 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2132 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2133 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2134 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2135 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2136 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2137 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2138 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2139 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2140 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2141 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2142 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2143 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2144 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2145 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2146 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2147 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2148 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2149 | } |
| 2150 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2151 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2152 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2153 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2154 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2155 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2156 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2157 | |
| 2158 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2159 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2160 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2161 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2162 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2163 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2164 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2165 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2166 | if (calldata->roc && |
| 2167 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2168 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2169 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2170 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2171 | } |
| 2172 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2173 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2174 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2175 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2176 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2177 | &calldata->arg.seq_args, |
| 2178 | &calldata->res.seq_res, |
| 2179 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2180 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2181 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2182 | out: |
| 2183 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2186 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2187 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2188 | .rpc_call_done = nfs4_close_done, |
| 2189 | .rpc_release = nfs4_free_closedata, |
| 2190 | }; |
| 2191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | /* |
| 2193 | * It is possible for data to be read/written from a mem-mapped file |
| 2194 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2195 | * This means that we can't safely call nfsv4 close on a file until |
| 2196 | * the inode is cleared. This in turn means that we are not good |
| 2197 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2198 | * share state even when we are done with one of the three share |
| 2199 | * stateid's in the inode. |
| 2200 | * |
| 2201 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2202 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2203 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2205 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2207 | struct nfs4_state_owner *sp = state->owner; |
| 2208 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2209 | struct rpc_message msg = { |
| 2210 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2211 | .rpc_cred = state->owner->so_cred, |
| 2212 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2213 | struct rpc_task_setup task_setup_data = { |
| 2214 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2215 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2216 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2217 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2218 | .flags = RPC_TASK_ASYNC, |
| 2219 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2220 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2222 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2224 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2225 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2226 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2228 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2229 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2231 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2232 | if (calldata->arg.seqid == NULL) |
| 2233 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2234 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2235 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2236 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2237 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2238 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2239 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2240 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2241 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2242 | msg.rpc_argp = &calldata->arg; |
| 2243 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2244 | task_setup_data.callback_data = calldata; |
| 2245 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2246 | if (IS_ERR(task)) |
| 2247 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2248 | status = 0; |
| 2249 | if (wait) |
| 2250 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2251 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2252 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2253 | out_free_calldata: |
| 2254 | kfree(calldata); |
| 2255 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2256 | if (roc) |
| 2257 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2258 | nfs4_put_open_state(state); |
| 2259 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2260 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2263 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2264 | 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] | 2265 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | struct nfs4_state *state; |
| 2267 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2268 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2269 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2270 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2271 | if (IS_ERR(state)) |
| 2272 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2273 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2274 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2277 | 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] | 2278 | { |
| 2279 | if (ctx->state == NULL) |
| 2280 | return; |
| 2281 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2282 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2283 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2284 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
| 2287 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2288 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2289 | struct nfs4_server_caps_arg args = { |
| 2290 | .fhandle = fhandle, |
| 2291 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | struct nfs4_server_caps_res res = {}; |
| 2293 | struct rpc_message msg = { |
| 2294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2295 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | .rpc_resp = &res, |
| 2297 | }; |
| 2298 | int status; |
| 2299 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2300 | 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] | 2301 | if (status == 0) { |
| 2302 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2303 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2304 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2305 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2306 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2307 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2309 | server->caps |= NFS_CAP_ACLS; |
| 2310 | if (res.has_links != 0) |
| 2311 | server->caps |= NFS_CAP_HARDLINKS; |
| 2312 | if (res.has_symlinks != 0) |
| 2313 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2314 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2315 | server->caps |= NFS_CAP_FILEID; |
| 2316 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2317 | server->caps |= NFS_CAP_MODE; |
| 2318 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2319 | server->caps |= NFS_CAP_NLINK; |
| 2320 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2321 | server->caps |= NFS_CAP_OWNER; |
| 2322 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2323 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2324 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2325 | server->caps |= NFS_CAP_ATIME; |
| 2326 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2327 | server->caps |= NFS_CAP_CTIME; |
| 2328 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2329 | server->caps |= NFS_CAP_MTIME; |
| 2330 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2331 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2332 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2333 | 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] | 2334 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2335 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | return status; |
| 2339 | } |
| 2340 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2341 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | { |
| 2343 | struct nfs4_exception exception = { }; |
| 2344 | int err; |
| 2345 | do { |
| 2346 | err = nfs4_handle_exception(server, |
| 2347 | _nfs4_server_capabilities(server, fhandle), |
| 2348 | &exception); |
| 2349 | } while (exception.retry); |
| 2350 | return err; |
| 2351 | } |
| 2352 | |
| 2353 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2354 | struct nfs_fsinfo *info) |
| 2355 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | struct nfs4_lookup_root_arg args = { |
| 2357 | .bitmask = nfs4_fattr_bitmap, |
| 2358 | }; |
| 2359 | struct nfs4_lookup_res res = { |
| 2360 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2361 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | .fh = fhandle, |
| 2363 | }; |
| 2364 | struct rpc_message msg = { |
| 2365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2366 | .rpc_argp = &args, |
| 2367 | .rpc_resp = &res, |
| 2368 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2369 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2370 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2371 | 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] | 2372 | } |
| 2373 | |
| 2374 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2375 | struct nfs_fsinfo *info) |
| 2376 | { |
| 2377 | struct nfs4_exception exception = { }; |
| 2378 | int err; |
| 2379 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2380 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2381 | switch (err) { |
| 2382 | case 0: |
| 2383 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2384 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2385 | default: |
| 2386 | err = nfs4_handle_exception(server, err, &exception); |
| 2387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2389 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | return err; |
| 2391 | } |
| 2392 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2393 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2394 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2395 | { |
| 2396 | struct rpc_auth *auth; |
| 2397 | int ret; |
| 2398 | |
| 2399 | auth = rpcauth_create(flavor, server->client); |
| 2400 | if (!auth) { |
| 2401 | ret = -EIO; |
| 2402 | goto out; |
| 2403 | } |
| 2404 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2405 | out: |
| 2406 | return ret; |
| 2407 | } |
| 2408 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2409 | 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] | 2410 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2412 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2413 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2415 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2416 | flav_array[len] = RPC_AUTH_NULL; |
| 2417 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2418 | |
| 2419 | for (i = 0; i < len; i++) { |
| 2420 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2421 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2422 | continue; |
| 2423 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2424 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2425 | /* |
| 2426 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2427 | * to access the mount. It could also mean that we tried to mount |
| 2428 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2429 | * existing mount programs don't handle -EACCES very well so it should |
| 2430 | * be mapped to -EPERM instead. |
| 2431 | */ |
| 2432 | if (status == -EACCES) |
| 2433 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2434 | return status; |
| 2435 | } |
| 2436 | |
| 2437 | /* |
| 2438 | * get the file handle for the "/" directory on the server |
| 2439 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2440 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2441 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2442 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2443 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2444 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2445 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2446 | /* |
| 2447 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2448 | * by nfs4_map_errors() as this function exits. |
| 2449 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2450 | 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] | 2451 | if (status == 0) |
| 2452 | status = nfs4_server_capabilities(server, fhandle); |
| 2453 | if (status == 0) |
| 2454 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2455 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2458 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2459 | struct nfs_fsinfo *info) |
| 2460 | { |
| 2461 | int error; |
| 2462 | struct nfs_fattr *fattr = info->fattr; |
| 2463 | |
| 2464 | error = nfs4_server_capabilities(server, mntfh); |
| 2465 | if (error < 0) { |
| 2466 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2467 | return error; |
| 2468 | } |
| 2469 | |
| 2470 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2471 | if (error < 0) { |
| 2472 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2473 | return error; |
| 2474 | } |
| 2475 | |
| 2476 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2477 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2478 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2479 | |
| 2480 | return error; |
| 2481 | } |
| 2482 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2483 | /* |
| 2484 | * Get locations and (maybe) other attributes of a referral. |
| 2485 | * Note that we'll actually follow the referral later when |
| 2486 | * we detect fsid mismatch in inode revalidation |
| 2487 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2488 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2489 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2490 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2491 | { |
| 2492 | int status = -ENOMEM; |
| 2493 | struct page *page = NULL; |
| 2494 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2495 | |
| 2496 | page = alloc_page(GFP_KERNEL); |
| 2497 | if (page == NULL) |
| 2498 | goto out; |
| 2499 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2500 | if (locations == NULL) |
| 2501 | goto out; |
| 2502 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2503 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2504 | if (status != 0) |
| 2505 | goto out; |
| 2506 | /* Make sure server returned a different fsid for the referral */ |
| 2507 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2508 | dprintk("%s: server did not return a different fsid for" |
| 2509 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2510 | status = -EIO; |
| 2511 | goto out; |
| 2512 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2513 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2514 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2515 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2516 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2517 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2518 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2519 | out: |
| 2520 | if (page) |
| 2521 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2522 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2523 | return status; |
| 2524 | } |
| 2525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2527 | { |
| 2528 | struct nfs4_getattr_arg args = { |
| 2529 | .fh = fhandle, |
| 2530 | .bitmask = server->attr_bitmask, |
| 2531 | }; |
| 2532 | struct nfs4_getattr_res res = { |
| 2533 | .fattr = fattr, |
| 2534 | .server = server, |
| 2535 | }; |
| 2536 | struct rpc_message msg = { |
| 2537 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2538 | .rpc_argp = &args, |
| 2539 | .rpc_resp = &res, |
| 2540 | }; |
| 2541 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2542 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2543 | 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] | 2544 | } |
| 2545 | |
| 2546 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2547 | { |
| 2548 | struct nfs4_exception exception = { }; |
| 2549 | int err; |
| 2550 | do { |
| 2551 | err = nfs4_handle_exception(server, |
| 2552 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2553 | &exception); |
| 2554 | } while (exception.retry); |
| 2555 | return err; |
| 2556 | } |
| 2557 | |
| 2558 | /* |
| 2559 | * The file is not closed if it is opened due to the a request to change |
| 2560 | * the size of the file. The open call will not be needed once the |
| 2561 | * VFS layer lookup-intents are implemented. |
| 2562 | * |
| 2563 | * Close is called when the inode is destroyed. |
| 2564 | * If we haven't opened the file for O_WRONLY, we |
| 2565 | * need to in the size_change case to obtain a stateid. |
| 2566 | * |
| 2567 | * Got race? |
| 2568 | * Because OPEN is always done by name in nfsv4, it is |
| 2569 | * possible that we opened a different file by the same |
| 2570 | * name. We can recognize this race condition, but we |
| 2571 | * can't do anything about it besides returning an error. |
| 2572 | * |
| 2573 | * This will be fixed with VFS changes (lookup-intent). |
| 2574 | */ |
| 2575 | static int |
| 2576 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2577 | struct iattr *sattr) |
| 2578 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2579 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2580 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2581 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | int status; |
| 2583 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2584 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2585 | pnfs_return_layout(inode); |
| 2586 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2587 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2589 | /* Deal with open(O_TRUNC) */ |
| 2590 | if (sattr->ia_valid & ATTR_OPEN) |
| 2591 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2592 | |
| 2593 | /* Optimization: if the end result is no change, don't RPC */ |
| 2594 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2595 | return 0; |
| 2596 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2597 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2598 | if (sattr->ia_valid & ATTR_FILE) { |
| 2599 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2600 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2601 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2602 | if (ctx) { |
| 2603 | cred = ctx->cred; |
| 2604 | state = ctx->state; |
| 2605 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2609 | if (status == 0) |
| 2610 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | return status; |
| 2612 | } |
| 2613 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2614 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2615 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2616 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2617 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2618 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2619 | int status; |
| 2620 | struct nfs4_lookup_arg args = { |
| 2621 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2622 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2623 | .name = name, |
| 2624 | }; |
| 2625 | struct nfs4_lookup_res res = { |
| 2626 | .server = server, |
| 2627 | .fattr = fattr, |
| 2628 | .fh = fhandle, |
| 2629 | }; |
| 2630 | struct rpc_message msg = { |
| 2631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2632 | .rpc_argp = &args, |
| 2633 | .rpc_resp = &res, |
| 2634 | }; |
| 2635 | |
| 2636 | nfs_fattr_init(fattr); |
| 2637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2639 | 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] | 2640 | dprintk("NFS reply lookup: %d\n", status); |
| 2641 | return status; |
| 2642 | } |
| 2643 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2644 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2645 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2646 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2647 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2648 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2649 | fattr->nlink = 2; |
| 2650 | } |
| 2651 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2652 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2653 | struct qstr *name, struct nfs_fh *fhandle, |
| 2654 | struct nfs_fattr *fattr) |
| 2655 | { |
| 2656 | struct nfs4_exception exception = { }; |
| 2657 | struct rpc_clnt *client = *clnt; |
| 2658 | int err; |
| 2659 | do { |
| 2660 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2661 | switch (err) { |
| 2662 | case -NFS4ERR_BADNAME: |
| 2663 | err = -ENOENT; |
| 2664 | goto out; |
| 2665 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2666 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2667 | goto out; |
| 2668 | case -NFS4ERR_WRONGSEC: |
| 2669 | err = -EPERM; |
| 2670 | if (client != *clnt) |
| 2671 | goto out; |
| 2672 | |
| 2673 | client = nfs4_create_sec_client(client, dir, name); |
| 2674 | if (IS_ERR(client)) |
| 2675 | return PTR_ERR(client); |
| 2676 | |
| 2677 | exception.retry = 1; |
| 2678 | break; |
| 2679 | default: |
| 2680 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2681 | } |
| 2682 | } while (exception.retry); |
| 2683 | |
| 2684 | out: |
| 2685 | if (err == 0) |
| 2686 | *clnt = client; |
| 2687 | else if (client != *clnt) |
| 2688 | rpc_shutdown_client(client); |
| 2689 | |
| 2690 | return err; |
| 2691 | } |
| 2692 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2693 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2694 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2696 | int status; |
| 2697 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2698 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2699 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2700 | if (client != NFS_CLIENT(dir)) { |
| 2701 | rpc_shutdown_client(client); |
| 2702 | nfs_fixup_secinfo_attributes(fattr); |
| 2703 | } |
| 2704 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2707 | struct rpc_clnt * |
| 2708 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2709 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2710 | { |
| 2711 | int status; |
| 2712 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2713 | |
| 2714 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2715 | if (status < 0) { |
| 2716 | rpc_shutdown_client(client); |
| 2717 | return ERR_PTR(status); |
| 2718 | } |
| 2719 | return client; |
| 2720 | } |
| 2721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2723 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2724 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | struct nfs4_accessargs args = { |
| 2726 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2727 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2729 | struct nfs4_accessres res = { |
| 2730 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2731 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | struct rpc_message msg = { |
| 2733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2734 | .rpc_argp = &args, |
| 2735 | .rpc_resp = &res, |
| 2736 | .rpc_cred = entry->cred, |
| 2737 | }; |
| 2738 | int mode = entry->mask; |
| 2739 | int status; |
| 2740 | |
| 2741 | /* |
| 2742 | * Determine which access bits we want to ask for... |
| 2743 | */ |
| 2744 | if (mode & MAY_READ) |
| 2745 | args.access |= NFS4_ACCESS_READ; |
| 2746 | if (S_ISDIR(inode->i_mode)) { |
| 2747 | if (mode & MAY_WRITE) |
| 2748 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2749 | if (mode & MAY_EXEC) |
| 2750 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2751 | } else { |
| 2752 | if (mode & MAY_WRITE) |
| 2753 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2754 | if (mode & MAY_EXEC) |
| 2755 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2756 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2757 | |
| 2758 | res.fattr = nfs_alloc_fattr(); |
| 2759 | if (res.fattr == NULL) |
| 2760 | return -ENOMEM; |
| 2761 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2762 | 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] | 2763 | if (!status) { |
| 2764 | entry->mask = 0; |
| 2765 | if (res.access & NFS4_ACCESS_READ) |
| 2766 | entry->mask |= MAY_READ; |
| 2767 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2768 | entry->mask |= MAY_WRITE; |
| 2769 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2770 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2771 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2773 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | return status; |
| 2775 | } |
| 2776 | |
| 2777 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2778 | { |
| 2779 | struct nfs4_exception exception = { }; |
| 2780 | int err; |
| 2781 | do { |
| 2782 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2783 | _nfs4_proc_access(inode, entry), |
| 2784 | &exception); |
| 2785 | } while (exception.retry); |
| 2786 | return err; |
| 2787 | } |
| 2788 | |
| 2789 | /* |
| 2790 | * TODO: For the time being, we don't try to get any attributes |
| 2791 | * along with any of the zero-copy operations READ, READDIR, |
| 2792 | * READLINK, WRITE. |
| 2793 | * |
| 2794 | * In the case of the first three, we want to put the GETATTR |
| 2795 | * after the read-type operation -- this is because it is hard |
| 2796 | * to predict the length of a GETATTR response in v4, and thus |
| 2797 | * align the READ data correctly. This means that the GETATTR |
| 2798 | * may end up partially falling into the page cache, and we should |
| 2799 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2800 | * To do this efficiently, we need to know the total length |
| 2801 | * of data received, which doesn't seem to be available outside |
| 2802 | * of the RPC layer. |
| 2803 | * |
| 2804 | * In the case of WRITE, we also want to put the GETATTR after |
| 2805 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2806 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | * |
| 2808 | * Both of these changes to the XDR layer would in fact be quite |
| 2809 | * minor, but I decided to leave them for a subsequent patch. |
| 2810 | */ |
| 2811 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2812 | unsigned int pgbase, unsigned int pglen) |
| 2813 | { |
| 2814 | struct nfs4_readlink args = { |
| 2815 | .fh = NFS_FH(inode), |
| 2816 | .pgbase = pgbase, |
| 2817 | .pglen = pglen, |
| 2818 | .pages = &page, |
| 2819 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2820 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | struct rpc_message msg = { |
| 2822 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2823 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2824 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | }; |
| 2826 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2827 | 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] | 2828 | } |
| 2829 | |
| 2830 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2831 | unsigned int pgbase, unsigned int pglen) |
| 2832 | { |
| 2833 | struct nfs4_exception exception = { }; |
| 2834 | int err; |
| 2835 | do { |
| 2836 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2837 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2838 | &exception); |
| 2839 | } while (exception.retry); |
| 2840 | return err; |
| 2841 | } |
| 2842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2844 | * 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] | 2845 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | static int |
| 2847 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2848 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2850 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | int status = 0; |
| 2853 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2854 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2855 | if (IS_ERR(ctx)) |
| 2856 | return PTR_ERR(ctx); |
| 2857 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2858 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2859 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2860 | flags, sattr, ctx->cred, |
| 2861 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2862 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | if (IS_ERR(state)) { |
| 2864 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2865 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2867 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2868 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2869 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2871 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | return status; |
| 2873 | } |
| 2874 | |
| 2875 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2876 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2877 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2878 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2880 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2882 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2883 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2884 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2886 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2887 | .rpc_argp = &args, |
| 2888 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2890 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2891 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2892 | 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] | 2893 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2894 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | return status; |
| 2896 | } |
| 2897 | |
| 2898 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2899 | { |
| 2900 | struct nfs4_exception exception = { }; |
| 2901 | int err; |
| 2902 | do { |
| 2903 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2904 | _nfs4_proc_remove(dir, name), |
| 2905 | &exception); |
| 2906 | } while (exception.retry); |
| 2907 | return err; |
| 2908 | } |
| 2909 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2910 | 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] | 2911 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2912 | struct nfs_server *server = NFS_SERVER(dir); |
| 2913 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2914 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2916 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2918 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2921 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2922 | { |
| 2923 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2924 | &data->args.seq_args, |
| 2925 | &data->res.seq_res, |
| 2926 | task)) |
| 2927 | return; |
| 2928 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2931 | 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] | 2932 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2933 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2934 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2935 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2936 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2937 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2938 | return 0; |
| 2939 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2940 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2943 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2944 | { |
| 2945 | struct nfs_server *server = NFS_SERVER(dir); |
| 2946 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2947 | struct nfs_renameres *res = msg->rpc_resp; |
| 2948 | |
| 2949 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2950 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2951 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2952 | } |
| 2953 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2954 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2955 | { |
| 2956 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2957 | &data->args.seq_args, |
| 2958 | &data->res.seq_res, |
| 2959 | task)) |
| 2960 | return; |
| 2961 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2965 | struct inode *new_dir) |
| 2966 | { |
| 2967 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2968 | |
| 2969 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2970 | return 0; |
| 2971 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2972 | return 0; |
| 2973 | |
| 2974 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2975 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2976 | return 1; |
| 2977 | } |
| 2978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2980 | struct inode *new_dir, struct qstr *new_name) |
| 2981 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2982 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2983 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | .old_dir = NFS_FH(old_dir), |
| 2985 | .new_dir = NFS_FH(new_dir), |
| 2986 | .old_name = old_name, |
| 2987 | .new_name = new_name, |
| 2988 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2989 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2990 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2991 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | struct rpc_message msg = { |
| 2993 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2994 | .rpc_argp = &arg, |
| 2995 | .rpc_resp = &res, |
| 2996 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2997 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2999 | 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] | 3000 | if (!status) { |
| 3001 | update_changeattr(old_dir, &res.old_cinfo); |
| 3002 | update_changeattr(new_dir, &res.new_cinfo); |
| 3003 | } |
| 3004 | return status; |
| 3005 | } |
| 3006 | |
| 3007 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3008 | struct inode *new_dir, struct qstr *new_name) |
| 3009 | { |
| 3010 | struct nfs4_exception exception = { }; |
| 3011 | int err; |
| 3012 | do { |
| 3013 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3014 | _nfs4_proc_rename(old_dir, old_name, |
| 3015 | new_dir, new_name), |
| 3016 | &exception); |
| 3017 | } while (exception.retry); |
| 3018 | return err; |
| 3019 | } |
| 3020 | |
| 3021 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3022 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3023 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | struct nfs4_link_arg arg = { |
| 3025 | .fh = NFS_FH(inode), |
| 3026 | .dir_fh = NFS_FH(dir), |
| 3027 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3028 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3030 | struct nfs4_link_res res = { |
| 3031 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3032 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | struct rpc_message msg = { |
| 3034 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3035 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3036 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3038 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3040 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3041 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3042 | goto out; |
| 3043 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3044 | 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] | 3045 | if (!status) { |
| 3046 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3047 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3048 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3049 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3050 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | return status; |
| 3052 | } |
| 3053 | |
| 3054 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3055 | { |
| 3056 | struct nfs4_exception exception = { }; |
| 3057 | int err; |
| 3058 | do { |
| 3059 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3060 | _nfs4_proc_link(inode, dir, name), |
| 3061 | &exception); |
| 3062 | } while (exception.retry); |
| 3063 | return err; |
| 3064 | } |
| 3065 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3066 | struct nfs4_createdata { |
| 3067 | struct rpc_message msg; |
| 3068 | struct nfs4_create_arg arg; |
| 3069 | struct nfs4_create_res res; |
| 3070 | struct nfs_fh fh; |
| 3071 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3072 | }; |
| 3073 | |
| 3074 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3075 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3076 | { |
| 3077 | struct nfs4_createdata *data; |
| 3078 | |
| 3079 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3080 | if (data != NULL) { |
| 3081 | struct nfs_server *server = NFS_SERVER(dir); |
| 3082 | |
| 3083 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3084 | data->msg.rpc_argp = &data->arg; |
| 3085 | data->msg.rpc_resp = &data->res; |
| 3086 | data->arg.dir_fh = NFS_FH(dir); |
| 3087 | data->arg.server = server; |
| 3088 | data->arg.name = name; |
| 3089 | data->arg.attrs = sattr; |
| 3090 | data->arg.ftype = ftype; |
| 3091 | data->arg.bitmask = server->attr_bitmask; |
| 3092 | data->res.server = server; |
| 3093 | data->res.fh = &data->fh; |
| 3094 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3095 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3096 | } |
| 3097 | return data; |
| 3098 | } |
| 3099 | |
| 3100 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3101 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3102 | 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] | 3103 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3104 | if (status == 0) { |
| 3105 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3106 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3107 | } |
| 3108 | return status; |
| 3109 | } |
| 3110 | |
| 3111 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3112 | { |
| 3113 | kfree(data); |
| 3114 | } |
| 3115 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3116 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3117 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3119 | struct nfs4_createdata *data; |
| 3120 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3122 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3123 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3124 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3125 | status = -ENOMEM; |
| 3126 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3127 | if (data == NULL) |
| 3128 | goto out; |
| 3129 | |
| 3130 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3131 | data->arg.u.symlink.pages = &page; |
| 3132 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3134 | status = nfs4_do_create(dir, dentry, data); |
| 3135 | |
| 3136 | nfs4_free_createdata(data); |
| 3137 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | return status; |
| 3139 | } |
| 3140 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3141 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3142 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | { |
| 3144 | struct nfs4_exception exception = { }; |
| 3145 | int err; |
| 3146 | do { |
| 3147 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3148 | _nfs4_proc_symlink(dir, dentry, page, |
| 3149 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | &exception); |
| 3151 | } while (exception.retry); |
| 3152 | return err; |
| 3153 | } |
| 3154 | |
| 3155 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3156 | struct iattr *sattr) |
| 3157 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3158 | struct nfs4_createdata *data; |
| 3159 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3161 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3162 | if (data == NULL) |
| 3163 | goto out; |
| 3164 | |
| 3165 | status = nfs4_do_create(dir, dentry, data); |
| 3166 | |
| 3167 | nfs4_free_createdata(data); |
| 3168 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | return status; |
| 3170 | } |
| 3171 | |
| 3172 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3173 | struct iattr *sattr) |
| 3174 | { |
| 3175 | struct nfs4_exception exception = { }; |
| 3176 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3177 | |
| 3178 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | do { |
| 3180 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3181 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3182 | &exception); |
| 3183 | } while (exception.retry); |
| 3184 | return err; |
| 3185 | } |
| 3186 | |
| 3187 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3188 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | { |
| 3190 | struct inode *dir = dentry->d_inode; |
| 3191 | struct nfs4_readdir_arg args = { |
| 3192 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3193 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | .pgbase = 0, |
| 3195 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3196 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3197 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | }; |
| 3199 | struct nfs4_readdir_res res; |
| 3200 | struct rpc_message msg = { |
| 3201 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3202 | .rpc_argp = &args, |
| 3203 | .rpc_resp = &res, |
| 3204 | .rpc_cred = cred, |
| 3205 | }; |
| 3206 | int status; |
| 3207 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3208 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3209 | dentry->d_parent->d_name.name, |
| 3210 | dentry->d_name.name, |
| 3211 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3213 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3214 | 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] | 3215 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3217 | status += args.pgbase; |
| 3218 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3219 | |
| 3220 | nfs_invalidate_atime(dir); |
| 3221 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3222 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | return status; |
| 3224 | } |
| 3225 | |
| 3226 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3227 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | { |
| 3229 | struct nfs4_exception exception = { }; |
| 3230 | int err; |
| 3231 | do { |
| 3232 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3233 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3234 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | &exception); |
| 3236 | } while (exception.retry); |
| 3237 | return err; |
| 3238 | } |
| 3239 | |
| 3240 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3241 | struct iattr *sattr, dev_t rdev) |
| 3242 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3243 | struct nfs4_createdata *data; |
| 3244 | int mode = sattr->ia_mode; |
| 3245 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
| 3247 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3248 | BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3249 | |
| 3250 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3251 | if (data == NULL) |
| 3252 | goto out; |
| 3253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3255 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3257 | data->arg.ftype = NF4BLK; |
| 3258 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3259 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | } |
| 3261 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3262 | data->arg.ftype = NF4CHR; |
| 3263 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3264 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3267 | status = nfs4_do_create(dir, dentry, data); |
| 3268 | |
| 3269 | nfs4_free_createdata(data); |
| 3270 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | return status; |
| 3272 | } |
| 3273 | |
| 3274 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3275 | struct iattr *sattr, dev_t rdev) |
| 3276 | { |
| 3277 | struct nfs4_exception exception = { }; |
| 3278 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3279 | |
| 3280 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | do { |
| 3282 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3283 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3284 | &exception); |
| 3285 | } while (exception.retry); |
| 3286 | return err; |
| 3287 | } |
| 3288 | |
| 3289 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3290 | struct nfs_fsstat *fsstat) |
| 3291 | { |
| 3292 | struct nfs4_statfs_arg args = { |
| 3293 | .fh = fhandle, |
| 3294 | .bitmask = server->attr_bitmask, |
| 3295 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3296 | struct nfs4_statfs_res res = { |
| 3297 | .fsstat = fsstat, |
| 3298 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | struct rpc_message msg = { |
| 3300 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3301 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3302 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | }; |
| 3304 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3305 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3306 | 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] | 3307 | } |
| 3308 | |
| 3309 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3310 | { |
| 3311 | struct nfs4_exception exception = { }; |
| 3312 | int err; |
| 3313 | do { |
| 3314 | err = nfs4_handle_exception(server, |
| 3315 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3316 | &exception); |
| 3317 | } while (exception.retry); |
| 3318 | return err; |
| 3319 | } |
| 3320 | |
| 3321 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3322 | struct nfs_fsinfo *fsinfo) |
| 3323 | { |
| 3324 | struct nfs4_fsinfo_arg args = { |
| 3325 | .fh = fhandle, |
| 3326 | .bitmask = server->attr_bitmask, |
| 3327 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3328 | struct nfs4_fsinfo_res res = { |
| 3329 | .fsinfo = fsinfo, |
| 3330 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | struct rpc_message msg = { |
| 3332 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3333 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3334 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | }; |
| 3336 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3337 | 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] | 3338 | } |
| 3339 | |
| 3340 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3341 | { |
| 3342 | struct nfs4_exception exception = { }; |
| 3343 | int err; |
| 3344 | |
| 3345 | do { |
| 3346 | err = nfs4_handle_exception(server, |
| 3347 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3348 | &exception); |
| 3349 | } while (exception.retry); |
| 3350 | return err; |
| 3351 | } |
| 3352 | |
| 3353 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3354 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3355 | int error; |
| 3356 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3357 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3358 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3359 | if (error == 0) |
| 3360 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
| 3361 | |
| 3362 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3366 | struct nfs_pathconf *pathconf) |
| 3367 | { |
| 3368 | struct nfs4_pathconf_arg args = { |
| 3369 | .fh = fhandle, |
| 3370 | .bitmask = server->attr_bitmask, |
| 3371 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3372 | struct nfs4_pathconf_res res = { |
| 3373 | .pathconf = pathconf, |
| 3374 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | struct rpc_message msg = { |
| 3376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3377 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3378 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | }; |
| 3380 | |
| 3381 | /* None of the pathconf attributes are mandatory to implement */ |
| 3382 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3383 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3384 | return 0; |
| 3385 | } |
| 3386 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3387 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3388 | 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] | 3389 | } |
| 3390 | |
| 3391 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3392 | struct nfs_pathconf *pathconf) |
| 3393 | { |
| 3394 | struct nfs4_exception exception = { }; |
| 3395 | int err; |
| 3396 | |
| 3397 | do { |
| 3398 | err = nfs4_handle_exception(server, |
| 3399 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3400 | &exception); |
| 3401 | } while (exception.retry); |
| 3402 | return err; |
| 3403 | } |
| 3404 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3405 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3406 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3407 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3408 | } |
| 3409 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3410 | 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] | 3411 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3412 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3414 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3415 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3416 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3418 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3419 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3421 | renew_lease(server, data->timestamp); |
| 3422 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3425 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3426 | { |
| 3427 | |
| 3428 | dprintk("--> %s\n", __func__); |
| 3429 | |
| 3430 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3431 | return -EAGAIN; |
| 3432 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3433 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3434 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3437 | 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] | 3438 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3440 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3441 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3442 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3445 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3446 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3447 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3448 | &data->args.seq_args, |
| 3449 | &data->res.seq_res, |
| 3450 | task)) |
| 3451 | return; |
| 3452 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3455 | 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] | 3456 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3457 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3459 | 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] | 3460 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3461 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3463 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3465 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3466 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3467 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3470 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3471 | { |
| 3472 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3473 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3474 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3475 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3478 | static |
| 3479 | 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] | 3480 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3481 | const struct nfs_pgio_header *hdr = data->header; |
| 3482 | |
| 3483 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3484 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3485 | return false; |
| 3486 | /* Otherwise, request attributes if and only if we don't hold |
| 3487 | * a delegation |
| 3488 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3489 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3490 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3491 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3492 | 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] | 3493 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3494 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3495 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3496 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3497 | data->args.bitmask = NULL; |
| 3498 | data->res.fattr = NULL; |
| 3499 | } else |
| 3500 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3501 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3502 | if (!data->write_done_cb) |
| 3503 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3504 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | data->timestamp = jiffies; |
| 3506 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3507 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3508 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3511 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3512 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3513 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3514 | &data->args.seq_args, |
| 3515 | &data->res.seq_res, |
| 3516 | task)) |
| 3517 | return; |
| 3518 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3521 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3522 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3524 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3525 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | return; |
| 3528 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3529 | } |
| 3530 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3531 | 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] | 3532 | { |
| 3533 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3534 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3535 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3536 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3537 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3539 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3542 | 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] | 3543 | { |
| 3544 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3545 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3546 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3547 | } |
| 3548 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3549 | 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] | 3550 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3551 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3552 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3553 | if (data->commit_done_cb == NULL) |
| 3554 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3555 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3556 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3557 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3560 | struct nfs4_renewdata { |
| 3561 | struct nfs_client *client; |
| 3562 | unsigned long timestamp; |
| 3563 | }; |
| 3564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | /* |
| 3566 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3567 | * standalone procedure for queueing an asynchronous RENEW. |
| 3568 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3569 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3570 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3571 | struct nfs4_renewdata *data = calldata; |
| 3572 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3573 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3574 | if (atomic_read(&clp->cl_count) > 1) |
| 3575 | nfs4_schedule_state_renewal(clp); |
| 3576 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3577 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3578 | } |
| 3579 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3580 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3582 | struct nfs4_renewdata *data = calldata; |
| 3583 | struct nfs_client *clp = data->client; |
| 3584 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | |
| 3586 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3587 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3588 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3589 | return; |
| 3590 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3591 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3592 | return; |
| 3593 | } |
| 3594 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3596 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | } |
| 3598 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3599 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3600 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3601 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3602 | }; |
| 3603 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3604 | 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] | 3605 | { |
| 3606 | struct rpc_message msg = { |
| 3607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3608 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3609 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3611 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3613 | if (renew_flags == 0) |
| 3614 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3615 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3616 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3617 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3618 | if (data == NULL) |
| 3619 | return -ENOMEM; |
| 3620 | data->client = clp; |
| 3621 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3623 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3626 | 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] | 3627 | { |
| 3628 | struct rpc_message msg = { |
| 3629 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3630 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3631 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | }; |
| 3633 | unsigned long now = jiffies; |
| 3634 | int status; |
| 3635 | |
| 3636 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3637 | if (status < 0) |
| 3638 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3639 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | return 0; |
| 3641 | } |
| 3642 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3643 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3644 | { |
| 3645 | return (server->caps & NFS_CAP_ACLS) |
| 3646 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3647 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3648 | } |
| 3649 | |
| 3650 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3651 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3652 | * the stack. |
| 3653 | */ |
| 3654 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3655 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3656 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3657 | struct page **pages, unsigned int *pgbase) |
| 3658 | { |
| 3659 | struct page *newpage, **spages; |
| 3660 | int rc = 0; |
| 3661 | size_t len; |
| 3662 | spages = pages; |
| 3663 | |
| 3664 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3665 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3666 | newpage = alloc_page(GFP_KERNEL); |
| 3667 | |
| 3668 | if (newpage == NULL) |
| 3669 | goto unwind; |
| 3670 | memcpy(page_address(newpage), buf, len); |
| 3671 | buf += len; |
| 3672 | buflen -= len; |
| 3673 | *pages++ = newpage; |
| 3674 | rc++; |
| 3675 | } while (buflen != 0); |
| 3676 | |
| 3677 | return rc; |
| 3678 | |
| 3679 | unwind: |
| 3680 | for(; rc > 0; rc--) |
| 3681 | __free_page(spages[rc-1]); |
| 3682 | return -ENOMEM; |
| 3683 | } |
| 3684 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3685 | struct nfs4_cached_acl { |
| 3686 | int cached; |
| 3687 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3688 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3689 | }; |
| 3690 | |
| 3691 | 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] | 3692 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3693 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3694 | |
| 3695 | spin_lock(&inode->i_lock); |
| 3696 | kfree(nfsi->nfs4_acl); |
| 3697 | nfsi->nfs4_acl = acl; |
| 3698 | spin_unlock(&inode->i_lock); |
| 3699 | } |
| 3700 | |
| 3701 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3702 | { |
| 3703 | nfs4_set_cached_acl(inode, NULL); |
| 3704 | } |
| 3705 | |
| 3706 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3707 | { |
| 3708 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3709 | struct nfs4_cached_acl *acl; |
| 3710 | int ret = -ENOENT; |
| 3711 | |
| 3712 | spin_lock(&inode->i_lock); |
| 3713 | acl = nfsi->nfs4_acl; |
| 3714 | if (acl == NULL) |
| 3715 | goto out; |
| 3716 | if (buf == NULL) /* user is just asking for length */ |
| 3717 | goto out_len; |
| 3718 | if (acl->cached == 0) |
| 3719 | goto out; |
| 3720 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3721 | if (acl->len > buflen) |
| 3722 | goto out; |
| 3723 | memcpy(buf, acl->data, acl->len); |
| 3724 | out_len: |
| 3725 | ret = acl->len; |
| 3726 | out: |
| 3727 | spin_unlock(&inode->i_lock); |
| 3728 | return ret; |
| 3729 | } |
| 3730 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3731 | 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] | 3732 | { |
| 3733 | struct nfs4_cached_acl *acl; |
| 3734 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3735 | if (pages && acl_len <= PAGE_SIZE) { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3736 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3737 | if (acl == NULL) |
| 3738 | goto out; |
| 3739 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3740 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3741 | } else { |
| 3742 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3743 | if (acl == NULL) |
| 3744 | goto out; |
| 3745 | acl->cached = 0; |
| 3746 | } |
| 3747 | acl->len = acl_len; |
| 3748 | out: |
| 3749 | nfs4_set_cached_acl(inode, acl); |
| 3750 | } |
| 3751 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3752 | /* |
| 3753 | * The getxattr API returns the required buffer length when called with a |
| 3754 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3755 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3756 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3757 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3758 | * the cache. If not so, we throw away the page, and cache the required |
| 3759 | * length. The next getxattr call will then produce another round trip to |
| 3760 | * the server, this time with the input buf of the required size. |
| 3761 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3762 | 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] | 3763 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3764 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3765 | struct nfs_getaclargs args = { |
| 3766 | .fh = NFS_FH(inode), |
| 3767 | .acl_pages = pages, |
| 3768 | .acl_len = buflen, |
| 3769 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3770 | struct nfs_getaclres res = { |
| 3771 | .acl_len = buflen, |
| 3772 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3773 | struct rpc_message msg = { |
| 3774 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3775 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3776 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3777 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3778 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3779 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3780 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3781 | /* As long as we're doing a round trip to the server anyway, |
| 3782 | * let's be prepared for a page of acl data. */ |
| 3783 | if (npages == 0) |
| 3784 | npages = 1; |
| 3785 | |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3786 | /* Add an extra page to handle the bitmap returned */ |
| 3787 | npages++; |
| 3788 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3789 | for (i = 0; i < npages; i++) { |
| 3790 | pages[i] = alloc_page(GFP_KERNEL); |
| 3791 | if (!pages[i]) |
| 3792 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3793 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3794 | |
| 3795 | /* for decoding across pages */ |
| 3796 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3797 | if (!res.acl_scratch) |
| 3798 | goto out_free; |
| 3799 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3800 | args.acl_len = npages * PAGE_SIZE; |
| 3801 | args.acl_pgbase = 0; |
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 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3804 | * the page we send as a guess */ |
| 3805 | if (buf == NULL) |
| 3806 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3807 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3808 | 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] | 3809 | __func__, buf, buflen, npages, args.acl_len); |
| 3810 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3811 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3812 | if (ret) |
| 3813 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3814 | |
| 3815 | acl_len = res.acl_len - res.acl_data_offset; |
| 3816 | if (acl_len > args.acl_len) |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3817 | nfs4_write_cached_acl(inode, NULL, 0, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3818 | else |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3819 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3820 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3821 | if (buf) { |
| 3822 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3823 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3824 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3825 | _copy_from_pages(buf, pages, res.acl_data_offset, |
Sachin Prabhu | 20e0fa9 | 2012-03-22 16:46:28 +0000 | [diff] [blame] | 3826 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3827 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3828 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3829 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3830 | for (i = 0; i < npages; i++) |
| 3831 | if (pages[i]) |
| 3832 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3833 | if (res.acl_scratch) |
| 3834 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3835 | return ret; |
| 3836 | } |
| 3837 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3838 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3839 | { |
| 3840 | struct nfs4_exception exception = { }; |
| 3841 | ssize_t ret; |
| 3842 | do { |
| 3843 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3844 | if (ret >= 0) |
| 3845 | break; |
| 3846 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3847 | } while (exception.retry); |
| 3848 | return ret; |
| 3849 | } |
| 3850 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3851 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3852 | { |
| 3853 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3854 | int ret; |
| 3855 | |
| 3856 | if (!nfs4_server_supports_acls(server)) |
| 3857 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3858 | ret = nfs_revalidate_inode(server, inode); |
| 3859 | if (ret < 0) |
| 3860 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3861 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3862 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3863 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3864 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3865 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3866 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3867 | return ret; |
| 3868 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3871 | 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] | 3872 | { |
| 3873 | struct nfs_server *server = NFS_SERVER(inode); |
| 3874 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3875 | struct nfs_setaclargs arg = { |
| 3876 | .fh = NFS_FH(inode), |
| 3877 | .acl_pages = pages, |
| 3878 | .acl_len = buflen, |
| 3879 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3880 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3881 | struct rpc_message msg = { |
| 3882 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3883 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3884 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3885 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3886 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3887 | |
| 3888 | if (!nfs4_server_supports_acls(server)) |
| 3889 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3890 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3891 | if (i < 0) |
| 3892 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3893 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3894 | 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] | 3895 | |
| 3896 | /* |
| 3897 | * Free each page after tx, so the only ref left is |
| 3898 | * held by the network stack |
| 3899 | */ |
| 3900 | for (; i > 0; i--) |
| 3901 | put_page(pages[i-1]); |
| 3902 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3903 | /* |
| 3904 | * Acl update can result in inode attribute update. |
| 3905 | * so mark the attribute cache invalid. |
| 3906 | */ |
| 3907 | spin_lock(&inode->i_lock); |
| 3908 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3909 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3910 | nfs_access_zap_cache(inode); |
| 3911 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3912 | return ret; |
| 3913 | } |
| 3914 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3915 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3916 | { |
| 3917 | struct nfs4_exception exception = { }; |
| 3918 | int err; |
| 3919 | do { |
| 3920 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3921 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3922 | &exception); |
| 3923 | } while (exception.retry); |
| 3924 | return err; |
| 3925 | } |
| 3926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3928 | 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] | 3929 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3930 | struct nfs_client *clp = server->nfs_client; |
| 3931 | |
| 3932 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | return 0; |
| 3934 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3935 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3936 | case -NFS4ERR_ADMIN_REVOKED: |
| 3937 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3938 | if (state == NULL) |
| 3939 | break; |
| 3940 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3941 | case -NFS4ERR_OPENMODE: |
| 3942 | if (state == NULL) |
| 3943 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3944 | nfs4_schedule_stateid_recovery(server, state); |
| 3945 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3946 | case -NFS4ERR_EXPIRED: |
| 3947 | if (state != NULL) |
| 3948 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3950 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3951 | nfs4_schedule_lease_recovery(clp); |
| 3952 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3953 | #if defined(CONFIG_NFS_V4_1) |
| 3954 | case -NFS4ERR_BADSESSION: |
| 3955 | case -NFS4ERR_BADSLOT: |
| 3956 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3957 | case -NFS4ERR_DEADSESSION: |
| 3958 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3959 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3960 | case -NFS4ERR_SEQ_MISORDERED: |
| 3961 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3962 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3963 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3964 | task->tk_status = 0; |
| 3965 | return -EAGAIN; |
| 3966 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3968 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3969 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3970 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3972 | task->tk_status = 0; |
| 3973 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3974 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | case -NFS4ERR_OLD_STATEID: |
| 3976 | task->tk_status = 0; |
| 3977 | return -EAGAIN; |
| 3978 | } |
| 3979 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3980 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3981 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3982 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3983 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3984 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3985 | task->tk_status = 0; |
| 3986 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3989 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 3990 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3991 | { |
| 3992 | __be32 verf[2]; |
| 3993 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 3994 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 3995 | /* An impossible timestamp guarantees this value |
| 3996 | * will never match a generated boot time. */ |
| 3997 | verf[0] = 0; |
| 3998 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 3999 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4000 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4001 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4002 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4003 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4004 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4005 | } |
| 4006 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4007 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4008 | unsigned short port, struct rpc_cred *cred, |
| 4009 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | { |
| 4011 | nfs4_verifier sc_verifier; |
| 4012 | struct nfs4_setclientid setclientid = { |
| 4013 | .sc_verifier = &sc_verifier, |
| 4014 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4015 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | }; |
| 4017 | struct rpc_message msg = { |
| 4018 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4019 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4020 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4021 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | int loop = 0; |
| 4024 | int status; |
| 4025 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4026 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | |
| 4028 | for(;;) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 4029 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 4031 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4032 | clp->cl_ipaddr, |
| 4033 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4034 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 4035 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4036 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 4037 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | clp->cl_id_uniquifier); |
| 4039 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4040 | sizeof(setclientid.sc_netid), |
| 4041 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4042 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4044 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | clp->cl_ipaddr, port >> 8, port & 255); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 4046 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4048 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | if (status != -NFS4ERR_CLID_INUSE) |
| 4050 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4051 | if (loop != 0) { |
| 4052 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4054 | } |
| 4055 | ++loop; |
| 4056 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | } |
| 4058 | return status; |
| 4059 | } |
| 4060 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4061 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4062 | struct nfs4_setclientid_res *arg, |
| 4063 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | { |
| 4065 | struct nfs_fsinfo fsinfo; |
| 4066 | struct rpc_message msg = { |
| 4067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4068 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4070 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | }; |
| 4072 | unsigned long now; |
| 4073 | int status; |
| 4074 | |
| 4075 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4076 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | if (status == 0) { |
| 4078 | spin_lock(&clp->cl_lock); |
| 4079 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4080 | clp->cl_last_renewal = now; |
| 4081 | spin_unlock(&clp->cl_lock); |
| 4082 | } |
| 4083 | return status; |
| 4084 | } |
| 4085 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4086 | struct nfs4_delegreturndata { |
| 4087 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4088 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4089 | struct nfs_fh fh; |
| 4090 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4091 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4092 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4093 | int rpc_status; |
| 4094 | }; |
| 4095 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4096 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4097 | { |
| 4098 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4099 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4100 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4101 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4102 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4103 | switch (task->tk_status) { |
| 4104 | case -NFS4ERR_STALE_STATEID: |
| 4105 | case -NFS4ERR_EXPIRED: |
| 4106 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4107 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4108 | break; |
| 4109 | default: |
| 4110 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4111 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4112 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4113 | return; |
| 4114 | } |
| 4115 | } |
| 4116 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | static void nfs4_delegreturn_release(void *calldata) |
| 4120 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4121 | kfree(calldata); |
| 4122 | } |
| 4123 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4124 | #if defined(CONFIG_NFS_V4_1) |
| 4125 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4126 | { |
| 4127 | struct nfs4_delegreturndata *d_data; |
| 4128 | |
| 4129 | d_data = (struct nfs4_delegreturndata *)data; |
| 4130 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4131 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4132 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4133 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4134 | return; |
| 4135 | rpc_call_start(task); |
| 4136 | } |
| 4137 | #endif /* CONFIG_NFS_V4_1 */ |
| 4138 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4139 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4140 | #if defined(CONFIG_NFS_V4_1) |
| 4141 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4142 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4143 | .rpc_call_done = nfs4_delegreturn_done, |
| 4144 | .rpc_release = nfs4_delegreturn_release, |
| 4145 | }; |
| 4146 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4147 | 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] | 4148 | { |
| 4149 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4150 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4151 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4152 | struct rpc_message msg = { |
| 4153 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4154 | .rpc_cred = cred, |
| 4155 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4156 | struct rpc_task_setup task_setup_data = { |
| 4157 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4158 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4159 | .callback_ops = &nfs4_delegreturn_ops, |
| 4160 | .flags = RPC_TASK_ASYNC, |
| 4161 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4162 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4163 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4164 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4165 | if (data == NULL) |
| 4166 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4167 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4168 | data->args.fhandle = &data->fh; |
| 4169 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4170 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4171 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4172 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4173 | data->res.fattr = &data->fattr; |
| 4174 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4175 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4176 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4177 | data->rpc_status = 0; |
| 4178 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4179 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4180 | msg.rpc_argp = &data->args; |
| 4181 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4182 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4183 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4184 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4185 | if (!issync) |
| 4186 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4187 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4188 | if (status != 0) |
| 4189 | goto out; |
| 4190 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4191 | if (status == 0) |
| 4192 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4193 | else |
| 4194 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4195 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4196 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4197 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4200 | 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] | 4201 | { |
| 4202 | struct nfs_server *server = NFS_SERVER(inode); |
| 4203 | struct nfs4_exception exception = { }; |
| 4204 | int err; |
| 4205 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4206 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | switch (err) { |
| 4208 | case -NFS4ERR_STALE_STATEID: |
| 4209 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | case 0: |
| 4211 | return 0; |
| 4212 | } |
| 4213 | err = nfs4_handle_exception(server, err, &exception); |
| 4214 | } while (exception.retry); |
| 4215 | return err; |
| 4216 | } |
| 4217 | |
| 4218 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4219 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4220 | |
| 4221 | /* |
| 4222 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4223 | */ |
| 4224 | static unsigned long |
| 4225 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4226 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4227 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | timeout <<= 1; |
| 4229 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4230 | return NFS4_LOCK_MAXTIMEOUT; |
| 4231 | return timeout; |
| 4232 | } |
| 4233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4235 | { |
| 4236 | struct inode *inode = state->inode; |
| 4237 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4238 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4239 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4241 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4243 | struct nfs_lockt_res res = { |
| 4244 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | }; |
| 4246 | struct rpc_message msg = { |
| 4247 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4248 | .rpc_argp = &arg, |
| 4249 | .rpc_resp = &res, |
| 4250 | .rpc_cred = state->owner->so_cred, |
| 4251 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | struct nfs4_lock_state *lsp; |
| 4253 | int status; |
| 4254 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4255 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4256 | status = nfs4_set_lock_state(state, request); |
| 4257 | if (status != 0) |
| 4258 | goto out; |
| 4259 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4260 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4261 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4262 | 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] | 4263 | switch (status) { |
| 4264 | case 0: |
| 4265 | request->fl_type = F_UNLCK; |
| 4266 | break; |
| 4267 | case -NFS4ERR_DENIED: |
| 4268 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4270 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4271 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | return status; |
| 4273 | } |
| 4274 | |
| 4275 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4276 | { |
| 4277 | struct nfs4_exception exception = { }; |
| 4278 | int err; |
| 4279 | |
| 4280 | do { |
| 4281 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4282 | _nfs4_proc_getlk(state, cmd, request), |
| 4283 | &exception); |
| 4284 | } while (exception.retry); |
| 4285 | return err; |
| 4286 | } |
| 4287 | |
| 4288 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4289 | { |
| 4290 | int res = 0; |
| 4291 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4292 | case FL_POSIX: |
| 4293 | res = posix_lock_file_wait(file, fl); |
| 4294 | break; |
| 4295 | case FL_FLOCK: |
| 4296 | res = flock_lock_file_wait(file, fl); |
| 4297 | break; |
| 4298 | default: |
| 4299 | BUG(); |
| 4300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | return res; |
| 4302 | } |
| 4303 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4304 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4305 | struct nfs_locku_args arg; |
| 4306 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4307 | struct nfs4_lock_state *lsp; |
| 4308 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4309 | struct file_lock fl; |
| 4310 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4311 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4312 | }; |
| 4313 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4314 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4315 | struct nfs_open_context *ctx, |
| 4316 | struct nfs4_lock_state *lsp, |
| 4317 | struct nfs_seqid *seqid) |
| 4318 | { |
| 4319 | struct nfs4_unlockdata *p; |
| 4320 | struct inode *inode = lsp->ls_state->inode; |
| 4321 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4322 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4323 | if (p == NULL) |
| 4324 | return NULL; |
| 4325 | p->arg.fh = NFS_FH(inode); |
| 4326 | p->arg.fl = &p->fl; |
| 4327 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4328 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4329 | p->arg.stateid = &lsp->ls_stateid; |
| 4330 | p->lsp = lsp; |
| 4331 | atomic_inc(&lsp->ls_count); |
| 4332 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4333 | p->ctx = get_nfs_open_context(ctx); |
| 4334 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4335 | p->server = NFS_SERVER(inode); |
| 4336 | return p; |
| 4337 | } |
| 4338 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4339 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4340 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4341 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4342 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4343 | nfs4_put_lock_state(calldata->lsp); |
| 4344 | put_nfs_open_context(calldata->ctx); |
| 4345 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4348 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4349 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4350 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4351 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4352 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4353 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4354 | switch (task->tk_status) { |
| 4355 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4356 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4357 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4358 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4359 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4360 | case -NFS4ERR_BAD_STATEID: |
| 4361 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4362 | case -NFS4ERR_STALE_STATEID: |
| 4363 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4364 | break; |
| 4365 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4366 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4367 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4368 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4371 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4372 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4373 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4375 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4376 | return; |
| 4377 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4378 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4379 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4380 | return; |
| 4381 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4382 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4383 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4384 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4385 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4386 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4387 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4390 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4391 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4392 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4393 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4394 | }; |
| 4395 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4396 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4397 | struct nfs_open_context *ctx, |
| 4398 | struct nfs4_lock_state *lsp, |
| 4399 | struct nfs_seqid *seqid) |
| 4400 | { |
| 4401 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4402 | struct rpc_message msg = { |
| 4403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4404 | .rpc_cred = ctx->cred, |
| 4405 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4406 | struct rpc_task_setup task_setup_data = { |
| 4407 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4408 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4409 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4410 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4411 | .flags = RPC_TASK_ASYNC, |
| 4412 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4413 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4414 | /* Ensure this is an unlock - when canceling a lock, the |
| 4415 | * canceled lock is passed in, and it won't be an unlock. |
| 4416 | */ |
| 4417 | fl->fl_type = F_UNLCK; |
| 4418 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4419 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4420 | if (data == NULL) { |
| 4421 | nfs_free_seqid(seqid); |
| 4422 | return ERR_PTR(-ENOMEM); |
| 4423 | } |
| 4424 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4425 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4426 | msg.rpc_argp = &data->arg; |
| 4427 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4428 | task_setup_data.callback_data = data; |
| 4429 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4430 | } |
| 4431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4433 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4434 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4435 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4436 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4437 | struct rpc_task *task; |
| 4438 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4439 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4441 | status = nfs4_set_lock_state(state, request); |
| 4442 | /* Unlock _before_ we do the RPC call */ |
| 4443 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4444 | down_read(&nfsi->rwsem); |
| 4445 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4446 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4447 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4448 | } |
| 4449 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4450 | if (status != 0) |
| 4451 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4452 | /* Is this a delegated lock? */ |
| 4453 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4454 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4455 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4456 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4457 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4458 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4459 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4460 | 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] | 4461 | status = PTR_ERR(task); |
| 4462 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4463 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4464 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4465 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4466 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4467 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4468 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | } |
| 4470 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4471 | struct nfs4_lockdata { |
| 4472 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4473 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4474 | struct nfs4_lock_state *lsp; |
| 4475 | struct nfs_open_context *ctx; |
| 4476 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4477 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4478 | int rpc_status; |
| 4479 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4480 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4481 | }; |
| 4482 | |
| 4483 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4484 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4485 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4486 | { |
| 4487 | struct nfs4_lockdata *p; |
| 4488 | struct inode *inode = lsp->ls_state->inode; |
| 4489 | struct nfs_server *server = NFS_SERVER(inode); |
| 4490 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4491 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4492 | if (p == NULL) |
| 4493 | return NULL; |
| 4494 | |
| 4495 | p->arg.fh = NFS_FH(inode); |
| 4496 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4497 | 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] | 4498 | if (p->arg.open_seqid == NULL) |
| 4499 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4500 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4501 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4502 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4503 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4504 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4505 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4506 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4507 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4508 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4509 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4510 | atomic_inc(&lsp->ls_count); |
| 4511 | p->ctx = get_nfs_open_context(ctx); |
| 4512 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4513 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4514 | out_free_seqid: |
| 4515 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4516 | out_free: |
| 4517 | kfree(p); |
| 4518 | return NULL; |
| 4519 | } |
| 4520 | |
| 4521 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4522 | { |
| 4523 | struct nfs4_lockdata *data = calldata; |
| 4524 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4526 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4527 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4528 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4529 | /* Do we need to do an open_to_lock_owner? */ |
| 4530 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4531 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4532 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4533 | data->arg.open_stateid = &state->stateid; |
| 4534 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4535 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4536 | } else |
| 4537 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4538 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4539 | if (nfs4_setup_sequence(data->server, |
| 4540 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4541 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4542 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4543 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4544 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4545 | } |
| 4546 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4547 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4548 | { |
| 4549 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4550 | nfs4_lock_prepare(task, calldata); |
| 4551 | } |
| 4552 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4553 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4554 | { |
| 4555 | struct nfs4_lockdata *data = calldata; |
| 4556 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4557 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4558 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4559 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4560 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4561 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4562 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4563 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4564 | if (data->rpc_status == 0) |
| 4565 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4566 | else |
| 4567 | goto out; |
| 4568 | } |
| 4569 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4570 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4571 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4572 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4573 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4574 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4575 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | static void nfs4_lock_release(void *calldata) |
| 4579 | { |
| 4580 | struct nfs4_lockdata *data = calldata; |
| 4581 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4582 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4583 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4584 | if (data->cancelled != 0) { |
| 4585 | struct rpc_task *task; |
| 4586 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4587 | data->arg.lock_seqid); |
| 4588 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4589 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4590 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4591 | } else |
| 4592 | nfs_free_seqid(data->arg.lock_seqid); |
| 4593 | nfs4_put_lock_state(data->lsp); |
| 4594 | put_nfs_open_context(data->ctx); |
| 4595 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4596 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4600 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4601 | .rpc_call_done = nfs4_lock_done, |
| 4602 | .rpc_release = nfs4_lock_release, |
| 4603 | }; |
| 4604 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4605 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4606 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4607 | .rpc_call_done = nfs4_lock_done, |
| 4608 | .rpc_release = nfs4_lock_release, |
| 4609 | }; |
| 4610 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4611 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4612 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4613 | switch (error) { |
| 4614 | case -NFS4ERR_ADMIN_REVOKED: |
| 4615 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4616 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4617 | if (new_lock_owner != 0 || |
| 4618 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4619 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4620 | break; |
| 4621 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4622 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4623 | case -NFS4ERR_EXPIRED: |
| 4624 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4625 | }; |
| 4626 | } |
| 4627 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4628 | 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] | 4629 | { |
| 4630 | struct nfs4_lockdata *data; |
| 4631 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4632 | struct rpc_message msg = { |
| 4633 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4634 | .rpc_cred = state->owner->so_cred, |
| 4635 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4636 | struct rpc_task_setup task_setup_data = { |
| 4637 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4638 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4639 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4640 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4641 | .flags = RPC_TASK_ASYNC, |
| 4642 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4643 | int ret; |
| 4644 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4645 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4646 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4647 | fl->fl_u.nfs4_fl.owner, |
| 4648 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4649 | if (data == NULL) |
| 4650 | return -ENOMEM; |
| 4651 | if (IS_SETLKW(cmd)) |
| 4652 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4653 | if (recovery_type > NFS_LOCK_NEW) { |
| 4654 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4655 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4656 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4657 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4658 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4659 | msg.rpc_argp = &data->arg; |
| 4660 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4661 | task_setup_data.callback_data = data; |
| 4662 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4663 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4664 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4665 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4666 | if (ret == 0) { |
| 4667 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4668 | if (ret) |
| 4669 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4670 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4671 | } else |
| 4672 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4673 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4674 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4675 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | } |
| 4677 | |
| 4678 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4679 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4680 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4681 | struct nfs4_exception exception = { |
| 4682 | .inode = state->inode, |
| 4683 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4684 | int err; |
| 4685 | |
| 4686 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4687 | /* Cache the lock if possible... */ |
| 4688 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4689 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4690 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4691 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4692 | break; |
| 4693 | nfs4_handle_exception(server, err, &exception); |
| 4694 | } while (exception.retry); |
| 4695 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4699 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4700 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4701 | struct nfs4_exception exception = { |
| 4702 | .inode = state->inode, |
| 4703 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4704 | int err; |
| 4705 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4706 | err = nfs4_set_lock_state(state, request); |
| 4707 | if (err != 0) |
| 4708 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4709 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4710 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4711 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4712 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4713 | switch (err) { |
| 4714 | default: |
| 4715 | goto out; |
| 4716 | case -NFS4ERR_GRACE: |
| 4717 | case -NFS4ERR_DELAY: |
| 4718 | nfs4_handle_exception(server, err, &exception); |
| 4719 | err = 0; |
| 4720 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4721 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4722 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4723 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | } |
| 4725 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4726 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame^] | 4727 | /** |
| 4728 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4729 | * |
| 4730 | * @state: NFSv4 state for an inode |
| 4731 | * |
| 4732 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4733 | * Otherwise a negative NFS4ERR value is returned. |
| 4734 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4735 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4736 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4737 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4738 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4739 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4740 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4741 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4742 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4743 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4744 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame^] | 4745 | /* Free the stateid unless the server |
| 4746 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4747 | if (status != -NFS4ERR_BAD_STATEID) |
| 4748 | nfs41_free_stateid(server, |
| 4749 | &lsp->ls_stateid); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4750 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4751 | ret = status; |
| 4752 | } |
| 4753 | } |
| 4754 | }; |
| 4755 | |
| 4756 | return ret; |
| 4757 | } |
| 4758 | |
| 4759 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4760 | { |
| 4761 | int status = NFS_OK; |
| 4762 | |
| 4763 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4764 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4765 | if (status != NFS_OK) |
| 4766 | status = nfs4_lock_expired(state, request); |
| 4767 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4768 | } |
| 4769 | #endif |
| 4770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4772 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4773 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4774 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4775 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4777 | if ((fl_flags & FL_POSIX) && |
| 4778 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4779 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4780 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4781 | status = nfs4_set_lock_state(state, request); |
| 4782 | if (status != 0) |
| 4783 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4784 | request->fl_flags |= FL_ACCESS; |
| 4785 | status = do_vfs_lock(request->fl_file, request); |
| 4786 | if (status < 0) |
| 4787 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4788 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4789 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4790 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4791 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4792 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4793 | status = do_vfs_lock(request->fl_file, request); |
| 4794 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4795 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4796 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4797 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4798 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4799 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4800 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4801 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4802 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4803 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4804 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4805 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4806 | out: |
| 4807 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | return status; |
| 4809 | } |
| 4810 | |
| 4811 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4812 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4813 | struct nfs4_exception exception = { |
| 4814 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4815 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4816 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | int err; |
| 4818 | |
| 4819 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4820 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4821 | if (err == -NFS4ERR_DENIED) |
| 4822 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4824 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | } while (exception.retry); |
| 4826 | return err; |
| 4827 | } |
| 4828 | |
| 4829 | static int |
| 4830 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4831 | { |
| 4832 | struct nfs_open_context *ctx; |
| 4833 | struct nfs4_state *state; |
| 4834 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4835 | int status; |
| 4836 | |
| 4837 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4838 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | state = ctx->state; |
| 4840 | |
| 4841 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4842 | return -EINVAL; |
| 4843 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4844 | if (IS_GETLK(cmd)) { |
| 4845 | if (state != NULL) |
| 4846 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4847 | return 0; |
| 4848 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | |
| 4850 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4851 | return -EINVAL; |
| 4852 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4853 | if (request->fl_type == F_UNLCK) { |
| 4854 | if (state != NULL) |
| 4855 | return nfs4_proc_unlck(state, cmd, request); |
| 4856 | return 0; |
| 4857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4859 | if (state == NULL) |
| 4860 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4861 | /* |
| 4862 | * Don't rely on the VFS having checked the file open mode, |
| 4863 | * since it won't do this for flock() locks. |
| 4864 | */ |
| 4865 | switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) { |
| 4866 | case F_RDLCK: |
| 4867 | if (!(filp->f_mode & FMODE_READ)) |
| 4868 | return -EBADF; |
| 4869 | break; |
| 4870 | case F_WRLCK: |
| 4871 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4872 | return -EBADF; |
| 4873 | } |
| 4874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | do { |
| 4876 | status = nfs4_proc_setlk(state, cmd, request); |
| 4877 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4878 | break; |
| 4879 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4880 | status = -ERESTARTSYS; |
| 4881 | if (signalled()) |
| 4882 | break; |
| 4883 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | return status; |
| 4885 | } |
| 4886 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4887 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4888 | { |
| 4889 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4890 | struct nfs4_exception exception = { }; |
| 4891 | int err; |
| 4892 | |
| 4893 | err = nfs4_set_lock_state(state, fl); |
| 4894 | if (err != 0) |
| 4895 | goto out; |
| 4896 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4897 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4898 | switch (err) { |
| 4899 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4900 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4901 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4902 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4903 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4904 | goto out; |
| 4905 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4906 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4907 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4908 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4909 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4910 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4911 | case -NFS4ERR_BADSESSION: |
| 4912 | case -NFS4ERR_BADSLOT: |
| 4913 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4914 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4915 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4916 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4917 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4918 | case -ERESTARTSYS: |
| 4919 | /* |
| 4920 | * The show must go on: exit, but mark the |
| 4921 | * stateid as needing recovery. |
| 4922 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4923 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4924 | case -NFS4ERR_ADMIN_REVOKED: |
| 4925 | case -NFS4ERR_BAD_STATEID: |
| 4926 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4927 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4928 | err = 0; |
| 4929 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4930 | case -EKEYEXPIRED: |
| 4931 | /* |
| 4932 | * User RPCSEC_GSS context has expired. |
| 4933 | * We cannot recover this stateid now, so |
| 4934 | * skip it and allow recovery thread to |
| 4935 | * proceed. |
| 4936 | */ |
| 4937 | err = 0; |
| 4938 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4939 | case -ENOMEM: |
| 4940 | case -NFS4ERR_DENIED: |
| 4941 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4942 | err = 0; |
| 4943 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4944 | case -NFS4ERR_DELAY: |
| 4945 | break; |
| 4946 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4947 | err = nfs4_handle_exception(server, err, &exception); |
| 4948 | } while (exception.retry); |
| 4949 | out: |
| 4950 | return err; |
| 4951 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4952 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4953 | struct nfs_release_lockowner_data { |
| 4954 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4955 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4956 | struct nfs_release_lockowner_args args; |
| 4957 | }; |
| 4958 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4959 | static void nfs4_release_lockowner_release(void *calldata) |
| 4960 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4961 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4962 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4963 | kfree(calldata); |
| 4964 | } |
| 4965 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4966 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4967 | .rpc_release = nfs4_release_lockowner_release, |
| 4968 | }; |
| 4969 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4970 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4971 | { |
| 4972 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4973 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4974 | struct rpc_message msg = { |
| 4975 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4976 | }; |
| 4977 | |
| 4978 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4979 | return -EINVAL; |
| 4980 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 4981 | if (!data) |
| 4982 | return -ENOMEM; |
| 4983 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4984 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4985 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4986 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 4987 | data->args.lock_owner.s_dev = server->s_dev; |
| 4988 | msg.rpc_argp = &data->args; |
| 4989 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 4990 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4991 | } |
| 4992 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4993 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4994 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4995 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4996 | const void *buf, size_t buflen, |
| 4997 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4998 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4999 | if (strcmp(key, "") != 0) |
| 5000 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5001 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5002 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5005 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5006 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5007 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5008 | if (strcmp(key, "") != 0) |
| 5009 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5010 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5011 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5014 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5015 | size_t list_len, const char *name, |
| 5016 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5017 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5018 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5019 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5020 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5021 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5022 | |
| 5023 | if (list && len <= list_len) |
| 5024 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5025 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5028 | /* |
| 5029 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5030 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5031 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5032 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5033 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5034 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5035 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5036 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5037 | return; |
| 5038 | |
| 5039 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5040 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5041 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5042 | fattr->nlink = 2; |
| 5043 | } |
| 5044 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5045 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5046 | const struct qstr *name, |
| 5047 | struct nfs4_fs_locations *fs_locations, |
| 5048 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5049 | { |
| 5050 | struct nfs_server *server = NFS_SERVER(dir); |
| 5051 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5052 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5053 | }; |
| 5054 | struct nfs4_fs_locations_arg args = { |
| 5055 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5056 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5057 | .page = page, |
| 5058 | .bitmask = bitmask, |
| 5059 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5060 | struct nfs4_fs_locations_res res = { |
| 5061 | .fs_locations = fs_locations, |
| 5062 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5063 | struct rpc_message msg = { |
| 5064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5065 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5066 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5067 | }; |
| 5068 | int status; |
| 5069 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5070 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5071 | |
| 5072 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5073 | * is not supported */ |
| 5074 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5075 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5076 | else |
| 5077 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5078 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5079 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5080 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5081 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5082 | 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] | 5083 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5084 | return status; |
| 5085 | } |
| 5086 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5087 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5088 | const struct qstr *name, |
| 5089 | struct nfs4_fs_locations *fs_locations, |
| 5090 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5091 | { |
| 5092 | struct nfs4_exception exception = { }; |
| 5093 | int err; |
| 5094 | do { |
| 5095 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5096 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5097 | &exception); |
| 5098 | } while (exception.retry); |
| 5099 | return err; |
| 5100 | } |
| 5101 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5102 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5103 | { |
| 5104 | int status; |
| 5105 | struct nfs4_secinfo_arg args = { |
| 5106 | .dir_fh = NFS_FH(dir), |
| 5107 | .name = name, |
| 5108 | }; |
| 5109 | struct nfs4_secinfo_res res = { |
| 5110 | .flavors = flavors, |
| 5111 | }; |
| 5112 | struct rpc_message msg = { |
| 5113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5114 | .rpc_argp = &args, |
| 5115 | .rpc_resp = &res, |
| 5116 | }; |
| 5117 | |
| 5118 | dprintk("NFS call secinfo %s\n", name->name); |
| 5119 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5120 | dprintk("NFS reply secinfo: %d\n", status); |
| 5121 | return status; |
| 5122 | } |
| 5123 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5124 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5125 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5126 | { |
| 5127 | struct nfs4_exception exception = { }; |
| 5128 | int err; |
| 5129 | do { |
| 5130 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5131 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5132 | &exception); |
| 5133 | } while (exception.retry); |
| 5134 | return err; |
| 5135 | } |
| 5136 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5137 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5138 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5139 | * Check the exchange flags returned by the server for invalid flags, having |
| 5140 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5141 | * DS flags set. |
| 5142 | */ |
| 5143 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5144 | { |
| 5145 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5146 | goto out_inval; |
| 5147 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5148 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5149 | goto out_inval; |
| 5150 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5151 | goto out_inval; |
| 5152 | return NFS_OK; |
| 5153 | out_inval: |
| 5154 | return -NFS4ERR_INVAL; |
| 5155 | } |
| 5156 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5157 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5158 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5159 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5160 | { |
| 5161 | if (a->server_scope_sz == b->server_scope_sz && |
| 5162 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5163 | return true; |
| 5164 | |
| 5165 | return false; |
| 5166 | } |
| 5167 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5168 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5169 | * nfs4_proc_bind_conn_to_session() |
| 5170 | * |
| 5171 | * The 4.1 client currently uses the same TCP connection for the |
| 5172 | * fore and backchannel. |
| 5173 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5174 | 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] | 5175 | { |
| 5176 | int status; |
| 5177 | struct nfs41_bind_conn_to_session_res res; |
| 5178 | struct rpc_message msg = { |
| 5179 | .rpc_proc = |
| 5180 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5181 | .rpc_argp = clp, |
| 5182 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5183 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5184 | }; |
| 5185 | |
| 5186 | dprintk("--> %s\n", __func__); |
| 5187 | BUG_ON(clp == NULL); |
| 5188 | |
| 5189 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5190 | if (unlikely(res.session == NULL)) { |
| 5191 | status = -ENOMEM; |
| 5192 | goto out; |
| 5193 | } |
| 5194 | |
| 5195 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5196 | if (status == 0) { |
| 5197 | if (memcmp(res.session->sess_id.data, |
| 5198 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5199 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5200 | status = -EIO; |
| 5201 | goto out_session; |
| 5202 | } |
| 5203 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5204 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5205 | __func__); |
| 5206 | status = -EIO; |
| 5207 | goto out_session; |
| 5208 | } |
| 5209 | if (res.use_conn_in_rdma_mode) { |
| 5210 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5211 | __func__); |
| 5212 | status = -EIO; |
| 5213 | goto out_session; |
| 5214 | } |
| 5215 | } |
| 5216 | out_session: |
| 5217 | kfree(res.session); |
| 5218 | out: |
| 5219 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5220 | return status; |
| 5221 | } |
| 5222 | |
| 5223 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5224 | * nfs4_proc_exchange_id() |
| 5225 | * |
| 5226 | * Since the clientid has expired, all compounds using sessions |
| 5227 | * associated with the stale clientid will be returning |
| 5228 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5229 | * be in some phase of session reset. |
| 5230 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5231 | 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] | 5232 | { |
| 5233 | nfs4_verifier verifier; |
| 5234 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5235 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5236 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5237 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5238 | }; |
| 5239 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5240 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5241 | }; |
| 5242 | int status; |
| 5243 | struct rpc_message msg = { |
| 5244 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5245 | .rpc_argp = &args, |
| 5246 | .rpc_resp = &res, |
| 5247 | .rpc_cred = cred, |
| 5248 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5249 | |
| 5250 | dprintk("--> %s\n", __func__); |
| 5251 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5252 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5253 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5254 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5255 | args.id_len = scnprintf(args.id, sizeof(args.id), |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5256 | "%s/%s/%u", |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5257 | clp->cl_ipaddr, |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5258 | clp->cl_rpcclient->cl_nodename, |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5259 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5260 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5261 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5262 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5263 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5264 | status = -ENOMEM; |
| 5265 | goto out; |
| 5266 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5267 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5268 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5269 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5270 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5271 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5272 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5273 | } |
| 5274 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5275 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5276 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5277 | status = -ENOMEM; |
| 5278 | goto out_server_scope; |
| 5279 | } |
| 5280 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5281 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5282 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5283 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5284 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5285 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5286 | clp->cl_clientid = res.clientid; |
| 5287 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5288 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5289 | clp->cl_seqid = res.seqid; |
| 5290 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5291 | kfree(clp->cl_serverowner); |
| 5292 | clp->cl_serverowner = res.server_owner; |
| 5293 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5294 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5295 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5296 | kfree(clp->cl_implid); |
| 5297 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5298 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5299 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5300 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5301 | res.server_scope)) { |
| 5302 | dprintk("%s: server_scope mismatch detected\n", |
| 5303 | __func__); |
| 5304 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5305 | kfree(clp->cl_serverscope); |
| 5306 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5307 | } |
| 5308 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5309 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5310 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5311 | goto out; |
| 5312 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5313 | } else |
| 5314 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5315 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5316 | out_server_owner: |
| 5317 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5318 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5319 | kfree(res.server_scope); |
| 5320 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5321 | if (clp->cl_implid != NULL) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5322 | dprintk("%s: Server Implementation ID: " |
| 5323 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5324 | __func__, clp->cl_implid->domain, clp->cl_implid->name, |
| 5325 | clp->cl_implid->date.seconds, |
| 5326 | clp->cl_implid->date.nseconds); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5327 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5328 | return status; |
| 5329 | } |
| 5330 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5331 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5332 | struct rpc_cred *cred) |
| 5333 | { |
| 5334 | struct rpc_message msg = { |
| 5335 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5336 | .rpc_argp = clp, |
| 5337 | .rpc_cred = cred, |
| 5338 | }; |
| 5339 | int status; |
| 5340 | |
| 5341 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5342 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5343 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5344 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5345 | return status; |
| 5346 | } |
| 5347 | |
| 5348 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5349 | struct rpc_cred *cred) |
| 5350 | { |
| 5351 | unsigned int loop; |
| 5352 | int ret; |
| 5353 | |
| 5354 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5355 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5356 | switch (ret) { |
| 5357 | case -NFS4ERR_DELAY: |
| 5358 | case -NFS4ERR_CLIENTID_BUSY: |
| 5359 | ssleep(1); |
| 5360 | break; |
| 5361 | default: |
| 5362 | return ret; |
| 5363 | } |
| 5364 | } |
| 5365 | return 0; |
| 5366 | } |
| 5367 | |
| 5368 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5369 | { |
| 5370 | struct rpc_cred *cred; |
| 5371 | int ret = 0; |
| 5372 | |
| 5373 | if (clp->cl_mvops->minor_version < 1) |
| 5374 | goto out; |
| 5375 | if (clp->cl_exchange_flags == 0) |
| 5376 | goto out; |
| 5377 | cred = nfs4_get_exchange_id_cred(clp); |
| 5378 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5379 | if (cred) |
| 5380 | put_rpccred(cred); |
| 5381 | switch (ret) { |
| 5382 | case 0: |
| 5383 | case -NFS4ERR_STALE_CLIENTID: |
| 5384 | clp->cl_exchange_flags = 0; |
| 5385 | } |
| 5386 | out: |
| 5387 | return ret; |
| 5388 | } |
| 5389 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5390 | struct nfs4_get_lease_time_data { |
| 5391 | struct nfs4_get_lease_time_args *args; |
| 5392 | struct nfs4_get_lease_time_res *res; |
| 5393 | struct nfs_client *clp; |
| 5394 | }; |
| 5395 | |
| 5396 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5397 | void *calldata) |
| 5398 | { |
| 5399 | int ret; |
| 5400 | struct nfs4_get_lease_time_data *data = |
| 5401 | (struct nfs4_get_lease_time_data *)calldata; |
| 5402 | |
| 5403 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5404 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5405 | /* just setup sequence, do not trigger session recovery |
| 5406 | since we're invoked within one */ |
| 5407 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5408 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5409 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5410 | |
| 5411 | BUG_ON(ret == -EAGAIN); |
| 5412 | rpc_call_start(task); |
| 5413 | dprintk("<-- %s\n", __func__); |
| 5414 | } |
| 5415 | |
| 5416 | /* |
| 5417 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5418 | * from sequence operation or clientid errors. |
| 5419 | */ |
| 5420 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5421 | { |
| 5422 | struct nfs4_get_lease_time_data *data = |
| 5423 | (struct nfs4_get_lease_time_data *)calldata; |
| 5424 | |
| 5425 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5426 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5427 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5428 | switch (task->tk_status) { |
| 5429 | case -NFS4ERR_DELAY: |
| 5430 | case -NFS4ERR_GRACE: |
| 5431 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5432 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5433 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5434 | /* fall through */ |
| 5435 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5436 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5437 | return; |
| 5438 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5439 | dprintk("<-- %s\n", __func__); |
| 5440 | } |
| 5441 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5442 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5443 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5444 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5445 | }; |
| 5446 | |
| 5447 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5448 | { |
| 5449 | struct rpc_task *task; |
| 5450 | struct nfs4_get_lease_time_args args; |
| 5451 | struct nfs4_get_lease_time_res res = { |
| 5452 | .lr_fsinfo = fsinfo, |
| 5453 | }; |
| 5454 | struct nfs4_get_lease_time_data data = { |
| 5455 | .args = &args, |
| 5456 | .res = &res, |
| 5457 | .clp = clp, |
| 5458 | }; |
| 5459 | struct rpc_message msg = { |
| 5460 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5461 | .rpc_argp = &args, |
| 5462 | .rpc_resp = &res, |
| 5463 | }; |
| 5464 | struct rpc_task_setup task_setup = { |
| 5465 | .rpc_client = clp->cl_rpcclient, |
| 5466 | .rpc_message = &msg, |
| 5467 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5468 | .callback_data = &data, |
| 5469 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5470 | }; |
| 5471 | int status; |
| 5472 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5473 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5474 | dprintk("--> %s\n", __func__); |
| 5475 | task = rpc_run_task(&task_setup); |
| 5476 | |
| 5477 | if (IS_ERR(task)) |
| 5478 | status = PTR_ERR(task); |
| 5479 | else { |
| 5480 | status = task->tk_status; |
| 5481 | rpc_put_task(task); |
| 5482 | } |
| 5483 | dprintk("<-- %s return %d\n", __func__, status); |
| 5484 | |
| 5485 | return status; |
| 5486 | } |
| 5487 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5488 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5489 | { |
| 5490 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5491 | } |
| 5492 | |
| 5493 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5494 | struct nfs4_slot *new, |
| 5495 | u32 max_slots, |
| 5496 | u32 ivalue) |
| 5497 | { |
| 5498 | struct nfs4_slot *old = NULL; |
| 5499 | u32 i; |
| 5500 | |
| 5501 | spin_lock(&tbl->slot_tbl_lock); |
| 5502 | if (new) { |
| 5503 | old = tbl->slots; |
| 5504 | tbl->slots = new; |
| 5505 | tbl->max_slots = max_slots; |
| 5506 | } |
| 5507 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5508 | for (i = 0; i < tbl->max_slots; i++) |
| 5509 | tbl->slots[i].seq_nr = ivalue; |
| 5510 | spin_unlock(&tbl->slot_tbl_lock); |
| 5511 | kfree(old); |
| 5512 | } |
| 5513 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5514 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5515 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5516 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5517 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5518 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5519 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5520 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5521 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5522 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5523 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5524 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5525 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5526 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5527 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5528 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5529 | if (!new) |
| 5530 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5531 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5532 | ret = 0; |
| 5533 | |
| 5534 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5535 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5536 | tbl, tbl->slots, tbl->max_slots); |
| 5537 | out: |
| 5538 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5539 | return ret; |
| 5540 | } |
| 5541 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5542 | /* Destroy the slot table */ |
| 5543 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5544 | { |
| 5545 | if (session->fc_slot_table.slots != NULL) { |
| 5546 | kfree(session->fc_slot_table.slots); |
| 5547 | session->fc_slot_table.slots = NULL; |
| 5548 | } |
| 5549 | if (session->bc_slot_table.slots != NULL) { |
| 5550 | kfree(session->bc_slot_table.slots); |
| 5551 | session->bc_slot_table.slots = NULL; |
| 5552 | } |
| 5553 | return; |
| 5554 | } |
| 5555 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5556 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5557 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5558 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5559 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5560 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5561 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5562 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5563 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5564 | dprintk("--> %s\n", __func__); |
| 5565 | /* Fore channel */ |
| 5566 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5567 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5568 | if (status) /* -ENOMEM */ |
| 5569 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5570 | /* Back channel */ |
| 5571 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5572 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5573 | if (status && tbl->slots == NULL) |
| 5574 | /* Fore and back channel share a connection so get |
| 5575 | * both slot tables or neither */ |
| 5576 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5577 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5581 | { |
| 5582 | struct nfs4_session *session; |
| 5583 | struct nfs4_slot_table *tbl; |
| 5584 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5585 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5586 | if (!session) |
| 5587 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5588 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5589 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5590 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5591 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5592 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5593 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5594 | |
| 5595 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5596 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5597 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5598 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5599 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5600 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5601 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5602 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5603 | session->clp = clp; |
| 5604 | return session; |
| 5605 | } |
| 5606 | |
| 5607 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5608 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5609 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5610 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5611 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5612 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5613 | nfs4_proc_destroy_session(session, cred); |
| 5614 | if (cred) |
| 5615 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5616 | |
| 5617 | rcu_read_lock(); |
| 5618 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5619 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5620 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5621 | __func__, xprt); |
| 5622 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5623 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5624 | kfree(session); |
| 5625 | } |
| 5626 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5627 | /* |
| 5628 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5629 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5630 | * use them. |
| 5631 | * |
| 5632 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5633 | * always set csa_cachethis to FALSE because the current implementation |
| 5634 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5635 | */ |
| 5636 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5637 | { |
| 5638 | struct nfs4_session *session = args->client->cl_session; |
| 5639 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5640 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5641 | |
| 5642 | if (mxrqst_sz == 0) |
| 5643 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5644 | if (mxresp_sz == 0) |
| 5645 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5646 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5647 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5648 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5649 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5650 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5651 | |
| 5652 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5653 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5654 | __func__, |
| 5655 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5656 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5657 | |
| 5658 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5659 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5660 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5661 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5662 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5663 | args->bc_attrs.max_reqs = 1; |
| 5664 | |
| 5665 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5666 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5667 | __func__, |
| 5668 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5669 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5670 | args->bc_attrs.max_reqs); |
| 5671 | } |
| 5672 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5673 | 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] | 5674 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5675 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5676 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5677 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5678 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5679 | return -EINVAL; |
| 5680 | /* |
| 5681 | * Our requested max_ops is the minimum we need; we're not |
| 5682 | * prepared to break up compounds into smaller pieces than that. |
| 5683 | * So, no point even trying to continue if the server won't |
| 5684 | * cooperate: |
| 5685 | */ |
| 5686 | if (rcvd->max_ops < sent->max_ops) |
| 5687 | return -EINVAL; |
| 5688 | if (rcvd->max_reqs == 0) |
| 5689 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5690 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5691 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5692 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5693 | } |
| 5694 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5695 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5696 | { |
| 5697 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5698 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5699 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5700 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5701 | return -EINVAL; |
| 5702 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5703 | return -EINVAL; |
| 5704 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5705 | return -EINVAL; |
| 5706 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5707 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5708 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5709 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5710 | return -EINVAL; |
| 5711 | return 0; |
| 5712 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5713 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5714 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5715 | struct nfs4_session *session) |
| 5716 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5717 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5718 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5719 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5720 | if (ret) |
| 5721 | return ret; |
| 5722 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5723 | } |
| 5724 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5725 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5726 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5727 | { |
| 5728 | struct nfs4_session *session = clp->cl_session; |
| 5729 | struct nfs41_create_session_args args = { |
| 5730 | .client = clp, |
| 5731 | .cb_program = NFS4_CALLBACK, |
| 5732 | }; |
| 5733 | struct nfs41_create_session_res res = { |
| 5734 | .client = clp, |
| 5735 | }; |
| 5736 | struct rpc_message msg = { |
| 5737 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5738 | .rpc_argp = &args, |
| 5739 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5740 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5741 | }; |
| 5742 | int status; |
| 5743 | |
| 5744 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5745 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5746 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5747 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5748 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5749 | if (!status) |
| 5750 | /* Verify the session's negotiated channel_attrs values */ |
| 5751 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5752 | if (!status) { |
| 5753 | /* Increment the clientid slot sequence id */ |
| 5754 | clp->cl_seqid++; |
| 5755 | } |
| 5756 | |
| 5757 | return status; |
| 5758 | } |
| 5759 | |
| 5760 | /* |
| 5761 | * Issues a CREATE_SESSION operation to the server. |
| 5762 | * It is the responsibility of the caller to verify the session is |
| 5763 | * expired before calling this routine. |
| 5764 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5765 | 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] | 5766 | { |
| 5767 | int status; |
| 5768 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5769 | struct nfs4_session *session = clp->cl_session; |
| 5770 | |
| 5771 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5772 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5773 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5774 | if (status) |
| 5775 | goto out; |
| 5776 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5777 | /* Init or reset the session slot tables */ |
| 5778 | status = nfs4_setup_session_slot_tables(session); |
| 5779 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5780 | if (status) |
| 5781 | goto out; |
| 5782 | |
| 5783 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5784 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5785 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5786 | out: |
| 5787 | dprintk("<-- %s\n", __func__); |
| 5788 | return status; |
| 5789 | } |
| 5790 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5791 | /* |
| 5792 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5793 | * The caller must serialize access to this routine. |
| 5794 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5795 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5796 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5797 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5798 | struct rpc_message msg = { |
| 5799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5800 | .rpc_argp = session, |
| 5801 | .rpc_cred = cred, |
| 5802 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5803 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5804 | |
| 5805 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5806 | |
| 5807 | /* session is still being setup */ |
| 5808 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5809 | return status; |
| 5810 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5811 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5812 | |
| 5813 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5814 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5815 | "Session has been destroyed regardless...\n", status); |
| 5816 | |
| 5817 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5818 | return status; |
| 5819 | } |
| 5820 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5821 | /* |
| 5822 | * With sessions, the client is not marked ready until after a |
| 5823 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 5824 | * |
| 5825 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 5826 | * other versions of NFS can be tried. |
| 5827 | */ |
| 5828 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 5829 | { |
| 5830 | int ret; |
| 5831 | |
| 5832 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 5833 | ret = nfs4_client_recover_expired_lease(clp); |
| 5834 | if (ret) |
| 5835 | return ret; |
| 5836 | } |
| 5837 | if (clp->cl_cons_state < NFS_CS_READY) |
| 5838 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 5839 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5840 | return 0; |
| 5841 | } |
| 5842 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5843 | int nfs4_init_session(struct nfs_server *server) |
| 5844 | { |
| 5845 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5846 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5847 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5848 | |
| 5849 | if (!nfs4_has_session(clp)) |
| 5850 | return 0; |
| 5851 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5852 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5853 | spin_lock(&clp->cl_lock); |
| 5854 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5855 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5856 | rsize = server->rsize; |
| 5857 | if (rsize == 0) |
| 5858 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5859 | wsize = server->wsize; |
| 5860 | if (wsize == 0) |
| 5861 | wsize = NFS_MAX_FILE_IO_SIZE; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5862 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5863 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5864 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
| 5865 | } |
| 5866 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5867 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5868 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5869 | } |
| 5870 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5871 | int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time) |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5872 | { |
| 5873 | struct nfs4_session *session = clp->cl_session; |
| 5874 | int ret; |
| 5875 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5876 | spin_lock(&clp->cl_lock); |
| 5877 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 5878 | /* |
| 5879 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 5880 | * DS lease to be equal to the MDS lease. |
| 5881 | */ |
| 5882 | clp->cl_lease_time = lease_time; |
| 5883 | clp->cl_last_renewal = jiffies; |
| 5884 | } |
| 5885 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5886 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5887 | ret = nfs41_check_session_ready(clp); |
| 5888 | if (ret) |
| 5889 | return ret; |
| 5890 | /* Test for the DS role */ |
| 5891 | if (!is_ds_client(clp)) |
| 5892 | return -ENODEV; |
| 5893 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5894 | } |
| 5895 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5896 | |
| 5897 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5898 | /* |
| 5899 | * Renew the cl_session lease. |
| 5900 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5901 | struct nfs4_sequence_data { |
| 5902 | struct nfs_client *clp; |
| 5903 | struct nfs4_sequence_args args; |
| 5904 | struct nfs4_sequence_res res; |
| 5905 | }; |
| 5906 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5907 | static void nfs41_sequence_release(void *data) |
| 5908 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5909 | struct nfs4_sequence_data *calldata = data; |
| 5910 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5911 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5912 | if (atomic_read(&clp->cl_count) > 1) |
| 5913 | nfs4_schedule_state_renewal(clp); |
| 5914 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5915 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5916 | } |
| 5917 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5918 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5919 | { |
| 5920 | switch(task->tk_status) { |
| 5921 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5922 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5923 | return -EAGAIN; |
| 5924 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5925 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5926 | } |
| 5927 | return 0; |
| 5928 | } |
| 5929 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5930 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5931 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5932 | struct nfs4_sequence_data *calldata = data; |
| 5933 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5934 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5935 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5936 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5937 | |
| 5938 | if (task->tk_status < 0) { |
| 5939 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5940 | if (atomic_read(&clp->cl_count) == 1) |
| 5941 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5942 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5943 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5944 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5945 | return; |
| 5946 | } |
| 5947 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5948 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5949 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5950 | dprintk("<-- %s\n", __func__); |
| 5951 | } |
| 5952 | |
| 5953 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5954 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5955 | struct nfs4_sequence_data *calldata = data; |
| 5956 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5957 | struct nfs4_sequence_args *args; |
| 5958 | struct nfs4_sequence_res *res; |
| 5959 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5960 | args = task->tk_msg.rpc_argp; |
| 5961 | res = task->tk_msg.rpc_resp; |
| 5962 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5963 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5964 | return; |
| 5965 | rpc_call_start(task); |
| 5966 | } |
| 5967 | |
| 5968 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5969 | .rpc_call_done = nfs41_sequence_call_done, |
| 5970 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5971 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5972 | }; |
| 5973 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5974 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5975 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5976 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5977 | struct rpc_message msg = { |
| 5978 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5979 | .rpc_cred = cred, |
| 5980 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5981 | struct rpc_task_setup task_setup_data = { |
| 5982 | .rpc_client = clp->cl_rpcclient, |
| 5983 | .rpc_message = &msg, |
| 5984 | .callback_ops = &nfs41_sequence_ops, |
| 5985 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5986 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5987 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5988 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5989 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5990 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5991 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5992 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5993 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5994 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5995 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5996 | msg.rpc_argp = &calldata->args; |
| 5997 | msg.rpc_resp = &calldata->res; |
| 5998 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5999 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6000 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6001 | return rpc_run_task(&task_setup_data); |
| 6002 | } |
| 6003 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6004 | 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] | 6005 | { |
| 6006 | struct rpc_task *task; |
| 6007 | int ret = 0; |
| 6008 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6009 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6010 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6011 | task = _nfs41_proc_sequence(clp, cred); |
| 6012 | if (IS_ERR(task)) |
| 6013 | ret = PTR_ERR(task); |
| 6014 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6015 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6016 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6017 | return ret; |
| 6018 | } |
| 6019 | |
| 6020 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6021 | { |
| 6022 | struct rpc_task *task; |
| 6023 | int ret; |
| 6024 | |
| 6025 | task = _nfs41_proc_sequence(clp, cred); |
| 6026 | if (IS_ERR(task)) { |
| 6027 | ret = PTR_ERR(task); |
| 6028 | goto out; |
| 6029 | } |
| 6030 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6031 | if (!ret) { |
| 6032 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6033 | |
| 6034 | if (task->tk_status == 0) |
| 6035 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6036 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6037 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6038 | rpc_put_task(task); |
| 6039 | out: |
| 6040 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6041 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6042 | } |
| 6043 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6044 | struct nfs4_reclaim_complete_data { |
| 6045 | struct nfs_client *clp; |
| 6046 | struct nfs41_reclaim_complete_args arg; |
| 6047 | struct nfs41_reclaim_complete_res res; |
| 6048 | }; |
| 6049 | |
| 6050 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6051 | { |
| 6052 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6053 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6054 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6055 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6056 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6057 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6058 | return; |
| 6059 | |
| 6060 | rpc_call_start(task); |
| 6061 | } |
| 6062 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6063 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6064 | { |
| 6065 | switch(task->tk_status) { |
| 6066 | case 0: |
| 6067 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6068 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6069 | break; |
| 6070 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6071 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6072 | /* fall through */ |
| 6073 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6074 | return -EAGAIN; |
| 6075 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6076 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6077 | } |
| 6078 | return 0; |
| 6079 | } |
| 6080 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6081 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6082 | { |
| 6083 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6084 | struct nfs_client *clp = calldata->clp; |
| 6085 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6086 | |
| 6087 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6088 | if (!nfs41_sequence_done(task, res)) |
| 6089 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6090 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6091 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6092 | rpc_restart_call_prepare(task); |
| 6093 | return; |
| 6094 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6095 | dprintk("<-- %s\n", __func__); |
| 6096 | } |
| 6097 | |
| 6098 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6099 | { |
| 6100 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6101 | |
| 6102 | kfree(calldata); |
| 6103 | } |
| 6104 | |
| 6105 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6106 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6107 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6108 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6109 | }; |
| 6110 | |
| 6111 | /* |
| 6112 | * Issue a global reclaim complete. |
| 6113 | */ |
| 6114 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6115 | { |
| 6116 | struct nfs4_reclaim_complete_data *calldata; |
| 6117 | struct rpc_task *task; |
| 6118 | struct rpc_message msg = { |
| 6119 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6120 | }; |
| 6121 | struct rpc_task_setup task_setup_data = { |
| 6122 | .rpc_client = clp->cl_rpcclient, |
| 6123 | .rpc_message = &msg, |
| 6124 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6125 | .flags = RPC_TASK_ASYNC, |
| 6126 | }; |
| 6127 | int status = -ENOMEM; |
| 6128 | |
| 6129 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6130 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6131 | if (calldata == NULL) |
| 6132 | goto out; |
| 6133 | calldata->clp = clp; |
| 6134 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6135 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6136 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6137 | msg.rpc_argp = &calldata->arg; |
| 6138 | msg.rpc_resp = &calldata->res; |
| 6139 | task_setup_data.callback_data = calldata; |
| 6140 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6141 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6142 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6143 | goto out; |
| 6144 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6145 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6146 | if (status == 0) |
| 6147 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6148 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6149 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6150 | out: |
| 6151 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6152 | return status; |
| 6153 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6154 | |
| 6155 | static void |
| 6156 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6157 | { |
| 6158 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6159 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6160 | |
| 6161 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6162 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6163 | * right now covering the LAYOUTGET we are about to send. |
| 6164 | * However, that is not so catastrophic, and there seems |
| 6165 | * to be no way to prevent it completely. |
| 6166 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6167 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6168 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6169 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6170 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6171 | NFS_I(lgp->args.inode)->layout, |
| 6172 | lgp->args.ctx->state)) { |
| 6173 | rpc_exit(task, NFS4_OK); |
| 6174 | return; |
| 6175 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6176 | rpc_call_start(task); |
| 6177 | } |
| 6178 | |
| 6179 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6180 | { |
| 6181 | struct nfs4_layoutget *lgp = calldata; |
| 6182 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6183 | |
| 6184 | dprintk("--> %s\n", __func__); |
| 6185 | |
| 6186 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 6187 | return; |
| 6188 | |
| 6189 | switch (task->tk_status) { |
| 6190 | case 0: |
| 6191 | break; |
| 6192 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6193 | case -NFS4ERR_RECALLCONFLICT: |
| 6194 | task->tk_status = -NFS4ERR_DELAY; |
| 6195 | /* Fall through */ |
| 6196 | default: |
| 6197 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6198 | rpc_restart_call_prepare(task); |
| 6199 | return; |
| 6200 | } |
| 6201 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6202 | dprintk("<-- %s\n", __func__); |
| 6203 | } |
| 6204 | |
| 6205 | static void nfs4_layoutget_release(void *calldata) |
| 6206 | { |
| 6207 | struct nfs4_layoutget *lgp = calldata; |
| 6208 | |
| 6209 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6210 | put_nfs_open_context(lgp->args.ctx); |
| 6211 | kfree(calldata); |
| 6212 | dprintk("<-- %s\n", __func__); |
| 6213 | } |
| 6214 | |
| 6215 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6216 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6217 | .rpc_call_done = nfs4_layoutget_done, |
| 6218 | .rpc_release = nfs4_layoutget_release, |
| 6219 | }; |
| 6220 | |
| 6221 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 6222 | { |
| 6223 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6224 | struct rpc_task *task; |
| 6225 | struct rpc_message msg = { |
| 6226 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6227 | .rpc_argp = &lgp->args, |
| 6228 | .rpc_resp = &lgp->res, |
| 6229 | }; |
| 6230 | struct rpc_task_setup task_setup_data = { |
| 6231 | .rpc_client = server->client, |
| 6232 | .rpc_message = &msg, |
| 6233 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6234 | .callback_data = lgp, |
| 6235 | .flags = RPC_TASK_ASYNC, |
| 6236 | }; |
| 6237 | int status = 0; |
| 6238 | |
| 6239 | dprintk("--> %s\n", __func__); |
| 6240 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6241 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6242 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6243 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6244 | task = rpc_run_task(&task_setup_data); |
| 6245 | if (IS_ERR(task)) |
| 6246 | return PTR_ERR(task); |
| 6247 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6248 | if (status == 0) |
| 6249 | status = task->tk_status; |
| 6250 | if (status == 0) |
| 6251 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6252 | rpc_put_task(task); |
| 6253 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6254 | return status; |
| 6255 | } |
| 6256 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6257 | static void |
| 6258 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6259 | { |
| 6260 | struct nfs4_layoutreturn *lrp = calldata; |
| 6261 | |
| 6262 | dprintk("--> %s\n", __func__); |
| 6263 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6264 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6265 | return; |
| 6266 | rpc_call_start(task); |
| 6267 | } |
| 6268 | |
| 6269 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6270 | { |
| 6271 | struct nfs4_layoutreturn *lrp = calldata; |
| 6272 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6273 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6274 | |
| 6275 | dprintk("--> %s\n", __func__); |
| 6276 | |
| 6277 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6278 | return; |
| 6279 | |
| 6280 | server = NFS_SERVER(lrp->args.inode); |
| 6281 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6282 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6283 | return; |
| 6284 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6285 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6286 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6287 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6288 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6289 | } else |
| 6290 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 6291 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6292 | lo->plh_block_lgets--; |
| 6293 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6294 | dprintk("<-- %s\n", __func__); |
| 6295 | } |
| 6296 | |
| 6297 | static void nfs4_layoutreturn_release(void *calldata) |
| 6298 | { |
| 6299 | struct nfs4_layoutreturn *lrp = calldata; |
| 6300 | |
| 6301 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6302 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6303 | kfree(calldata); |
| 6304 | dprintk("<-- %s\n", __func__); |
| 6305 | } |
| 6306 | |
| 6307 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6308 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6309 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6310 | .rpc_release = nfs4_layoutreturn_release, |
| 6311 | }; |
| 6312 | |
| 6313 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6314 | { |
| 6315 | struct rpc_task *task; |
| 6316 | struct rpc_message msg = { |
| 6317 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6318 | .rpc_argp = &lrp->args, |
| 6319 | .rpc_resp = &lrp->res, |
| 6320 | }; |
| 6321 | struct rpc_task_setup task_setup_data = { |
| 6322 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6323 | .rpc_message = &msg, |
| 6324 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6325 | .callback_data = lrp, |
| 6326 | }; |
| 6327 | int status; |
| 6328 | |
| 6329 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6330 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6331 | task = rpc_run_task(&task_setup_data); |
| 6332 | if (IS_ERR(task)) |
| 6333 | return PTR_ERR(task); |
| 6334 | status = task->tk_status; |
| 6335 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6336 | rpc_put_task(task); |
| 6337 | return status; |
| 6338 | } |
| 6339 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6340 | /* |
| 6341 | * Retrieve the list of Data Server devices from the MDS. |
| 6342 | */ |
| 6343 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6344 | const struct nfs_fh *fh, |
| 6345 | struct pnfs_devicelist *devlist) |
| 6346 | { |
| 6347 | struct nfs4_getdevicelist_args args = { |
| 6348 | .fh = fh, |
| 6349 | .layoutclass = server->pnfs_curr_ld->id, |
| 6350 | }; |
| 6351 | struct nfs4_getdevicelist_res res = { |
| 6352 | .devlist = devlist, |
| 6353 | }; |
| 6354 | struct rpc_message msg = { |
| 6355 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6356 | .rpc_argp = &args, |
| 6357 | .rpc_resp = &res, |
| 6358 | }; |
| 6359 | int status; |
| 6360 | |
| 6361 | dprintk("--> %s\n", __func__); |
| 6362 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6363 | &res.seq_res, 0); |
| 6364 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6365 | return status; |
| 6366 | } |
| 6367 | |
| 6368 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6369 | const struct nfs_fh *fh, |
| 6370 | struct pnfs_devicelist *devlist) |
| 6371 | { |
| 6372 | struct nfs4_exception exception = { }; |
| 6373 | int err; |
| 6374 | |
| 6375 | do { |
| 6376 | err = nfs4_handle_exception(server, |
| 6377 | _nfs4_getdevicelist(server, fh, devlist), |
| 6378 | &exception); |
| 6379 | } while (exception.retry); |
| 6380 | |
| 6381 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6382 | err, devlist->num_devs); |
| 6383 | |
| 6384 | return err; |
| 6385 | } |
| 6386 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6387 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6388 | static int |
| 6389 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6390 | { |
| 6391 | struct nfs4_getdeviceinfo_args args = { |
| 6392 | .pdev = pdev, |
| 6393 | }; |
| 6394 | struct nfs4_getdeviceinfo_res res = { |
| 6395 | .pdev = pdev, |
| 6396 | }; |
| 6397 | struct rpc_message msg = { |
| 6398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6399 | .rpc_argp = &args, |
| 6400 | .rpc_resp = &res, |
| 6401 | }; |
| 6402 | int status; |
| 6403 | |
| 6404 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6405 | 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] | 6406 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6407 | |
| 6408 | return status; |
| 6409 | } |
| 6410 | |
| 6411 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6412 | { |
| 6413 | struct nfs4_exception exception = { }; |
| 6414 | int err; |
| 6415 | |
| 6416 | do { |
| 6417 | err = nfs4_handle_exception(server, |
| 6418 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6419 | &exception); |
| 6420 | } while (exception.retry); |
| 6421 | return err; |
| 6422 | } |
| 6423 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6424 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6425 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6426 | { |
| 6427 | struct nfs4_layoutcommit_data *data = calldata; |
| 6428 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6429 | |
| 6430 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6431 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6432 | return; |
| 6433 | rpc_call_start(task); |
| 6434 | } |
| 6435 | |
| 6436 | static void |
| 6437 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6438 | { |
| 6439 | struct nfs4_layoutcommit_data *data = calldata; |
| 6440 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6441 | |
| 6442 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6443 | return; |
| 6444 | |
| 6445 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6446 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6447 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6448 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6449 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6450 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6451 | break; |
| 6452 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6453 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6454 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6455 | break; |
| 6456 | default: |
| 6457 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6458 | rpc_restart_call_prepare(task); |
| 6459 | return; |
| 6460 | } |
| 6461 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | static void nfs4_layoutcommit_release(void *calldata) |
| 6465 | { |
| 6466 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6467 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6468 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6469 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6470 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6471 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6472 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6473 | list_del_init(&lseg->pls_lc_list); |
| 6474 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6475 | &lseg->pls_flags)) |
| 6476 | put_lseg(lseg); |
| 6477 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6478 | |
| 6479 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6480 | smp_mb__after_clear_bit(); |
| 6481 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6482 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6483 | put_rpccred(data->cred); |
| 6484 | kfree(data); |
| 6485 | } |
| 6486 | |
| 6487 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6488 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6489 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6490 | .rpc_release = nfs4_layoutcommit_release, |
| 6491 | }; |
| 6492 | |
| 6493 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6494 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6495 | { |
| 6496 | struct rpc_message msg = { |
| 6497 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6498 | .rpc_argp = &data->args, |
| 6499 | .rpc_resp = &data->res, |
| 6500 | .rpc_cred = data->cred, |
| 6501 | }; |
| 6502 | struct rpc_task_setup task_setup_data = { |
| 6503 | .task = &data->task, |
| 6504 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6505 | .rpc_message = &msg, |
| 6506 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6507 | .callback_data = data, |
| 6508 | .flags = RPC_TASK_ASYNC, |
| 6509 | }; |
| 6510 | struct rpc_task *task; |
| 6511 | int status = 0; |
| 6512 | |
| 6513 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6514 | "lbw: %llu inode %lu\n", |
| 6515 | data->task.tk_pid, sync, |
| 6516 | data->args.lastbytewritten, |
| 6517 | data->args.inode->i_ino); |
| 6518 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6519 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6520 | task = rpc_run_task(&task_setup_data); |
| 6521 | if (IS_ERR(task)) |
| 6522 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6523 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6524 | goto out; |
| 6525 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6526 | if (status != 0) |
| 6527 | goto out; |
| 6528 | status = task->tk_status; |
| 6529 | out: |
| 6530 | dprintk("%s: status %d\n", __func__, status); |
| 6531 | rpc_put_task(task); |
| 6532 | return status; |
| 6533 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6534 | |
| 6535 | static int |
| 6536 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6537 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6538 | { |
| 6539 | struct nfs41_secinfo_no_name_args args = { |
| 6540 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6541 | }; |
| 6542 | struct nfs4_secinfo_res res = { |
| 6543 | .flavors = flavors, |
| 6544 | }; |
| 6545 | struct rpc_message msg = { |
| 6546 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6547 | .rpc_argp = &args, |
| 6548 | .rpc_resp = &res, |
| 6549 | }; |
| 6550 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6551 | } |
| 6552 | |
| 6553 | static int |
| 6554 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6555 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6556 | { |
| 6557 | struct nfs4_exception exception = { }; |
| 6558 | int err; |
| 6559 | do { |
| 6560 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6561 | switch (err) { |
| 6562 | case 0: |
| 6563 | case -NFS4ERR_WRONGSEC: |
| 6564 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6565 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6566 | default: |
| 6567 | err = nfs4_handle_exception(server, err, &exception); |
| 6568 | } |
| 6569 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6570 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6571 | return err; |
| 6572 | } |
| 6573 | |
| 6574 | static int |
| 6575 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6576 | struct nfs_fsinfo *info) |
| 6577 | { |
| 6578 | int err; |
| 6579 | struct page *page; |
| 6580 | rpc_authflavor_t flavor; |
| 6581 | struct nfs4_secinfo_flavors *flavors; |
| 6582 | |
| 6583 | page = alloc_page(GFP_KERNEL); |
| 6584 | if (!page) { |
| 6585 | err = -ENOMEM; |
| 6586 | goto out; |
| 6587 | } |
| 6588 | |
| 6589 | flavors = page_address(page); |
| 6590 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6591 | |
| 6592 | /* |
| 6593 | * Fall back on "guess and check" method if |
| 6594 | * the server doesn't support SECINFO_NO_NAME |
| 6595 | */ |
| 6596 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6597 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6598 | goto out_freepage; |
| 6599 | } |
| 6600 | if (err) |
| 6601 | goto out_freepage; |
| 6602 | |
| 6603 | flavor = nfs_find_best_sec(flavors); |
| 6604 | if (err == 0) |
| 6605 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6606 | |
| 6607 | out_freepage: |
| 6608 | put_page(page); |
| 6609 | if (err == -EACCES) |
| 6610 | return -EPERM; |
| 6611 | out: |
| 6612 | return err; |
| 6613 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6614 | |
| 6615 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6616 | { |
| 6617 | int status; |
| 6618 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6619 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6620 | }; |
| 6621 | struct nfs41_test_stateid_res res; |
| 6622 | struct rpc_message msg = { |
| 6623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6624 | .rpc_argp = &args, |
| 6625 | .rpc_resp = &res, |
| 6626 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6627 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6628 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6629 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6630 | if (status != NFS_OK) |
| 6631 | return status; |
| 6632 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6633 | } |
| 6634 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6635 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6636 | { |
| 6637 | struct nfs4_exception exception = { }; |
| 6638 | int err; |
| 6639 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6640 | err = _nfs41_test_stateid(server, stateid); |
| 6641 | if (err != -NFS4ERR_DELAY) |
| 6642 | break; |
| 6643 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6644 | } while (exception.retry); |
| 6645 | return err; |
| 6646 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6647 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6648 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6649 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6650 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6651 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6652 | }; |
| 6653 | struct nfs41_free_stateid_res res; |
| 6654 | struct rpc_message msg = { |
| 6655 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6656 | .rpc_argp = &args, |
| 6657 | .rpc_resp = &res, |
| 6658 | }; |
| 6659 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6660 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6661 | return nfs4_call_sync_sequence(server->client, server, &msg, |
| 6662 | &args.seq_args, &res.seq_res, 1); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6663 | } |
| 6664 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6665 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6666 | { |
| 6667 | struct nfs4_exception exception = { }; |
| 6668 | int err; |
| 6669 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6670 | err = _nfs4_free_stateid(server, stateid); |
| 6671 | if (err != -NFS4ERR_DELAY) |
| 6672 | break; |
| 6673 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6674 | } while (exception.retry); |
| 6675 | return err; |
| 6676 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6677 | |
| 6678 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6679 | const nfs4_stateid *s2) |
| 6680 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6681 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6682 | return false; |
| 6683 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6684 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6685 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6686 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6687 | return true; |
| 6688 | |
| 6689 | return false; |
| 6690 | } |
| 6691 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6692 | #endif /* CONFIG_NFS_V4_1 */ |
| 6693 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6694 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6695 | const nfs4_stateid *s2) |
| 6696 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6697 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6698 | } |
| 6699 | |
| 6700 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6701 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6702 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6703 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6704 | .recover_open = nfs4_open_reclaim, |
| 6705 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6706 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6707 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6708 | }; |
| 6709 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6710 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6711 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6712 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6713 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6714 | .recover_open = nfs4_open_reclaim, |
| 6715 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6716 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6717 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6718 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6719 | }; |
| 6720 | #endif /* CONFIG_NFS_V4_1 */ |
| 6721 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6722 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6723 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6724 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6725 | .recover_open = nfs4_open_expired, |
| 6726 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6727 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6728 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6729 | }; |
| 6730 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6731 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6732 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6733 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6734 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6735 | .recover_open = nfs41_open_expired, |
| 6736 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6737 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6738 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6739 | }; |
| 6740 | #endif /* CONFIG_NFS_V4_1 */ |
| 6741 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6742 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6743 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6744 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6745 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6746 | }; |
| 6747 | |
| 6748 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6749 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6750 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6751 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6752 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6753 | }; |
| 6754 | #endif |
| 6755 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6756 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6757 | .minor_version = 0, |
| 6758 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6759 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6760 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6761 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6762 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6763 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6764 | }; |
| 6765 | |
| 6766 | #if defined(CONFIG_NFS_V4_1) |
| 6767 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6768 | .minor_version = 1, |
| 6769 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6770 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6771 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6772 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6773 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6774 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6775 | }; |
| 6776 | #endif |
| 6777 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6778 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6779 | [0] = &nfs_v4_0_minor_ops, |
| 6780 | #if defined(CONFIG_NFS_V4_1) |
| 6781 | [1] = &nfs_v4_1_minor_ops, |
| 6782 | #endif |
| 6783 | }; |
| 6784 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6785 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6786 | .permission = nfs_permission, |
| 6787 | .getattr = nfs_getattr, |
| 6788 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6789 | .getxattr = generic_getxattr, |
| 6790 | .setxattr = generic_setxattr, |
| 6791 | .listxattr = generic_listxattr, |
| 6792 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6793 | }; |
| 6794 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6795 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6796 | .version = 4, /* protocol version */ |
| 6797 | .dentry_ops = &nfs4_dentry_operations, |
| 6798 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6799 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6800 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6801 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6802 | .submount = nfs4_submount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6803 | .getattr = nfs4_proc_getattr, |
| 6804 | .setattr = nfs4_proc_setattr, |
| 6805 | .lookup = nfs4_proc_lookup, |
| 6806 | .access = nfs4_proc_access, |
| 6807 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6808 | .create = nfs4_proc_create, |
| 6809 | .remove = nfs4_proc_remove, |
| 6810 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6811 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6812 | .unlink_done = nfs4_proc_unlink_done, |
| 6813 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6814 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6815 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6816 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6817 | .link = nfs4_proc_link, |
| 6818 | .symlink = nfs4_proc_symlink, |
| 6819 | .mkdir = nfs4_proc_mkdir, |
| 6820 | .rmdir = nfs4_proc_remove, |
| 6821 | .readdir = nfs4_proc_readdir, |
| 6822 | .mknod = nfs4_proc_mknod, |
| 6823 | .statfs = nfs4_proc_statfs, |
| 6824 | .fsinfo = nfs4_proc_fsinfo, |
| 6825 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6826 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6827 | .decode_dirent = nfs4_decode_dirent, |
| 6828 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6829 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6830 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6831 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6832 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6833 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6834 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6835 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6836 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6837 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6838 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6839 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6840 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6841 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6842 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6843 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6844 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6845 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6846 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6847 | .free_client = nfs4_free_client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | }; |
| 6849 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6850 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6851 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6852 | .list = nfs4_xattr_list_nfs4_acl, |
| 6853 | .get = nfs4_xattr_get_nfs4_acl, |
| 6854 | .set = nfs4_xattr_set_nfs4_acl, |
| 6855 | }; |
| 6856 | |
| 6857 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6858 | &nfs4_xattr_nfs4_acl_handler, |
| 6859 | NULL |
| 6860 | }; |
| 6861 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6862 | module_param(max_session_slots, ushort, 0644); |
| 6863 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6864 | "requests the client will negotiate"); |
| 6865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | /* |
| 6867 | * Local variables: |
| 6868 | * c-basic-offset: 8 |
| 6869 | * End: |
| 6870 | */ |