Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 55 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 56 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 57 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 58 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 60 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 62 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 63 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 64 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 65 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 66 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 75 | static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE; |
| 76 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | 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] | 81 | 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] | 82 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 83 | 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] | 84 | 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] | 85 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 86 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 87 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 89 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 90 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 91 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 93 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 95 | if (err >= -1000) |
| 96 | return err; |
| 97 | switch (err) { |
| 98 | case -NFS4ERR_RESOURCE: |
| 99 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 100 | case -NFS4ERR_WRONGSEC: |
| 101 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 102 | case -NFS4ERR_BADOWNER: |
| 103 | case -NFS4ERR_BADNAME: |
| 104 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 105 | case -NFS4ERR_SHARE_DENIED: |
| 106 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 107 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 108 | return -EPROTONOSUPPORT; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 111 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 114 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * This is our standard bitmap for GETATTR requests. |
| 119 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 120 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | FATTR4_WORD0_TYPE |
| 122 | | FATTR4_WORD0_CHANGE |
| 123 | | FATTR4_WORD0_SIZE |
| 124 | | FATTR4_WORD0_FSID |
| 125 | | FATTR4_WORD0_FILEID, |
| 126 | FATTR4_WORD1_MODE |
| 127 | | FATTR4_WORD1_NUMLINKS |
| 128 | | FATTR4_WORD1_OWNER |
| 129 | | FATTR4_WORD1_OWNER_GROUP |
| 130 | | FATTR4_WORD1_RAWDEV |
| 131 | | FATTR4_WORD1_SPACE_USED |
| 132 | | FATTR4_WORD1_TIME_ACCESS |
| 133 | | FATTR4_WORD1_TIME_METADATA |
| 134 | | FATTR4_WORD1_TIME_MODIFY |
| 135 | }; |
| 136 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 137 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 138 | FATTR4_WORD0_TYPE |
| 139 | | FATTR4_WORD0_CHANGE |
| 140 | | FATTR4_WORD0_SIZE |
| 141 | | FATTR4_WORD0_FSID |
| 142 | | FATTR4_WORD0_FILEID, |
| 143 | FATTR4_WORD1_MODE |
| 144 | | FATTR4_WORD1_NUMLINKS |
| 145 | | FATTR4_WORD1_OWNER |
| 146 | | FATTR4_WORD1_OWNER_GROUP |
| 147 | | FATTR4_WORD1_RAWDEV |
| 148 | | FATTR4_WORD1_SPACE_USED |
| 149 | | FATTR4_WORD1_TIME_ACCESS |
| 150 | | FATTR4_WORD1_TIME_METADATA |
| 151 | | FATTR4_WORD1_TIME_MODIFY, |
| 152 | FATTR4_WORD2_MDSTHRESHOLD |
| 153 | }; |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | const u32 nfs4_statfs_bitmap[2] = { |
| 156 | FATTR4_WORD0_FILES_AVAIL |
| 157 | | FATTR4_WORD0_FILES_FREE |
| 158 | | FATTR4_WORD0_FILES_TOTAL, |
| 159 | FATTR4_WORD1_SPACE_AVAIL |
| 160 | | FATTR4_WORD1_SPACE_FREE |
| 161 | | FATTR4_WORD1_SPACE_TOTAL |
| 162 | }; |
| 163 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 164 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | FATTR4_WORD0_MAXLINK |
| 166 | | FATTR4_WORD0_MAXNAME, |
| 167 | 0 |
| 168 | }; |
| 169 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 170 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | | FATTR4_WORD0_MAXREAD |
| 172 | | FATTR4_WORD0_MAXWRITE |
| 173 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 174 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 175 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 176 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 179 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 180 | FATTR4_WORD0_TYPE |
| 181 | | FATTR4_WORD0_CHANGE |
| 182 | | FATTR4_WORD0_SIZE |
| 183 | | FATTR4_WORD0_FSID |
| 184 | | FATTR4_WORD0_FILEID |
| 185 | | FATTR4_WORD0_FS_LOCATIONS, |
| 186 | FATTR4_WORD1_MODE |
| 187 | | FATTR4_WORD1_NUMLINKS |
| 188 | | FATTR4_WORD1_OWNER |
| 189 | | FATTR4_WORD1_OWNER_GROUP |
| 190 | | FATTR4_WORD1_RAWDEV |
| 191 | | FATTR4_WORD1_SPACE_USED |
| 192 | | FATTR4_WORD1_TIME_ACCESS |
| 193 | | FATTR4_WORD1_TIME_METADATA |
| 194 | | FATTR4_WORD1_TIME_MODIFY |
| 195 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 196 | }; |
| 197 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 198 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | struct nfs4_readdir_arg *readdir) |
| 200 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 201 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | BUG_ON(readdir->count < 80); |
| 204 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 205 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | readdir->cookie = 0; |
| 211 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 212 | if (cookie == 2) |
| 213 | return; |
| 214 | |
| 215 | /* |
| 216 | * NFSv4 servers do not return entries for '.' and '..' |
| 217 | * Therefore, we fake these entries here. We let '.' |
| 218 | * have cookie 0 and '..' have cookie 1. Note that |
| 219 | * when talking to the server, we always send cookie 0 |
| 220 | * instead of 1 or 2. |
| 221 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 222 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | if (cookie == 0) { |
| 225 | *p++ = xdr_one; /* next */ |
| 226 | *p++ = xdr_zero; /* cookie, first word */ |
| 227 | *p++ = xdr_one; /* cookie, second word */ |
| 228 | *p++ = xdr_one; /* entry len */ |
| 229 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 230 | p++; |
| 231 | *p++ = xdr_one; /* bitmap length */ |
| 232 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 233 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 234 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | *p++ = xdr_one; /* next */ |
| 238 | *p++ = xdr_zero; /* cookie, first word */ |
| 239 | *p++ = xdr_two; /* cookie, second word */ |
| 240 | *p++ = xdr_two; /* entry len */ |
| 241 | memcpy(p, "..\0\0", 4); /* entry */ |
| 242 | p++; |
| 243 | *p++ = xdr_one; /* bitmap length */ |
| 244 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 245 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 246 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | readdir->pgbase = (char *)p - (char *)start; |
| 249 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 250 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 253 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 254 | { |
| 255 | int res; |
| 256 | |
| 257 | might_sleep(); |
| 258 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 259 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 260 | nfs_wait_bit_killable, TASK_KILLABLE); |
Chuck Lever | 46a87b8 | 2012-07-11 16:30:41 -0400 | [diff] [blame] | 261 | if (res) |
| 262 | return res; |
| 263 | |
| 264 | if (clp->cl_cons_state < 0) |
| 265 | return clp->cl_cons_state; |
| 266 | return 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 270 | { |
| 271 | int res = 0; |
| 272 | |
| 273 | might_sleep(); |
| 274 | |
| 275 | if (*timeout <= 0) |
| 276 | *timeout = NFS4_POLL_RETRY_MIN; |
| 277 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 278 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 279 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 280 | if (fatal_signal_pending(current)) |
| 281 | res = -ERESTARTSYS; |
| 282 | *timeout <<= 1; |
| 283 | return res; |
| 284 | } |
| 285 | |
| 286 | /* This is the error handling routine for processes that are allowed |
| 287 | * to sleep. |
| 288 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 289 | 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] | 290 | { |
| 291 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 292 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 293 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 294 | int ret = errorcode; |
| 295 | |
| 296 | exception->retry = 0; |
| 297 | switch(errorcode) { |
| 298 | case 0: |
| 299 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 300 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 301 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 302 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 303 | exception->retry = 1; |
| 304 | return 0; |
| 305 | } |
| 306 | if (state == NULL) |
| 307 | break; |
| 308 | nfs4_schedule_stateid_recovery(server, state); |
| 309 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 310 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 311 | case -NFS4ERR_ADMIN_REVOKED: |
| 312 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 313 | if (state == NULL) |
| 314 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 315 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 316 | nfs4_schedule_stateid_recovery(server, state); |
| 317 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 318 | case -NFS4ERR_EXPIRED: |
| 319 | if (state != NULL) |
| 320 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 321 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 322 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 323 | nfs4_schedule_lease_recovery(clp); |
| 324 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 325 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 326 | case -NFS4ERR_BADSESSION: |
| 327 | case -NFS4ERR_BADSLOT: |
| 328 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 329 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 330 | case -NFS4ERR_DEADSESSION: |
| 331 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 332 | case -NFS4ERR_SEQ_MISORDERED: |
| 333 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 334 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 335 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 336 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 337 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 338 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 339 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 340 | if (exception->timeout > HZ) { |
| 341 | /* We have retried a decent amount, time to |
| 342 | * fail |
| 343 | */ |
| 344 | ret = -EBUSY; |
| 345 | break; |
| 346 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 347 | case -NFS4ERR_GRACE: |
| 348 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 349 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 350 | ret = nfs4_delay(server->client, &exception->timeout); |
| 351 | if (ret != 0) |
| 352 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 353 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 354 | case -NFS4ERR_OLD_STATEID: |
| 355 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 356 | break; |
| 357 | case -NFS4ERR_BADOWNER: |
| 358 | /* The following works around a Linux server bug! */ |
| 359 | case -NFS4ERR_BADNAME: |
| 360 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 361 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 362 | exception->retry = 1; |
| 363 | printk(KERN_WARNING "NFS: v4 server %s " |
| 364 | "does not accept raw " |
| 365 | "uid/gids. " |
| 366 | "Reenabling the idmapper.\n", |
| 367 | server->nfs_client->cl_hostname); |
| 368 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 369 | } |
| 370 | /* We failed to handle the error */ |
| 371 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 372 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 373 | ret = nfs4_wait_clnt_recover(clp); |
| 374 | if (ret == 0) |
| 375 | exception->retry = 1; |
| 376 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 380 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | spin_lock(&clp->cl_lock); |
| 383 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 384 | clp->cl_last_renewal = timestamp; |
| 385 | spin_unlock(&clp->cl_lock); |
| 386 | } |
| 387 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 388 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 389 | { |
| 390 | do_renew_lease(server->nfs_client, timestamp); |
| 391 | } |
| 392 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 393 | #if defined(CONFIG_NFS_V4_1) |
| 394 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 395 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 396 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 397 | * |
| 398 | * freeing a slot is trivially done by clearing its respective bit |
| 399 | * in the bitmap. |
| 400 | * If the freed slotid equals highest_used_slotid we want to update it |
| 401 | * so that the server would be able to size down the slot table if needed, |
| 402 | * otherwise we know that the highest_used_slotid is still in use. |
| 403 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 404 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 405 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 406 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 407 | * |
| 408 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 409 | */ |
| 410 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 411 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 412 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 413 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 414 | /* clear used bit in bitmap */ |
| 415 | __clear_bit(slotid, tbl->used_slots); |
| 416 | |
| 417 | /* update highest_used_slotid when it is freed */ |
| 418 | if (slotid == tbl->highest_used_slotid) { |
| 419 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 420 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 421 | tbl->highest_used_slotid = slotid; |
| 422 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 423 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 424 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 425 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 426 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 429 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 430 | { |
| 431 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 432 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 435 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 436 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 437 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 438 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 439 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 440 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 441 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 442 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 446 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 447 | return; |
| 448 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 449 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 450 | complete(&ses->fc_slot_table.complete); |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Signal state manager thread if session back channel is drained |
| 455 | */ |
| 456 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 457 | { |
| 458 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 459 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 460 | return; |
| 461 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 462 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 465 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 466 | { |
| 467 | struct nfs4_slot_table *tbl; |
| 468 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 469 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 470 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 471 | /* just wake up the next guy waiting since |
| 472 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 473 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 474 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 475 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 476 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 477 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 478 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 479 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 480 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 481 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 482 | } |
| 483 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 484 | 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] | 485 | { |
| 486 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 488 | |
| 489 | /* |
| 490 | * sr_status remains 1 if an RPC level error occurred. The server |
| 491 | * may or may not have processed the sequence operation.. |
| 492 | * Proceed as if the server received and processed the sequence |
| 493 | * operation. |
| 494 | */ |
| 495 | if (res->sr_status == 1) |
| 496 | res->sr_status = NFS_OK; |
| 497 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 498 | /* don't increment the sequence number if the task wasn't sent */ |
| 499 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 500 | goto out; |
| 501 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 502 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 503 | switch (res->sr_status) { |
| 504 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 505 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 506 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 507 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 508 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 509 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 510 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 511 | if (res->sr_status_flags != 0) |
| 512 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | break; |
| 514 | case -NFS4ERR_DELAY: |
| 515 | /* The server detected a resend of the RPC call and |
| 516 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 517 | * of RFC5661. |
| 518 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 519 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 520 | __func__, |
| 521 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 522 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 523 | goto out_retry; |
| 524 | default: |
| 525 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 526 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 527 | } |
| 528 | out: |
| 529 | /* The session may be reset by one of the error handlers. */ |
| 530 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 531 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 532 | return 1; |
| 533 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 534 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 535 | goto out; |
| 536 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 537 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 538 | } |
| 539 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 540 | static int nfs4_sequence_done(struct rpc_task *task, |
| 541 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 542 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 543 | if (res->sr_session == NULL) |
| 544 | return 1; |
| 545 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 548 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 549 | * nfs4_find_slot - efficiently look for a free slot |
| 550 | * |
| 551 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 552 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 553 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 554 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 555 | * |
| 556 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 557 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 558 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 559 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 560 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 561 | u32 slotid; |
| 562 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 563 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 564 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 565 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 566 | tbl->max_slots); |
| 567 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 568 | if (slotid >= tbl->max_slots) |
| 569 | goto out; |
| 570 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 571 | if (slotid > tbl->highest_used_slotid || |
| 572 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 573 | tbl->highest_used_slotid = slotid; |
| 574 | ret_id = slotid; |
| 575 | out: |
| 576 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 577 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 578 | return ret_id; |
| 579 | } |
| 580 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 581 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 582 | struct nfs4_sequence_res *res, int cache_reply) |
| 583 | { |
| 584 | args->sa_session = NULL; |
| 585 | args->sa_cache_this = 0; |
| 586 | if (cache_reply) |
| 587 | args->sa_cache_this = 1; |
| 588 | res->sr_session = NULL; |
| 589 | res->sr_slot = NULL; |
| 590 | } |
| 591 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 592 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 593 | struct nfs4_sequence_args *args, |
| 594 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | struct rpc_task *task) |
| 596 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 597 | struct nfs4_slot *slot; |
| 598 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 599 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 600 | |
| 601 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 603 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | return 0; |
| 605 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 606 | tbl = &session->fc_slot_table; |
| 607 | |
| 608 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 609 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 610 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 611 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 612 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 613 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 614 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 615 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 616 | } |
| 617 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 618 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 619 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 620 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 621 | spin_unlock(&tbl->slot_tbl_lock); |
| 622 | dprintk("%s enforce FIFO order\n", __func__); |
| 623 | return -EAGAIN; |
| 624 | } |
| 625 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 626 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 627 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 628 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 629 | spin_unlock(&tbl->slot_tbl_lock); |
| 630 | dprintk("<-- %s: no free slots\n", __func__); |
| 631 | return -EAGAIN; |
| 632 | } |
| 633 | spin_unlock(&tbl->slot_tbl_lock); |
| 634 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 635 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 636 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 637 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 638 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 639 | |
| 640 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 641 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 642 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 643 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 644 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 645 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 646 | /* |
| 647 | * sr_status is only set in decode_sequence, and so will remain |
| 648 | * set to 1 if an rpc level failure occurs. |
| 649 | */ |
| 650 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 651 | return 0; |
| 652 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 653 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 655 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 656 | struct nfs4_sequence_args *args, |
| 657 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 658 | struct rpc_task *task) |
| 659 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 660 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | int ret = 0; |
| 662 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 663 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 664 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 665 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 666 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 667 | __func__, session->clp, session, res->sr_slot ? |
| 668 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 669 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 670 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | out: |
| 672 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 673 | return ret; |
| 674 | } |
| 675 | |
| 676 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 677 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 678 | struct nfs4_sequence_args *seq_args; |
| 679 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 683 | { |
| 684 | struct nfs41_call_sync_data *data = calldata; |
| 685 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 687 | |
| 688 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 689 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 690 | return; |
| 691 | rpc_call_start(task); |
| 692 | } |
| 693 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 694 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 695 | { |
| 696 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 697 | nfs41_call_sync_prepare(task, calldata); |
| 698 | } |
| 699 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 700 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 701 | { |
| 702 | struct nfs41_call_sync_data *data = calldata; |
| 703 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 704 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 705 | } |
| 706 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 707 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 708 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 709 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 710 | }; |
| 711 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 712 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 713 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 714 | .rpc_call_done = nfs41_call_sync_done, |
| 715 | }; |
| 716 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 717 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 718 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 719 | struct rpc_message *msg, |
| 720 | struct nfs4_sequence_args *args, |
| 721 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 722 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 723 | { |
| 724 | int ret; |
| 725 | struct rpc_task *task; |
| 726 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 727 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 728 | .seq_args = args, |
| 729 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 730 | }; |
| 731 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 732 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 733 | .rpc_message = msg, |
| 734 | .callback_ops = &nfs41_call_sync_ops, |
| 735 | .callback_data = &data |
| 736 | }; |
| 737 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 738 | if (privileged) |
| 739 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 740 | task = rpc_run_task(&task_setup); |
| 741 | if (IS_ERR(task)) |
| 742 | ret = PTR_ERR(task); |
| 743 | else { |
| 744 | ret = task->tk_status; |
| 745 | rpc_put_task(task); |
| 746 | } |
| 747 | return ret; |
| 748 | } |
| 749 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 750 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 751 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 752 | struct rpc_message *msg, |
| 753 | struct nfs4_sequence_args *args, |
| 754 | struct nfs4_sequence_res *res, |
| 755 | int cache_reply) |
| 756 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 757 | nfs41_init_sequence(args, res, cache_reply); |
| 758 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 759 | } |
| 760 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 761 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 762 | static inline |
| 763 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 764 | struct nfs4_sequence_res *res, int cache_reply) |
| 765 | { |
| 766 | } |
| 767 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 768 | static int nfs4_sequence_done(struct rpc_task *task, |
| 769 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 770 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 771 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 772 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 773 | #endif /* CONFIG_NFS_V4_1 */ |
| 774 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 775 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 776 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 777 | struct rpc_message *msg, |
| 778 | struct nfs4_sequence_args *args, |
| 779 | struct nfs4_sequence_res *res, |
| 780 | int cache_reply) |
| 781 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 782 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 783 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 784 | } |
| 785 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 786 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 787 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 788 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 789 | struct rpc_message *msg, |
| 790 | struct nfs4_sequence_args *args, |
| 791 | struct nfs4_sequence_res *res, |
| 792 | int cache_reply) |
| 793 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 794 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 795 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 796 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 797 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 798 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 800 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 802 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 803 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 804 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 805 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 806 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 807 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 810 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 811 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | struct nfs_openargs o_arg; |
| 813 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 814 | struct nfs_open_confirmargs c_arg; |
| 815 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 816 | struct nfs4_string owner_name; |
| 817 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 820 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 822 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 824 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 825 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 826 | int rpc_status; |
| 827 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | }; |
| 829 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 830 | |
| 831 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 832 | { |
| 833 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 834 | p->o_res.seqid = p->o_arg.seqid; |
| 835 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 836 | p->o_res.server = p->o_arg.server; |
| 837 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 838 | 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] | 839 | } |
| 840 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 841 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 842 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 843 | const struct iattr *attrs, |
| 844 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 845 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 846 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | struct inode *dir = parent->d_inode; |
| 848 | struct nfs_server *server = NFS_SERVER(dir); |
| 849 | struct nfs4_opendata *p; |
| 850 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 851 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | if (p == NULL) |
| 853 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 854 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | if (p->o_arg.seqid == NULL) |
| 856 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 857 | nfs_sb_active(dentry->d_sb); |
| 858 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 859 | p->dir = parent; |
| 860 | p->owner = sp; |
| 861 | atomic_inc(&sp->so_count); |
| 862 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 863 | p->o_arg.open_flags = flags; |
| 864 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 865 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 866 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 867 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 868 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 869 | p->o_arg.server = server; |
| 870 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 871 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 872 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 873 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 874 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 875 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 876 | p->o_arg.u.attrs = &p->attrs; |
| 877 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 878 | |
| 879 | verf[0] = jiffies; |
| 880 | verf[1] = current->pid; |
| 881 | memcpy(p->o_arg.u.verifier.data, verf, |
| 882 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 883 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 884 | p->c_arg.fh = &p->o_res.fh; |
| 885 | p->c_arg.stateid = &p->o_res.stateid; |
| 886 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 887 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 888 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 889 | return p; |
| 890 | err_free: |
| 891 | kfree(p); |
| 892 | err: |
| 893 | dput(parent); |
| 894 | return NULL; |
| 895 | } |
| 896 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 897 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 898 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 899 | struct nfs4_opendata *p = container_of(kref, |
| 900 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 901 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 902 | |
| 903 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 904 | if (p->state != NULL) |
| 905 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 906 | nfs4_put_state_owner(p->owner); |
| 907 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 908 | dput(p->dentry); |
| 909 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 910 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 911 | kfree(p); |
| 912 | } |
| 913 | |
| 914 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 915 | { |
| 916 | if (p != NULL) |
| 917 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 920 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 921 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 922 | int ret; |
| 923 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 924 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 925 | return ret; |
| 926 | } |
| 927 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | 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] | 929 | { |
| 930 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 931 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 932 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 933 | goto out; |
| 934 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 935 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 936 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 937 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 938 | break; |
| 939 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 940 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 941 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 942 | break; |
| 943 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 944 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 945 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 946 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 948 | return ret; |
| 949 | } |
| 950 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 952 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 953 | if (delegation == NULL) |
| 954 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 956 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 957 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 958 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 959 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 960 | return 1; |
| 961 | } |
| 962 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 964 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 966 | case FMODE_WRITE: |
| 967 | state->n_wronly++; |
| 968 | break; |
| 969 | case FMODE_READ: |
| 970 | state->n_rdonly++; |
| 971 | break; |
| 972 | case FMODE_READ|FMODE_WRITE: |
| 973 | state->n_rdwr++; |
| 974 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 975 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | 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] | 979 | { |
| 980 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 981 | nfs4_stateid_copy(&state->stateid, stateid); |
| 982 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 983 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 984 | case FMODE_READ: |
| 985 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 986 | break; |
| 987 | case FMODE_WRITE: |
| 988 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 989 | break; |
| 990 | case FMODE_READ|FMODE_WRITE: |
| 991 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 992 | } |
| 993 | } |
| 994 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 995 | 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] | 996 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 997 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 999 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1002 | 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] | 1003 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1004 | /* |
| 1005 | * Protect the call to nfs4_state_set_mode_locked and |
| 1006 | * serialise the stateid update |
| 1007 | */ |
| 1008 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1009 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1010 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1011 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1012 | } |
| 1013 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1014 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1015 | write_sequnlock(&state->seqlock); |
| 1016 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1018 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1021 | 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] | 1022 | { |
| 1023 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1024 | struct nfs_delegation *deleg_cur; |
| 1025 | int ret = 0; |
| 1026 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1027 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1028 | |
| 1029 | rcu_read_lock(); |
| 1030 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1031 | if (deleg_cur == NULL) |
| 1032 | goto no_delegation; |
| 1033 | |
| 1034 | spin_lock(&deleg_cur->lock); |
| 1035 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1037 | goto no_delegation_unlock; |
| 1038 | |
| 1039 | if (delegation == NULL) |
| 1040 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1041 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1042 | goto no_delegation_unlock; |
| 1043 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1044 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1046 | ret = 1; |
| 1047 | no_delegation_unlock: |
| 1048 | spin_unlock(&deleg_cur->lock); |
| 1049 | no_delegation: |
| 1050 | rcu_read_unlock(); |
| 1051 | |
| 1052 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | ret = 1; |
| 1055 | } |
| 1056 | |
| 1057 | return ret; |
| 1058 | } |
| 1059 | |
| 1060 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1062 | { |
| 1063 | struct nfs_delegation *delegation; |
| 1064 | |
| 1065 | rcu_read_lock(); |
| 1066 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1067 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1068 | rcu_read_unlock(); |
| 1069 | return; |
| 1070 | } |
| 1071 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1072 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1075 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | { |
| 1077 | struct nfs4_state *state = opendata->state; |
| 1078 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1079 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1080 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1081 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1082 | nfs4_stateid stateid; |
| 1083 | int ret = -EAGAIN; |
| 1084 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1086 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1087 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1088 | if (can_open_cached(state, fmode, open_mode)) { |
| 1089 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1091 | goto out_return_state; |
| 1092 | } |
| 1093 | spin_unlock(&state->owner->so_lock); |
| 1094 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1095 | rcu_read_lock(); |
| 1096 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1097 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1098 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1099 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1100 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1101 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1102 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1103 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1104 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1105 | if (ret != 0) |
| 1106 | goto out; |
| 1107 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1108 | |
| 1109 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1111 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1112 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1113 | out: |
| 1114 | return ERR_PTR(ret); |
| 1115 | out_return_state: |
| 1116 | atomic_inc(&state->count); |
| 1117 | return state; |
| 1118 | } |
| 1119 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1120 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1121 | { |
| 1122 | struct inode *inode; |
| 1123 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1124 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1125 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1126 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1127 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1128 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1129 | goto out; |
| 1130 | } |
| 1131 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1132 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1133 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1134 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1135 | 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] | 1136 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1137 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1138 | goto err; |
| 1139 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1140 | state = nfs4_get_open_state(inode, data->owner); |
| 1141 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1142 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1143 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1144 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1145 | int delegation_flags = 0; |
| 1146 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1147 | rcu_read_lock(); |
| 1148 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1149 | if (delegation) |
| 1150 | delegation_flags = delegation->flags; |
| 1151 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1152 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1153 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1154 | "returning a delegation for " |
| 1155 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1156 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1157 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1158 | nfs_inode_set_delegation(state->inode, |
| 1159 | data->owner->so_cred, |
| 1160 | &data->o_res); |
| 1161 | else |
| 1162 | nfs_inode_reclaim_delegation(state->inode, |
| 1163 | data->owner->so_cred, |
| 1164 | &data->o_res); |
| 1165 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1166 | |
| 1167 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1168 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1169 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1170 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1171 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1172 | err_put_inode: |
| 1173 | iput(inode); |
| 1174 | err: |
| 1175 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1178 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1179 | { |
| 1180 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1181 | struct nfs_open_context *ctx; |
| 1182 | |
| 1183 | spin_lock(&state->inode->i_lock); |
| 1184 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1185 | if (ctx->state != state) |
| 1186 | continue; |
| 1187 | get_nfs_open_context(ctx); |
| 1188 | spin_unlock(&state->inode->i_lock); |
| 1189 | return ctx; |
| 1190 | } |
| 1191 | spin_unlock(&state->inode->i_lock); |
| 1192 | return ERR_PTR(-ENOENT); |
| 1193 | } |
| 1194 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1195 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1196 | { |
| 1197 | struct nfs4_opendata *opendata; |
| 1198 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1199 | 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] | 1200 | if (opendata == NULL) |
| 1201 | return ERR_PTR(-ENOMEM); |
| 1202 | opendata->state = state; |
| 1203 | atomic_inc(&state->count); |
| 1204 | return opendata; |
| 1205 | } |
| 1206 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1207 | 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] | 1208 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1209 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | int ret; |
| 1211 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1212 | opendata->o_arg.open_flags = 0; |
| 1213 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1214 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1215 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1216 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1217 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | if (ret != 0) |
| 1219 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1220 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1221 | if (IS_ERR(newstate)) |
| 1222 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1223 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1224 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1225 | return 0; |
| 1226 | } |
| 1227 | |
| 1228 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1229 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1230 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1231 | int ret; |
| 1232 | |
| 1233 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1234 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1235 | smp_rmb(); |
| 1236 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1237 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1238 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | if (ret != 0) |
| 1240 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1241 | if (newstate != state) |
| 1242 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1243 | } |
| 1244 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1245 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1246 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1247 | if (ret != 0) |
| 1248 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1249 | if (newstate != state) |
| 1250 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | } |
| 1252 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1253 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1254 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1255 | if (ret != 0) |
| 1256 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1257 | if (newstate != state) |
| 1258 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1259 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1260 | /* |
| 1261 | * We may have performed cached opens for all three recoveries. |
| 1262 | * Check if we need to update the current stateid. |
| 1263 | */ |
| 1264 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1265 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1266 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1267 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1268 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1269 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1270 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1271 | return 0; |
| 1272 | } |
| 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | /* |
| 1275 | * OPEN_RECLAIM: |
| 1276 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1278 | 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] | 1279 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1280 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1281 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1282 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | int status; |
| 1284 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1285 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1286 | if (IS_ERR(opendata)) |
| 1287 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1288 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1289 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1290 | rcu_read_lock(); |
| 1291 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1292 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1293 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1294 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1295 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1296 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1297 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | return status; |
| 1299 | } |
| 1300 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1301 | 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] | 1302 | { |
| 1303 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1304 | struct nfs4_exception exception = { }; |
| 1305 | int err; |
| 1306 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1307 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1308 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1309 | break; |
| 1310 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | } while (exception.retry); |
| 1312 | return err; |
| 1313 | } |
| 1314 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1315 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1316 | { |
| 1317 | struct nfs_open_context *ctx; |
| 1318 | int ret; |
| 1319 | |
| 1320 | ctx = nfs4_state_find_open_context(state); |
| 1321 | if (IS_ERR(ctx)) |
| 1322 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1323 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1324 | put_nfs_open_context(ctx); |
| 1325 | return ret; |
| 1326 | } |
| 1327 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1328 | 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] | 1329 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1330 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1331 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1333 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1334 | if (IS_ERR(opendata)) |
| 1335 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1336 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1337 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1338 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1339 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1340 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1343 | 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] | 1344 | { |
| 1345 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1346 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | int err; |
| 1348 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1349 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | switch (err) { |
| 1351 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1352 | case -ENOENT: |
| 1353 | case -ESTALE: |
| 1354 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1355 | case -NFS4ERR_BADSESSION: |
| 1356 | case -NFS4ERR_BADSLOT: |
| 1357 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1358 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1359 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1360 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1361 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | case -NFS4ERR_STALE_CLIENTID: |
| 1363 | case -NFS4ERR_STALE_STATEID: |
| 1364 | case -NFS4ERR_EXPIRED: |
| 1365 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1366 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1367 | goto out; |
| 1368 | case -ERESTARTSYS: |
| 1369 | /* |
| 1370 | * The show must go on: exit, but mark the |
| 1371 | * stateid as needing recovery. |
| 1372 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1373 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1374 | case -NFS4ERR_ADMIN_REVOKED: |
| 1375 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1376 | nfs_inode_find_state_and_recover(state->inode, |
| 1377 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1378 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1379 | case -EKEYEXPIRED: |
| 1380 | /* |
| 1381 | * User RPCSEC_GSS context has expired. |
| 1382 | * We cannot recover this stateid now, so |
| 1383 | * skip it and allow recovery thread to |
| 1384 | * proceed. |
| 1385 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1386 | case -ENOMEM: |
| 1387 | err = 0; |
| 1388 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } |
| 1390 | err = nfs4_handle_exception(server, err, &exception); |
| 1391 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1392 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | return err; |
| 1394 | } |
| 1395 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1396 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1397 | { |
| 1398 | struct nfs4_opendata *data = calldata; |
| 1399 | |
| 1400 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1401 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1402 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1403 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1404 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1405 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1406 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | static void nfs4_open_confirm_release(void *calldata) |
| 1410 | { |
| 1411 | struct nfs4_opendata *data = calldata; |
| 1412 | struct nfs4_state *state = NULL; |
| 1413 | |
| 1414 | /* If this request hasn't been cancelled, do nothing */ |
| 1415 | if (data->cancelled == 0) |
| 1416 | goto out_free; |
| 1417 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1418 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1419 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1420 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1421 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1422 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1423 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1424 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1428 | .rpc_call_done = nfs4_open_confirm_done, |
| 1429 | .rpc_release = nfs4_open_confirm_release, |
| 1430 | }; |
| 1431 | |
| 1432 | /* |
| 1433 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1434 | */ |
| 1435 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1436 | { |
| 1437 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1438 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1439 | struct rpc_message msg = { |
| 1440 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1441 | .rpc_argp = &data->c_arg, |
| 1442 | .rpc_resp = &data->c_res, |
| 1443 | .rpc_cred = data->owner->so_cred, |
| 1444 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1445 | struct rpc_task_setup task_setup_data = { |
| 1446 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1447 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1448 | .callback_ops = &nfs4_open_confirm_ops, |
| 1449 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1450 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1451 | .flags = RPC_TASK_ASYNC, |
| 1452 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | int status; |
| 1454 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1455 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1456 | data->rpc_done = 0; |
| 1457 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1458 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1459 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1460 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1461 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1462 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1463 | if (status != 0) { |
| 1464 | data->cancelled = 1; |
| 1465 | smp_wmb(); |
| 1466 | } else |
| 1467 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1468 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | return status; |
| 1470 | } |
| 1471 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1472 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1474 | struct nfs4_opendata *data = calldata; |
| 1475 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1476 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1477 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1478 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1479 | /* |
| 1480 | * Check if we still need to send an OPEN call, or if we can use |
| 1481 | * a delegation instead. |
| 1482 | */ |
| 1483 | if (data->state != NULL) { |
| 1484 | struct nfs_delegation *delegation; |
| 1485 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1486 | 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] | 1487 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1488 | rcu_read_lock(); |
| 1489 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1490 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1491 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1492 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1493 | rcu_read_unlock(); |
| 1494 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1495 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1496 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1497 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1498 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1499 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1500 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1501 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1502 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1503 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1504 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1505 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1506 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1507 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1508 | unlock_no_action: |
| 1509 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1510 | out_no_action: |
| 1511 | task->tk_action = NULL; |
| 1512 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1515 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1516 | { |
| 1517 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1518 | nfs4_open_prepare(task, calldata); |
| 1519 | } |
| 1520 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1522 | { |
| 1523 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1525 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1526 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1527 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1528 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1529 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1530 | if (task->tk_status == 0) { |
| 1531 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1532 | case S_IFREG: |
| 1533 | break; |
| 1534 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1535 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1536 | break; |
| 1537 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1538 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1539 | break; |
| 1540 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1541 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1542 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1543 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1544 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1545 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1546 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1547 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1548 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1549 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1550 | static void nfs4_open_release(void *calldata) |
| 1551 | { |
| 1552 | struct nfs4_opendata *data = calldata; |
| 1553 | struct nfs4_state *state = NULL; |
| 1554 | |
| 1555 | /* If this request hasn't been cancelled, do nothing */ |
| 1556 | if (data->cancelled == 0) |
| 1557 | goto out_free; |
| 1558 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1559 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1560 | goto out_free; |
| 1561 | /* In case we need an open_confirm, no cleanup! */ |
| 1562 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1563 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1564 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1565 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1566 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1567 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1568 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1572 | .rpc_call_prepare = nfs4_open_prepare, |
| 1573 | .rpc_call_done = nfs4_open_done, |
| 1574 | .rpc_release = nfs4_open_release, |
| 1575 | }; |
| 1576 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1577 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1578 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1579 | .rpc_call_done = nfs4_open_done, |
| 1580 | .rpc_release = nfs4_open_release, |
| 1581 | }; |
| 1582 | |
| 1583 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1584 | { |
| 1585 | struct inode *dir = data->dir->d_inode; |
| 1586 | struct nfs_server *server = NFS_SERVER(dir); |
| 1587 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1588 | struct nfs_openres *o_res = &data->o_res; |
| 1589 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1590 | struct rpc_message msg = { |
| 1591 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1592 | .rpc_argp = o_arg, |
| 1593 | .rpc_resp = o_res, |
| 1594 | .rpc_cred = data->owner->so_cred, |
| 1595 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1596 | struct rpc_task_setup task_setup_data = { |
| 1597 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1598 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1599 | .callback_ops = &nfs4_open_ops, |
| 1600 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1601 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1602 | .flags = RPC_TASK_ASYNC, |
| 1603 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1604 | int status; |
| 1605 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1606 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1607 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1608 | data->rpc_done = 0; |
| 1609 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1610 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1611 | if (isrecover) |
| 1612 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1613 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1614 | if (IS_ERR(task)) |
| 1615 | return PTR_ERR(task); |
| 1616 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1617 | if (status != 0) { |
| 1618 | data->cancelled = 1; |
| 1619 | smp_wmb(); |
| 1620 | } else |
| 1621 | status = data->rpc_status; |
| 1622 | rpc_put_task(task); |
| 1623 | |
| 1624 | return status; |
| 1625 | } |
| 1626 | |
| 1627 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1628 | { |
| 1629 | struct inode *dir = data->dir->d_inode; |
| 1630 | struct nfs_openres *o_res = &data->o_res; |
| 1631 | int status; |
| 1632 | |
| 1633 | status = nfs4_run_open_task(data, 1); |
| 1634 | if (status != 0 || !data->rpc_done) |
| 1635 | return status; |
| 1636 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1637 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1638 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1639 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1640 | status = _nfs4_proc_open_confirm(data); |
| 1641 | if (status != 0) |
| 1642 | return status; |
| 1643 | } |
| 1644 | |
| 1645 | return status; |
| 1646 | } |
| 1647 | |
| 1648 | /* |
| 1649 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1650 | */ |
| 1651 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1652 | { |
| 1653 | struct inode *dir = data->dir->d_inode; |
| 1654 | struct nfs_server *server = NFS_SERVER(dir); |
| 1655 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1656 | struct nfs_openres *o_res = &data->o_res; |
| 1657 | int status; |
| 1658 | |
| 1659 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1660 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1661 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1662 | if (status != 0) { |
| 1663 | if (status == -NFS4ERR_BADNAME && |
| 1664 | !(o_arg->open_flags & O_CREAT)) |
| 1665 | return -ENOENT; |
| 1666 | return status; |
| 1667 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1668 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1669 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1670 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1671 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1672 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1673 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1674 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1676 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | } |
| 1680 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1681 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1682 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1685 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1686 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1687 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1688 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1689 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1690 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1691 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1692 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1693 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1694 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1695 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1696 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1697 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1698 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1699 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1700 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1703 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1704 | { |
| 1705 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1706 | } |
| 1707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | /* |
| 1709 | * OPEN_EXPIRED: |
| 1710 | * reclaim state on the server after a network partition. |
| 1711 | * Assumes caller holds the appropriate lock |
| 1712 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1713 | static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1715 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1716 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1718 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1719 | if (IS_ERR(opendata)) |
| 1720 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1721 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1722 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1723 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1724 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1725 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1728 | static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1729 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1730 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1731 | struct nfs4_exception exception = { }; |
| 1732 | int err; |
| 1733 | |
| 1734 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1735 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1736 | switch (err) { |
| 1737 | default: |
| 1738 | goto out; |
| 1739 | case -NFS4ERR_GRACE: |
| 1740 | case -NFS4ERR_DELAY: |
| 1741 | nfs4_handle_exception(server, err, &exception); |
| 1742 | err = 0; |
| 1743 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1744 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1745 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1746 | return err; |
| 1747 | } |
| 1748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1750 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1752 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1754 | ctx = nfs4_state_find_open_context(state); |
| 1755 | if (IS_ERR(ctx)) |
| 1756 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1757 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1758 | put_nfs_open_context(ctx); |
| 1759 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1762 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1763 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1764 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1765 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1766 | nfs4_stateid *stateid = &state->stateid; |
| 1767 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1768 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1769 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1770 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1771 | return; |
| 1772 | |
| 1773 | status = nfs41_test_stateid(server, stateid); |
| 1774 | if (status != NFS_OK) { |
| 1775 | /* Free the stateid unless the server explicitly |
| 1776 | * informs us the stateid is unrecognized. */ |
| 1777 | if (status != -NFS4ERR_BAD_STATEID) |
| 1778 | nfs41_free_stateid(server, stateid); |
| 1779 | |
| 1780 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | /** |
| 1785 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1786 | * |
| 1787 | * @state: NFSv4 state for an inode |
| 1788 | * |
| 1789 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1790 | * Otherwise a negative NFS4ERR value is returned. |
| 1791 | */ |
| 1792 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1793 | { |
| 1794 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1795 | nfs4_stateid *stateid = &state->stateid; |
| 1796 | int status; |
| 1797 | |
| 1798 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1799 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1800 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1801 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1802 | return -NFS4ERR_BAD_STATEID; |
| 1803 | |
| 1804 | status = nfs41_test_stateid(server, stateid); |
| 1805 | if (status != NFS_OK) { |
| 1806 | /* Free the stateid unless the server explicitly |
| 1807 | * informs us the stateid is unrecognized. */ |
| 1808 | if (status != -NFS4ERR_BAD_STATEID) |
| 1809 | nfs41_free_stateid(server, stateid); |
| 1810 | |
| 1811 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1812 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1813 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1814 | } |
| 1815 | return status; |
| 1816 | } |
| 1817 | |
| 1818 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1819 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1820 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1821 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1822 | nfs41_clear_delegation_stateid(state); |
| 1823 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1824 | if (status != NFS_OK) |
| 1825 | status = nfs4_open_expired(sp, state); |
| 1826 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1827 | } |
| 1828 | #endif |
| 1829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1831 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1832 | * fields corresponding to attributes that were used to store the verifier. |
| 1833 | * Make sure we clobber those fields in the later setattr call |
| 1834 | */ |
| 1835 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1836 | { |
| 1837 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1838 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1839 | sattr->ia_valid |= ATTR_ATIME; |
| 1840 | |
| 1841 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1842 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1843 | sattr->ia_valid |= ATTR_MTIME; |
| 1844 | } |
| 1845 | |
| 1846 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1847 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1849 | static int _nfs4_do_open(struct inode *dir, |
| 1850 | struct dentry *dentry, |
| 1851 | fmode_t fmode, |
| 1852 | int flags, |
| 1853 | struct iattr *sattr, |
| 1854 | struct rpc_cred *cred, |
| 1855 | struct nfs4_state **res, |
| 1856 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | { |
| 1858 | struct nfs4_state_owner *sp; |
| 1859 | struct nfs4_state *state = NULL; |
| 1860 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1861 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1862 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | |
| 1864 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1866 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1867 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1869 | goto out_err; |
| 1870 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1871 | status = nfs4_recover_expired_lease(server); |
| 1872 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1873 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1874 | if (dentry->d_inode != NULL) |
| 1875 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1876 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1877 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1878 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1879 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1881 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1882 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1883 | if (!opendata->f_attr.mdsthreshold) |
| 1884 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1885 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1886 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1887 | if (dentry->d_inode != NULL) |
| 1888 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1889 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1890 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1892 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1894 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1895 | status = PTR_ERR(state); |
| 1896 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1897 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1898 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1899 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1900 | |
| 1901 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1902 | nfs4_exclusive_attrset(opendata, sattr); |
| 1903 | |
| 1904 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1905 | status = nfs4_do_setattr(state->inode, cred, |
| 1906 | opendata->o_res.f_attr, sattr, |
| 1907 | state); |
| 1908 | if (status == 0) |
| 1909 | nfs_setattr_update_inode(state->inode, sattr); |
| 1910 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1911 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1912 | |
| 1913 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1914 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1915 | else |
| 1916 | kfree(opendata->f_attr.mdsthreshold); |
| 1917 | opendata->f_attr.mdsthreshold = NULL; |
| 1918 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1919 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | *res = state; |
| 1922 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1923 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1924 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1925 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1926 | err_put_state_owner: |
| 1927 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | *res = NULL; |
| 1930 | return status; |
| 1931 | } |
| 1932 | |
| 1933 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1934 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1935 | struct dentry *dentry, |
| 1936 | fmode_t fmode, |
| 1937 | int flags, |
| 1938 | struct iattr *sattr, |
| 1939 | struct rpc_cred *cred, |
| 1940 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | { |
| 1942 | struct nfs4_exception exception = { }; |
| 1943 | struct nfs4_state *res; |
| 1944 | int status; |
| 1945 | |
Trond Myklebust | 2d0dbc6 | 2012-06-08 10:58:09 -0400 | [diff] [blame] | 1946 | fmode &= FMODE_READ|FMODE_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1948 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1949 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | if (status == 0) |
| 1951 | break; |
| 1952 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1953 | * book-keeping w.r.t. state-changing operations |
| 1954 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1955 | * It is actually a sign of a bug on the client or on the server. |
| 1956 | * |
| 1957 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1958 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | * have unhashed the old state_owner for us, and that we can |
| 1960 | * therefore safely retry using a new one. We should still warn |
| 1961 | * the user though... |
| 1962 | */ |
| 1963 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1964 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1965 | " returned a bad sequence-id error!\n", |
| 1966 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | exception.retry = 1; |
| 1968 | continue; |
| 1969 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1970 | /* |
| 1971 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1972 | * state before it received the OPEN_CONFIRM. |
| 1973 | * Recover by retrying the request as per the discussion |
| 1974 | * on Page 181 of RFC3530. |
| 1975 | */ |
| 1976 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1977 | exception.retry = 1; |
| 1978 | continue; |
| 1979 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1980 | if (status == -EAGAIN) { |
| 1981 | /* We must have found a delegation */ |
| 1982 | exception.retry = 1; |
| 1983 | continue; |
| 1984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1986 | status, &exception)); |
| 1987 | } while (exception.retry); |
| 1988 | return res; |
| 1989 | } |
| 1990 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1991 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1992 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1993 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1995 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1997 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | .iap = sattr, |
| 1999 | .server = server, |
| 2000 | .bitmask = server->attr_bitmask, |
| 2001 | }; |
| 2002 | struct nfs_setattrres res = { |
| 2003 | .fattr = fattr, |
| 2004 | .server = server, |
| 2005 | }; |
| 2006 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2008 | .rpc_argp = &arg, |
| 2009 | .rpc_resp = &res, |
| 2010 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2012 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2013 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2015 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2017 | if (state != NULL) { |
| 2018 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 2019 | current->files, current->tgid); |
| 2020 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2021 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2022 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2023 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2024 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2026 | 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] | 2027 | if (status == 0 && state != NULL) |
| 2028 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2029 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2032 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2033 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2034 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2036 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2037 | struct nfs4_exception exception = { |
| 2038 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2039 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2040 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | int err; |
| 2042 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2043 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2044 | switch (err) { |
| 2045 | case -NFS4ERR_OPENMODE: |
| 2046 | if (state && !(state->state & FMODE_WRITE)) { |
| 2047 | err = -EBADF; |
| 2048 | if (sattr->ia_valid & ATTR_OPEN) |
| 2049 | err = -EACCES; |
| 2050 | goto out; |
| 2051 | } |
| 2052 | } |
| 2053 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2055 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | return err; |
| 2057 | } |
| 2058 | |
| 2059 | struct nfs4_closedata { |
| 2060 | struct inode *inode; |
| 2061 | struct nfs4_state *state; |
| 2062 | struct nfs_closeargs arg; |
| 2063 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2064 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2065 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2066 | bool roc; |
| 2067 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | }; |
| 2069 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2070 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2071 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2072 | struct nfs4_closedata *calldata = data; |
| 2073 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2074 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2075 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2076 | if (calldata->roc) |
| 2077 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2078 | nfs4_put_open_state(calldata->state); |
| 2079 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2080 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2081 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2082 | kfree(calldata); |
| 2083 | } |
| 2084 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2085 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2086 | fmode_t fmode) |
| 2087 | { |
| 2088 | spin_lock(&state->owner->so_lock); |
| 2089 | if (!(fmode & FMODE_READ)) |
| 2090 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2091 | if (!(fmode & FMODE_WRITE)) |
| 2092 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2093 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2094 | spin_unlock(&state->owner->so_lock); |
| 2095 | } |
| 2096 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2097 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2099 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2102 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2103 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2104 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2105 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | /* hmm. we are done with the inode, and in the process of freeing |
| 2107 | * the state_owner. we keep this around to process errors |
| 2108 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | switch (task->tk_status) { |
| 2110 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2111 | if (calldata->roc) |
| 2112 | pnfs_roc_set_barrier(state->inode, |
| 2113 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2114 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2115 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2116 | nfs4_close_clear_stateid_flags(state, |
| 2117 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | break; |
| 2119 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2120 | case -NFS4ERR_OLD_STATEID: |
| 2121 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2123 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2124 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2126 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2127 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2129 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2130 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2131 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2134 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2136 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2137 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2138 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2139 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2140 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2141 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2142 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2143 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2144 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2145 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2146 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2147 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2148 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2149 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2150 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2151 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2152 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2153 | } |
| 2154 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2155 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2156 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2157 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2158 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2159 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2160 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2161 | |
| 2162 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2163 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2164 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2165 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2166 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2167 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2168 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2169 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2170 | if (calldata->roc && |
| 2171 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2172 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2173 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2174 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2175 | } |
| 2176 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2177 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2178 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2179 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2180 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2181 | &calldata->arg.seq_args, |
| 2182 | &calldata->res.seq_res, |
| 2183 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2184 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2185 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2186 | out: |
| 2187 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2190 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2191 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2192 | .rpc_call_done = nfs4_close_done, |
| 2193 | .rpc_release = nfs4_free_closedata, |
| 2194 | }; |
| 2195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | /* |
| 2197 | * It is possible for data to be read/written from a mem-mapped file |
| 2198 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2199 | * This means that we can't safely call nfsv4 close on a file until |
| 2200 | * the inode is cleared. This in turn means that we are not good |
| 2201 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2202 | * share state even when we are done with one of the three share |
| 2203 | * stateid's in the inode. |
| 2204 | * |
| 2205 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2206 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2207 | 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] | 2208 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2209 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2211 | struct nfs4_state_owner *sp = state->owner; |
| 2212 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2213 | struct rpc_message msg = { |
| 2214 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2215 | .rpc_cred = state->owner->so_cred, |
| 2216 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2217 | struct rpc_task_setup task_setup_data = { |
| 2218 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2219 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2220 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2221 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2222 | .flags = RPC_TASK_ASYNC, |
| 2223 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2224 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2226 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2228 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2229 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2230 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2232 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2233 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2235 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2236 | if (calldata->arg.seqid == NULL) |
| 2237 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2238 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2239 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2240 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2241 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2242 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2243 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2244 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2245 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2246 | msg.rpc_argp = &calldata->arg; |
| 2247 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2248 | task_setup_data.callback_data = calldata; |
| 2249 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2250 | if (IS_ERR(task)) |
| 2251 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2252 | status = 0; |
| 2253 | if (wait) |
| 2254 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2255 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2256 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2257 | out_free_calldata: |
| 2258 | kfree(calldata); |
| 2259 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2260 | if (roc) |
| 2261 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2262 | nfs4_put_open_state(state); |
| 2263 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2264 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2267 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2268 | 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] | 2269 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | struct nfs4_state *state; |
| 2271 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2272 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2273 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2274 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2275 | if (IS_ERR(state)) |
| 2276 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2277 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2278 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2281 | 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] | 2282 | { |
| 2283 | if (ctx->state == NULL) |
| 2284 | return; |
| 2285 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2286 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2287 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2288 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2289 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | |
| 2291 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2292 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2293 | struct nfs4_server_caps_arg args = { |
| 2294 | .fhandle = fhandle, |
| 2295 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | struct nfs4_server_caps_res res = {}; |
| 2297 | struct rpc_message msg = { |
| 2298 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2299 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | .rpc_resp = &res, |
| 2301 | }; |
| 2302 | int status; |
| 2303 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2304 | 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] | 2305 | if (status == 0) { |
| 2306 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2307 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2308 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2309 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2310 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2311 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2313 | server->caps |= NFS_CAP_ACLS; |
| 2314 | if (res.has_links != 0) |
| 2315 | server->caps |= NFS_CAP_HARDLINKS; |
| 2316 | if (res.has_symlinks != 0) |
| 2317 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2318 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2319 | server->caps |= NFS_CAP_FILEID; |
| 2320 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2321 | server->caps |= NFS_CAP_MODE; |
| 2322 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2323 | server->caps |= NFS_CAP_NLINK; |
| 2324 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2325 | server->caps |= NFS_CAP_OWNER; |
| 2326 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2327 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2328 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2329 | server->caps |= NFS_CAP_ATIME; |
| 2330 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2331 | server->caps |= NFS_CAP_CTIME; |
| 2332 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2333 | server->caps |= NFS_CAP_MTIME; |
| 2334 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2335 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2336 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2337 | 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] | 2338 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2339 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | return status; |
| 2343 | } |
| 2344 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2345 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | { |
| 2347 | struct nfs4_exception exception = { }; |
| 2348 | int err; |
| 2349 | do { |
| 2350 | err = nfs4_handle_exception(server, |
| 2351 | _nfs4_server_capabilities(server, fhandle), |
| 2352 | &exception); |
| 2353 | } while (exception.retry); |
| 2354 | return err; |
| 2355 | } |
| 2356 | |
| 2357 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2358 | struct nfs_fsinfo *info) |
| 2359 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | struct nfs4_lookup_root_arg args = { |
| 2361 | .bitmask = nfs4_fattr_bitmap, |
| 2362 | }; |
| 2363 | struct nfs4_lookup_res res = { |
| 2364 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2365 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | .fh = fhandle, |
| 2367 | }; |
| 2368 | struct rpc_message msg = { |
| 2369 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2370 | .rpc_argp = &args, |
| 2371 | .rpc_resp = &res, |
| 2372 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2373 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2374 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2375 | 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] | 2376 | } |
| 2377 | |
| 2378 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2379 | struct nfs_fsinfo *info) |
| 2380 | { |
| 2381 | struct nfs4_exception exception = { }; |
| 2382 | int err; |
| 2383 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2384 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2385 | switch (err) { |
| 2386 | case 0: |
| 2387 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2388 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2389 | default: |
| 2390 | err = nfs4_handle_exception(server, err, &exception); |
| 2391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2393 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | return err; |
| 2395 | } |
| 2396 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2397 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2398 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2399 | { |
| 2400 | struct rpc_auth *auth; |
| 2401 | int ret; |
| 2402 | |
| 2403 | auth = rpcauth_create(flavor, server->client); |
| 2404 | if (!auth) { |
| 2405 | ret = -EIO; |
| 2406 | goto out; |
| 2407 | } |
| 2408 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2409 | out: |
| 2410 | return ret; |
| 2411 | } |
| 2412 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2413 | 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] | 2414 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2416 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2417 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2419 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
| 2420 | BUG_ON(len < 0); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2421 | |
| 2422 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2423 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2424 | * thus has already been tried. */ |
| 2425 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2426 | continue; |
| 2427 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2428 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2429 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2430 | continue; |
| 2431 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2432 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2433 | /* |
| 2434 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2435 | * to access the mount. It could also mean that we tried to mount |
| 2436 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2437 | * existing mount programs don't handle -EACCES very well so it should |
| 2438 | * be mapped to -EPERM instead. |
| 2439 | */ |
| 2440 | if (status == -EACCES) |
| 2441 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2442 | return status; |
| 2443 | } |
| 2444 | |
| 2445 | /* |
| 2446 | * get the file handle for the "/" directory on the server |
| 2447 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2448 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2449 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2450 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2451 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2452 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2453 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2454 | /* |
| 2455 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2456 | * by nfs4_map_errors() as this function exits. |
| 2457 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2458 | 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] | 2459 | if (status == 0) |
| 2460 | status = nfs4_server_capabilities(server, fhandle); |
| 2461 | if (status == 0) |
| 2462 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2463 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2466 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2467 | struct nfs_fsinfo *info) |
| 2468 | { |
| 2469 | int error; |
| 2470 | struct nfs_fattr *fattr = info->fattr; |
| 2471 | |
| 2472 | error = nfs4_server_capabilities(server, mntfh); |
| 2473 | if (error < 0) { |
| 2474 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2475 | return error; |
| 2476 | } |
| 2477 | |
| 2478 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2479 | if (error < 0) { |
| 2480 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2481 | return error; |
| 2482 | } |
| 2483 | |
| 2484 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2485 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2486 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2487 | |
| 2488 | return error; |
| 2489 | } |
| 2490 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2491 | /* |
| 2492 | * Get locations and (maybe) other attributes of a referral. |
| 2493 | * Note that we'll actually follow the referral later when |
| 2494 | * we detect fsid mismatch in inode revalidation |
| 2495 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2496 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2497 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2498 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2499 | { |
| 2500 | int status = -ENOMEM; |
| 2501 | struct page *page = NULL; |
| 2502 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2503 | |
| 2504 | page = alloc_page(GFP_KERNEL); |
| 2505 | if (page == NULL) |
| 2506 | goto out; |
| 2507 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2508 | if (locations == NULL) |
| 2509 | goto out; |
| 2510 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2511 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2512 | if (status != 0) |
| 2513 | goto out; |
| 2514 | /* Make sure server returned a different fsid for the referral */ |
| 2515 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2516 | dprintk("%s: server did not return a different fsid for" |
| 2517 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2518 | status = -EIO; |
| 2519 | goto out; |
| 2520 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2521 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2522 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2523 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2524 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2525 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2526 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2527 | out: |
| 2528 | if (page) |
| 2529 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2530 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2531 | return status; |
| 2532 | } |
| 2533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2535 | { |
| 2536 | struct nfs4_getattr_arg args = { |
| 2537 | .fh = fhandle, |
| 2538 | .bitmask = server->attr_bitmask, |
| 2539 | }; |
| 2540 | struct nfs4_getattr_res res = { |
| 2541 | .fattr = fattr, |
| 2542 | .server = server, |
| 2543 | }; |
| 2544 | struct rpc_message msg = { |
| 2545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2546 | .rpc_argp = &args, |
| 2547 | .rpc_resp = &res, |
| 2548 | }; |
| 2549 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2550 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2551 | 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] | 2552 | } |
| 2553 | |
| 2554 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2555 | { |
| 2556 | struct nfs4_exception exception = { }; |
| 2557 | int err; |
| 2558 | do { |
| 2559 | err = nfs4_handle_exception(server, |
| 2560 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2561 | &exception); |
| 2562 | } while (exception.retry); |
| 2563 | return err; |
| 2564 | } |
| 2565 | |
| 2566 | /* |
| 2567 | * The file is not closed if it is opened due to the a request to change |
| 2568 | * the size of the file. The open call will not be needed once the |
| 2569 | * VFS layer lookup-intents are implemented. |
| 2570 | * |
| 2571 | * Close is called when the inode is destroyed. |
| 2572 | * If we haven't opened the file for O_WRONLY, we |
| 2573 | * need to in the size_change case to obtain a stateid. |
| 2574 | * |
| 2575 | * Got race? |
| 2576 | * Because OPEN is always done by name in nfsv4, it is |
| 2577 | * possible that we opened a different file by the same |
| 2578 | * name. We can recognize this race condition, but we |
| 2579 | * can't do anything about it besides returning an error. |
| 2580 | * |
| 2581 | * This will be fixed with VFS changes (lookup-intent). |
| 2582 | */ |
| 2583 | static int |
| 2584 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2585 | struct iattr *sattr) |
| 2586 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2587 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2588 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2589 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | int status; |
| 2591 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2592 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2593 | pnfs_return_layout(inode); |
| 2594 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2595 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2597 | /* Deal with open(O_TRUNC) */ |
| 2598 | if (sattr->ia_valid & ATTR_OPEN) |
| 2599 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2600 | |
| 2601 | /* Optimization: if the end result is no change, don't RPC */ |
| 2602 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2603 | return 0; |
| 2604 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2605 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2606 | if (sattr->ia_valid & ATTR_FILE) { |
| 2607 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2608 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2609 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2610 | if (ctx) { |
| 2611 | cred = ctx->cred; |
| 2612 | state = ctx->state; |
| 2613 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2617 | if (status == 0) |
| 2618 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | return status; |
| 2620 | } |
| 2621 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2622 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2623 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2624 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2625 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2626 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2627 | int status; |
| 2628 | struct nfs4_lookup_arg args = { |
| 2629 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2630 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2631 | .name = name, |
| 2632 | }; |
| 2633 | struct nfs4_lookup_res res = { |
| 2634 | .server = server, |
| 2635 | .fattr = fattr, |
| 2636 | .fh = fhandle, |
| 2637 | }; |
| 2638 | struct rpc_message msg = { |
| 2639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2640 | .rpc_argp = &args, |
| 2641 | .rpc_resp = &res, |
| 2642 | }; |
| 2643 | |
| 2644 | nfs_fattr_init(fattr); |
| 2645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2647 | 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] | 2648 | dprintk("NFS reply lookup: %d\n", status); |
| 2649 | return status; |
| 2650 | } |
| 2651 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2652 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2653 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2654 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2655 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2656 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2657 | fattr->nlink = 2; |
| 2658 | } |
| 2659 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2660 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2661 | struct qstr *name, struct nfs_fh *fhandle, |
| 2662 | struct nfs_fattr *fattr) |
| 2663 | { |
| 2664 | struct nfs4_exception exception = { }; |
| 2665 | struct rpc_clnt *client = *clnt; |
| 2666 | int err; |
| 2667 | do { |
| 2668 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2669 | switch (err) { |
| 2670 | case -NFS4ERR_BADNAME: |
| 2671 | err = -ENOENT; |
| 2672 | goto out; |
| 2673 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2674 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2675 | goto out; |
| 2676 | case -NFS4ERR_WRONGSEC: |
| 2677 | err = -EPERM; |
| 2678 | if (client != *clnt) |
| 2679 | goto out; |
| 2680 | |
| 2681 | client = nfs4_create_sec_client(client, dir, name); |
| 2682 | if (IS_ERR(client)) |
| 2683 | return PTR_ERR(client); |
| 2684 | |
| 2685 | exception.retry = 1; |
| 2686 | break; |
| 2687 | default: |
| 2688 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2689 | } |
| 2690 | } while (exception.retry); |
| 2691 | |
| 2692 | out: |
| 2693 | if (err == 0) |
| 2694 | *clnt = client; |
| 2695 | else if (client != *clnt) |
| 2696 | rpc_shutdown_client(client); |
| 2697 | |
| 2698 | return err; |
| 2699 | } |
| 2700 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2701 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2702 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2704 | int status; |
| 2705 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2706 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2707 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2708 | if (client != NFS_CLIENT(dir)) { |
| 2709 | rpc_shutdown_client(client); |
| 2710 | nfs_fixup_secinfo_attributes(fattr); |
| 2711 | } |
| 2712 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2715 | struct rpc_clnt * |
| 2716 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2717 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2718 | { |
| 2719 | int status; |
| 2720 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2721 | |
| 2722 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2723 | if (status < 0) { |
| 2724 | rpc_shutdown_client(client); |
| 2725 | return ERR_PTR(status); |
| 2726 | } |
| 2727 | return client; |
| 2728 | } |
| 2729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2731 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2732 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | struct nfs4_accessargs args = { |
| 2734 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2735 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2737 | struct nfs4_accessres res = { |
| 2738 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2739 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | struct rpc_message msg = { |
| 2741 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2742 | .rpc_argp = &args, |
| 2743 | .rpc_resp = &res, |
| 2744 | .rpc_cred = entry->cred, |
| 2745 | }; |
| 2746 | int mode = entry->mask; |
| 2747 | int status; |
| 2748 | |
| 2749 | /* |
| 2750 | * Determine which access bits we want to ask for... |
| 2751 | */ |
| 2752 | if (mode & MAY_READ) |
| 2753 | args.access |= NFS4_ACCESS_READ; |
| 2754 | if (S_ISDIR(inode->i_mode)) { |
| 2755 | if (mode & MAY_WRITE) |
| 2756 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2757 | if (mode & MAY_EXEC) |
| 2758 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2759 | } else { |
| 2760 | if (mode & MAY_WRITE) |
| 2761 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2762 | if (mode & MAY_EXEC) |
| 2763 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2764 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2765 | |
| 2766 | res.fattr = nfs_alloc_fattr(); |
| 2767 | if (res.fattr == NULL) |
| 2768 | return -ENOMEM; |
| 2769 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2770 | 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] | 2771 | if (!status) { |
| 2772 | entry->mask = 0; |
| 2773 | if (res.access & NFS4_ACCESS_READ) |
| 2774 | entry->mask |= MAY_READ; |
| 2775 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2776 | entry->mask |= MAY_WRITE; |
| 2777 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2778 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2779 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2781 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | return status; |
| 2783 | } |
| 2784 | |
| 2785 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2786 | { |
| 2787 | struct nfs4_exception exception = { }; |
| 2788 | int err; |
| 2789 | do { |
| 2790 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2791 | _nfs4_proc_access(inode, entry), |
| 2792 | &exception); |
| 2793 | } while (exception.retry); |
| 2794 | return err; |
| 2795 | } |
| 2796 | |
| 2797 | /* |
| 2798 | * TODO: For the time being, we don't try to get any attributes |
| 2799 | * along with any of the zero-copy operations READ, READDIR, |
| 2800 | * READLINK, WRITE. |
| 2801 | * |
| 2802 | * In the case of the first three, we want to put the GETATTR |
| 2803 | * after the read-type operation -- this is because it is hard |
| 2804 | * to predict the length of a GETATTR response in v4, and thus |
| 2805 | * align the READ data correctly. This means that the GETATTR |
| 2806 | * may end up partially falling into the page cache, and we should |
| 2807 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2808 | * To do this efficiently, we need to know the total length |
| 2809 | * of data received, which doesn't seem to be available outside |
| 2810 | * of the RPC layer. |
| 2811 | * |
| 2812 | * In the case of WRITE, we also want to put the GETATTR after |
| 2813 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2814 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | * |
| 2816 | * Both of these changes to the XDR layer would in fact be quite |
| 2817 | * minor, but I decided to leave them for a subsequent patch. |
| 2818 | */ |
| 2819 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2820 | unsigned int pgbase, unsigned int pglen) |
| 2821 | { |
| 2822 | struct nfs4_readlink args = { |
| 2823 | .fh = NFS_FH(inode), |
| 2824 | .pgbase = pgbase, |
| 2825 | .pglen = pglen, |
| 2826 | .pages = &page, |
| 2827 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2828 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | struct rpc_message msg = { |
| 2830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2831 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2832 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | }; |
| 2834 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2835 | 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] | 2836 | } |
| 2837 | |
| 2838 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2839 | unsigned int pgbase, unsigned int pglen) |
| 2840 | { |
| 2841 | struct nfs4_exception exception = { }; |
| 2842 | int err; |
| 2843 | do { |
| 2844 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2845 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2846 | &exception); |
| 2847 | } while (exception.retry); |
| 2848 | return err; |
| 2849 | } |
| 2850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2852 | * 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] | 2853 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | static int |
| 2855 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2856 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2858 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | int status = 0; |
| 2861 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2862 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2863 | if (IS_ERR(ctx)) |
| 2864 | return PTR_ERR(ctx); |
| 2865 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2866 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2867 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2868 | flags, sattr, ctx->cred, |
| 2869 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2870 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | if (IS_ERR(state)) { |
| 2872 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2873 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2875 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2876 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2877 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2879 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | return status; |
| 2881 | } |
| 2882 | |
| 2883 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2884 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2885 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2886 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2888 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2890 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2891 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2892 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2894 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2895 | .rpc_argp = &args, |
| 2896 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2898 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2899 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2900 | 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] | 2901 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2902 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | return status; |
| 2904 | } |
| 2905 | |
| 2906 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2907 | { |
| 2908 | struct nfs4_exception exception = { }; |
| 2909 | int err; |
| 2910 | do { |
| 2911 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2912 | _nfs4_proc_remove(dir, name), |
| 2913 | &exception); |
| 2914 | } while (exception.retry); |
| 2915 | return err; |
| 2916 | } |
| 2917 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2918 | 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] | 2919 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2920 | struct nfs_server *server = NFS_SERVER(dir); |
| 2921 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2922 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2924 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2926 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2929 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2930 | { |
| 2931 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2932 | &data->args.seq_args, |
| 2933 | &data->res.seq_res, |
| 2934 | task)) |
| 2935 | return; |
| 2936 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | } |
| 2938 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2939 | 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] | 2940 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2941 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2942 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2943 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2944 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2945 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2946 | return 0; |
| 2947 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2948 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2951 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2952 | { |
| 2953 | struct nfs_server *server = NFS_SERVER(dir); |
| 2954 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2955 | struct nfs_renameres *res = msg->rpc_resp; |
| 2956 | |
| 2957 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2958 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2959 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2960 | } |
| 2961 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2962 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2963 | { |
| 2964 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2965 | &data->args.seq_args, |
| 2966 | &data->res.seq_res, |
| 2967 | task)) |
| 2968 | return; |
| 2969 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2973 | struct inode *new_dir) |
| 2974 | { |
| 2975 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2976 | |
| 2977 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2978 | return 0; |
| 2979 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2980 | return 0; |
| 2981 | |
| 2982 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2983 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2984 | return 1; |
| 2985 | } |
| 2986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2988 | struct inode *new_dir, struct qstr *new_name) |
| 2989 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2990 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2991 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | .old_dir = NFS_FH(old_dir), |
| 2993 | .new_dir = NFS_FH(new_dir), |
| 2994 | .old_name = old_name, |
| 2995 | .new_name = new_name, |
| 2996 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2997 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2998 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2999 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | struct rpc_message msg = { |
| 3001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3002 | .rpc_argp = &arg, |
| 3003 | .rpc_resp = &res, |
| 3004 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3005 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3007 | 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] | 3008 | if (!status) { |
| 3009 | update_changeattr(old_dir, &res.old_cinfo); |
| 3010 | update_changeattr(new_dir, &res.new_cinfo); |
| 3011 | } |
| 3012 | return status; |
| 3013 | } |
| 3014 | |
| 3015 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3016 | struct inode *new_dir, struct qstr *new_name) |
| 3017 | { |
| 3018 | struct nfs4_exception exception = { }; |
| 3019 | int err; |
| 3020 | do { |
| 3021 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3022 | _nfs4_proc_rename(old_dir, old_name, |
| 3023 | new_dir, new_name), |
| 3024 | &exception); |
| 3025 | } while (exception.retry); |
| 3026 | return err; |
| 3027 | } |
| 3028 | |
| 3029 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3030 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3031 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | struct nfs4_link_arg arg = { |
| 3033 | .fh = NFS_FH(inode), |
| 3034 | .dir_fh = NFS_FH(dir), |
| 3035 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3036 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3038 | struct nfs4_link_res res = { |
| 3039 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3040 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | struct rpc_message msg = { |
| 3042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3043 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3044 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3046 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3048 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3049 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3050 | goto out; |
| 3051 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3052 | 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] | 3053 | if (!status) { |
| 3054 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3055 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3056 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3057 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3058 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | return status; |
| 3060 | } |
| 3061 | |
| 3062 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3063 | { |
| 3064 | struct nfs4_exception exception = { }; |
| 3065 | int err; |
| 3066 | do { |
| 3067 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3068 | _nfs4_proc_link(inode, dir, name), |
| 3069 | &exception); |
| 3070 | } while (exception.retry); |
| 3071 | return err; |
| 3072 | } |
| 3073 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3074 | struct nfs4_createdata { |
| 3075 | struct rpc_message msg; |
| 3076 | struct nfs4_create_arg arg; |
| 3077 | struct nfs4_create_res res; |
| 3078 | struct nfs_fh fh; |
| 3079 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3080 | }; |
| 3081 | |
| 3082 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3083 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3084 | { |
| 3085 | struct nfs4_createdata *data; |
| 3086 | |
| 3087 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3088 | if (data != NULL) { |
| 3089 | struct nfs_server *server = NFS_SERVER(dir); |
| 3090 | |
| 3091 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3092 | data->msg.rpc_argp = &data->arg; |
| 3093 | data->msg.rpc_resp = &data->res; |
| 3094 | data->arg.dir_fh = NFS_FH(dir); |
| 3095 | data->arg.server = server; |
| 3096 | data->arg.name = name; |
| 3097 | data->arg.attrs = sattr; |
| 3098 | data->arg.ftype = ftype; |
| 3099 | data->arg.bitmask = server->attr_bitmask; |
| 3100 | data->res.server = server; |
| 3101 | data->res.fh = &data->fh; |
| 3102 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3103 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3104 | } |
| 3105 | return data; |
| 3106 | } |
| 3107 | |
| 3108 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3109 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3110 | 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] | 3111 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3112 | if (status == 0) { |
| 3113 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3114 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3115 | } |
| 3116 | return status; |
| 3117 | } |
| 3118 | |
| 3119 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3120 | { |
| 3121 | kfree(data); |
| 3122 | } |
| 3123 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3124 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3125 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3127 | struct nfs4_createdata *data; |
| 3128 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3130 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3131 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3132 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3133 | status = -ENOMEM; |
| 3134 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3135 | if (data == NULL) |
| 3136 | goto out; |
| 3137 | |
| 3138 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3139 | data->arg.u.symlink.pages = &page; |
| 3140 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3142 | status = nfs4_do_create(dir, dentry, data); |
| 3143 | |
| 3144 | nfs4_free_createdata(data); |
| 3145 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | return status; |
| 3147 | } |
| 3148 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3149 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3150 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | { |
| 3152 | struct nfs4_exception exception = { }; |
| 3153 | int err; |
| 3154 | do { |
| 3155 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3156 | _nfs4_proc_symlink(dir, dentry, page, |
| 3157 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | &exception); |
| 3159 | } while (exception.retry); |
| 3160 | return err; |
| 3161 | } |
| 3162 | |
| 3163 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3164 | struct iattr *sattr) |
| 3165 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3166 | struct nfs4_createdata *data; |
| 3167 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3169 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3170 | if (data == NULL) |
| 3171 | goto out; |
| 3172 | |
| 3173 | status = nfs4_do_create(dir, dentry, data); |
| 3174 | |
| 3175 | nfs4_free_createdata(data); |
| 3176 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | return status; |
| 3178 | } |
| 3179 | |
| 3180 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3181 | struct iattr *sattr) |
| 3182 | { |
| 3183 | struct nfs4_exception exception = { }; |
| 3184 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3185 | |
| 3186 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | do { |
| 3188 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3189 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3190 | &exception); |
| 3191 | } while (exception.retry); |
| 3192 | return err; |
| 3193 | } |
| 3194 | |
| 3195 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3196 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | { |
| 3198 | struct inode *dir = dentry->d_inode; |
| 3199 | struct nfs4_readdir_arg args = { |
| 3200 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3201 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | .pgbase = 0, |
| 3203 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3204 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3205 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | }; |
| 3207 | struct nfs4_readdir_res res; |
| 3208 | struct rpc_message msg = { |
| 3209 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3210 | .rpc_argp = &args, |
| 3211 | .rpc_resp = &res, |
| 3212 | .rpc_cred = cred, |
| 3213 | }; |
| 3214 | int status; |
| 3215 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3216 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3217 | dentry->d_parent->d_name.name, |
| 3218 | dentry->d_name.name, |
| 3219 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3221 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3222 | 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] | 3223 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3225 | status += args.pgbase; |
| 3226 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3227 | |
| 3228 | nfs_invalidate_atime(dir); |
| 3229 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3230 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | return status; |
| 3232 | } |
| 3233 | |
| 3234 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3235 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | { |
| 3237 | struct nfs4_exception exception = { }; |
| 3238 | int err; |
| 3239 | do { |
| 3240 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3241 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3242 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | &exception); |
| 3244 | } while (exception.retry); |
| 3245 | return err; |
| 3246 | } |
| 3247 | |
| 3248 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3249 | struct iattr *sattr, dev_t rdev) |
| 3250 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3251 | struct nfs4_createdata *data; |
| 3252 | int mode = sattr->ia_mode; |
| 3253 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | |
| 3255 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3256 | 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] | 3257 | |
| 3258 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3259 | if (data == NULL) |
| 3260 | goto out; |
| 3261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3263 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3265 | data->arg.ftype = NF4BLK; |
| 3266 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3267 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | } |
| 3269 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3270 | data->arg.ftype = NF4CHR; |
| 3271 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3272 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3275 | status = nfs4_do_create(dir, dentry, data); |
| 3276 | |
| 3277 | nfs4_free_createdata(data); |
| 3278 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | return status; |
| 3280 | } |
| 3281 | |
| 3282 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3283 | struct iattr *sattr, dev_t rdev) |
| 3284 | { |
| 3285 | struct nfs4_exception exception = { }; |
| 3286 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3287 | |
| 3288 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | do { |
| 3290 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3291 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3292 | &exception); |
| 3293 | } while (exception.retry); |
| 3294 | return err; |
| 3295 | } |
| 3296 | |
| 3297 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3298 | struct nfs_fsstat *fsstat) |
| 3299 | { |
| 3300 | struct nfs4_statfs_arg args = { |
| 3301 | .fh = fhandle, |
| 3302 | .bitmask = server->attr_bitmask, |
| 3303 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3304 | struct nfs4_statfs_res res = { |
| 3305 | .fsstat = fsstat, |
| 3306 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | struct rpc_message msg = { |
| 3308 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3309 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3310 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | }; |
| 3312 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3313 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3314 | 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] | 3315 | } |
| 3316 | |
| 3317 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3318 | { |
| 3319 | struct nfs4_exception exception = { }; |
| 3320 | int err; |
| 3321 | do { |
| 3322 | err = nfs4_handle_exception(server, |
| 3323 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3324 | &exception); |
| 3325 | } while (exception.retry); |
| 3326 | return err; |
| 3327 | } |
| 3328 | |
| 3329 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3330 | struct nfs_fsinfo *fsinfo) |
| 3331 | { |
| 3332 | struct nfs4_fsinfo_arg args = { |
| 3333 | .fh = fhandle, |
| 3334 | .bitmask = server->attr_bitmask, |
| 3335 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3336 | struct nfs4_fsinfo_res res = { |
| 3337 | .fsinfo = fsinfo, |
| 3338 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | struct rpc_message msg = { |
| 3340 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3341 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3342 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | }; |
| 3344 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3345 | 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] | 3346 | } |
| 3347 | |
| 3348 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3349 | { |
| 3350 | struct nfs4_exception exception = { }; |
| 3351 | int err; |
| 3352 | |
| 3353 | do { |
| 3354 | err = nfs4_handle_exception(server, |
| 3355 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3356 | &exception); |
| 3357 | } while (exception.retry); |
| 3358 | return err; |
| 3359 | } |
| 3360 | |
| 3361 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3362 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3363 | int error; |
| 3364 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3365 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3366 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3367 | if (error == 0) |
| 3368 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
| 3369 | |
| 3370 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3374 | struct nfs_pathconf *pathconf) |
| 3375 | { |
| 3376 | struct nfs4_pathconf_arg args = { |
| 3377 | .fh = fhandle, |
| 3378 | .bitmask = server->attr_bitmask, |
| 3379 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3380 | struct nfs4_pathconf_res res = { |
| 3381 | .pathconf = pathconf, |
| 3382 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | struct rpc_message msg = { |
| 3384 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3385 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3386 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | }; |
| 3388 | |
| 3389 | /* None of the pathconf attributes are mandatory to implement */ |
| 3390 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3391 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3392 | return 0; |
| 3393 | } |
| 3394 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3395 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3396 | 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] | 3397 | } |
| 3398 | |
| 3399 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3400 | struct nfs_pathconf *pathconf) |
| 3401 | { |
| 3402 | struct nfs4_exception exception = { }; |
| 3403 | int err; |
| 3404 | |
| 3405 | do { |
| 3406 | err = nfs4_handle_exception(server, |
| 3407 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3408 | &exception); |
| 3409 | } while (exception.retry); |
| 3410 | return err; |
| 3411 | } |
| 3412 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3413 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3414 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3415 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3416 | } |
| 3417 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3418 | 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] | 3419 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3420 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3422 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3423 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3424 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3426 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3427 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3429 | renew_lease(server, data->timestamp); |
| 3430 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3433 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3434 | { |
| 3435 | |
| 3436 | dprintk("--> %s\n", __func__); |
| 3437 | |
| 3438 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3439 | return -EAGAIN; |
| 3440 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3441 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3442 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3445 | 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] | 3446 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3448 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3449 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3450 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3453 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3454 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3455 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3456 | &data->args.seq_args, |
| 3457 | &data->res.seq_res, |
| 3458 | task)) |
| 3459 | return; |
| 3460 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3463 | 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] | 3464 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3465 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3467 | 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] | 3468 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3469 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3471 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3473 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3474 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3475 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3478 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3479 | { |
| 3480 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3481 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3482 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3483 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3486 | static |
| 3487 | 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] | 3488 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3489 | const struct nfs_pgio_header *hdr = data->header; |
| 3490 | |
| 3491 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3492 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3493 | return false; |
| 3494 | /* Otherwise, request attributes if and only if we don't hold |
| 3495 | * a delegation |
| 3496 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3497 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3498 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3499 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3500 | 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] | 3501 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3502 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3503 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3504 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3505 | data->args.bitmask = NULL; |
| 3506 | data->res.fattr = NULL; |
| 3507 | } else |
| 3508 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3509 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3510 | if (!data->write_done_cb) |
| 3511 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3512 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | data->timestamp = jiffies; |
| 3514 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3515 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3516 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3519 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3520 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3521 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3522 | &data->args.seq_args, |
| 3523 | &data->res.seq_res, |
| 3524 | task)) |
| 3525 | return; |
| 3526 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3529 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3530 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3532 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3533 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | return; |
| 3536 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3537 | } |
| 3538 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3539 | 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] | 3540 | { |
| 3541 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3542 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3543 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3544 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3545 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3547 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3550 | 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] | 3551 | { |
| 3552 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3553 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3554 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3555 | } |
| 3556 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3557 | 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] | 3558 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3559 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3560 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3561 | if (data->commit_done_cb == NULL) |
| 3562 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3563 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3564 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3565 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3568 | struct nfs4_renewdata { |
| 3569 | struct nfs_client *client; |
| 3570 | unsigned long timestamp; |
| 3571 | }; |
| 3572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | /* |
| 3574 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3575 | * standalone procedure for queueing an asynchronous RENEW. |
| 3576 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3577 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3578 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3579 | struct nfs4_renewdata *data = calldata; |
| 3580 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3581 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3582 | if (atomic_read(&clp->cl_count) > 1) |
| 3583 | nfs4_schedule_state_renewal(clp); |
| 3584 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3585 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3588 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3590 | struct nfs4_renewdata *data = calldata; |
| 3591 | struct nfs_client *clp = data->client; |
| 3592 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | |
| 3594 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3595 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3596 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3597 | return; |
| 3598 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3599 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3600 | return; |
| 3601 | } |
| 3602 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3604 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3607 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3608 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3609 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3610 | }; |
| 3611 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3612 | 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] | 3613 | { |
| 3614 | struct rpc_message msg = { |
| 3615 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3616 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3617 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3619 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3621 | if (renew_flags == 0) |
| 3622 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3623 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3624 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3625 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3626 | if (data == NULL) |
| 3627 | return -ENOMEM; |
| 3628 | data->client = clp; |
| 3629 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3631 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3634 | 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] | 3635 | { |
| 3636 | struct rpc_message msg = { |
| 3637 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3638 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3639 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | }; |
| 3641 | unsigned long now = jiffies; |
| 3642 | int status; |
| 3643 | |
| 3644 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3645 | if (status < 0) |
| 3646 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3647 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | return 0; |
| 3649 | } |
| 3650 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3651 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3652 | { |
| 3653 | return (server->caps & NFS_CAP_ACLS) |
| 3654 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3655 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3656 | } |
| 3657 | |
| 3658 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3659 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3660 | * the stack. |
| 3661 | */ |
| 3662 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3663 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3664 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3665 | struct page **pages, unsigned int *pgbase) |
| 3666 | { |
| 3667 | struct page *newpage, **spages; |
| 3668 | int rc = 0; |
| 3669 | size_t len; |
| 3670 | spages = pages; |
| 3671 | |
| 3672 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3673 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3674 | newpage = alloc_page(GFP_KERNEL); |
| 3675 | |
| 3676 | if (newpage == NULL) |
| 3677 | goto unwind; |
| 3678 | memcpy(page_address(newpage), buf, len); |
| 3679 | buf += len; |
| 3680 | buflen -= len; |
| 3681 | *pages++ = newpage; |
| 3682 | rc++; |
| 3683 | } while (buflen != 0); |
| 3684 | |
| 3685 | return rc; |
| 3686 | |
| 3687 | unwind: |
| 3688 | for(; rc > 0; rc--) |
| 3689 | __free_page(spages[rc-1]); |
| 3690 | return -ENOMEM; |
| 3691 | } |
| 3692 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3693 | struct nfs4_cached_acl { |
| 3694 | int cached; |
| 3695 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3696 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3697 | }; |
| 3698 | |
| 3699 | 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] | 3700 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3701 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3702 | |
| 3703 | spin_lock(&inode->i_lock); |
| 3704 | kfree(nfsi->nfs4_acl); |
| 3705 | nfsi->nfs4_acl = acl; |
| 3706 | spin_unlock(&inode->i_lock); |
| 3707 | } |
| 3708 | |
| 3709 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3710 | { |
| 3711 | nfs4_set_cached_acl(inode, NULL); |
| 3712 | } |
| 3713 | |
| 3714 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3715 | { |
| 3716 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3717 | struct nfs4_cached_acl *acl; |
| 3718 | int ret = -ENOENT; |
| 3719 | |
| 3720 | spin_lock(&inode->i_lock); |
| 3721 | acl = nfsi->nfs4_acl; |
| 3722 | if (acl == NULL) |
| 3723 | goto out; |
| 3724 | if (buf == NULL) /* user is just asking for length */ |
| 3725 | goto out_len; |
| 3726 | if (acl->cached == 0) |
| 3727 | goto out; |
| 3728 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3729 | if (acl->len > buflen) |
| 3730 | goto out; |
| 3731 | memcpy(buf, acl->data, acl->len); |
| 3732 | out_len: |
| 3733 | ret = acl->len; |
| 3734 | out: |
| 3735 | spin_unlock(&inode->i_lock); |
| 3736 | return ret; |
| 3737 | } |
| 3738 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3739 | 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] | 3740 | { |
| 3741 | struct nfs4_cached_acl *acl; |
| 3742 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3743 | if (pages && acl_len <= PAGE_SIZE) { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3744 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3745 | if (acl == NULL) |
| 3746 | goto out; |
| 3747 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3748 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3749 | } else { |
| 3750 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3751 | if (acl == NULL) |
| 3752 | goto out; |
| 3753 | acl->cached = 0; |
| 3754 | } |
| 3755 | acl->len = acl_len; |
| 3756 | out: |
| 3757 | nfs4_set_cached_acl(inode, acl); |
| 3758 | } |
| 3759 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3760 | /* |
| 3761 | * The getxattr API returns the required buffer length when called with a |
| 3762 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3763 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3764 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3765 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3766 | * the cache. If not so, we throw away the page, and cache the required |
| 3767 | * length. The next getxattr call will then produce another round trip to |
| 3768 | * the server, this time with the input buf of the required size. |
| 3769 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3770 | 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] | 3771 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3772 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3773 | struct nfs_getaclargs args = { |
| 3774 | .fh = NFS_FH(inode), |
| 3775 | .acl_pages = pages, |
| 3776 | .acl_len = buflen, |
| 3777 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3778 | struct nfs_getaclres res = { |
| 3779 | .acl_len = buflen, |
| 3780 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3781 | struct rpc_message msg = { |
| 3782 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3783 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3784 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3785 | }; |
Chuck Lever | 56d08fe | 2012-07-11 16:30:32 -0400 | [diff] [blame] | 3786 | int ret = -ENOMEM, npages, i; |
| 3787 | size_t acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3788 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3789 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3790 | /* As long as we're doing a round trip to the server anyway, |
| 3791 | * let's be prepared for a page of acl data. */ |
| 3792 | if (npages == 0) |
| 3793 | npages = 1; |
| 3794 | |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3795 | /* Add an extra page to handle the bitmap returned */ |
| 3796 | npages++; |
| 3797 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3798 | for (i = 0; i < npages; i++) { |
| 3799 | pages[i] = alloc_page(GFP_KERNEL); |
| 3800 | if (!pages[i]) |
| 3801 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3802 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3803 | |
| 3804 | /* for decoding across pages */ |
| 3805 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3806 | if (!res.acl_scratch) |
| 3807 | goto out_free; |
| 3808 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3809 | args.acl_len = npages * PAGE_SIZE; |
| 3810 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3811 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3812 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3813 | * the page we send as a guess */ |
| 3814 | if (buf == NULL) |
| 3815 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3816 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3817 | dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3818 | __func__, buf, buflen, npages, args.acl_len); |
| 3819 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3820 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3821 | if (ret) |
| 3822 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3823 | |
| 3824 | acl_len = res.acl_len - res.acl_data_offset; |
| 3825 | if (acl_len > args.acl_len) |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3826 | nfs4_write_cached_acl(inode, NULL, 0, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3827 | else |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3828 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3829 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3830 | if (buf) { |
| 3831 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3832 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3833 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3834 | _copy_from_pages(buf, pages, res.acl_data_offset, |
Sachin Prabhu | 20e0fa9 | 2012-03-22 16:46:28 +0000 | [diff] [blame] | 3835 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3836 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3837 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3838 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3839 | for (i = 0; i < npages; i++) |
| 3840 | if (pages[i]) |
| 3841 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3842 | if (res.acl_scratch) |
| 3843 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3844 | return ret; |
| 3845 | } |
| 3846 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3847 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3848 | { |
| 3849 | struct nfs4_exception exception = { }; |
| 3850 | ssize_t ret; |
| 3851 | do { |
| 3852 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3853 | if (ret >= 0) |
| 3854 | break; |
| 3855 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3856 | } while (exception.retry); |
| 3857 | return ret; |
| 3858 | } |
| 3859 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3860 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3861 | { |
| 3862 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3863 | int ret; |
| 3864 | |
| 3865 | if (!nfs4_server_supports_acls(server)) |
| 3866 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3867 | ret = nfs_revalidate_inode(server, inode); |
| 3868 | if (ret < 0) |
| 3869 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3870 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3871 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3872 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3873 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3874 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3875 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3876 | return ret; |
| 3877 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3880 | static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3881 | { |
| 3882 | struct nfs_server *server = NFS_SERVER(inode); |
| 3883 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3884 | struct nfs_setaclargs arg = { |
| 3885 | .fh = NFS_FH(inode), |
| 3886 | .acl_pages = pages, |
| 3887 | .acl_len = buflen, |
| 3888 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3889 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3890 | struct rpc_message msg = { |
| 3891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3892 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3893 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3894 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3895 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3896 | |
| 3897 | if (!nfs4_server_supports_acls(server)) |
| 3898 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3899 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3900 | if (i < 0) |
| 3901 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3902 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3903 | 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] | 3904 | |
| 3905 | /* |
| 3906 | * Free each page after tx, so the only ref left is |
| 3907 | * held by the network stack |
| 3908 | */ |
| 3909 | for (; i > 0; i--) |
| 3910 | put_page(pages[i-1]); |
| 3911 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3912 | /* |
| 3913 | * Acl update can result in inode attribute update. |
| 3914 | * so mark the attribute cache invalid. |
| 3915 | */ |
| 3916 | spin_lock(&inode->i_lock); |
| 3917 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3918 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3919 | nfs_access_zap_cache(inode); |
| 3920 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3921 | return ret; |
| 3922 | } |
| 3923 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3924 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3925 | { |
| 3926 | struct nfs4_exception exception = { }; |
| 3927 | int err; |
| 3928 | do { |
| 3929 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3930 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3931 | &exception); |
| 3932 | } while (exception.retry); |
| 3933 | return err; |
| 3934 | } |
| 3935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3937 | 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] | 3938 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3939 | struct nfs_client *clp = server->nfs_client; |
| 3940 | |
| 3941 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | return 0; |
| 3943 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3944 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3945 | case -NFS4ERR_ADMIN_REVOKED: |
| 3946 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3947 | if (state == NULL) |
| 3948 | break; |
| 3949 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3950 | case -NFS4ERR_OPENMODE: |
| 3951 | if (state == NULL) |
| 3952 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3953 | nfs4_schedule_stateid_recovery(server, state); |
| 3954 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3955 | case -NFS4ERR_EXPIRED: |
| 3956 | if (state != NULL) |
| 3957 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3959 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3960 | nfs4_schedule_lease_recovery(clp); |
| 3961 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3962 | #if defined(CONFIG_NFS_V4_1) |
| 3963 | case -NFS4ERR_BADSESSION: |
| 3964 | case -NFS4ERR_BADSLOT: |
| 3965 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3966 | case -NFS4ERR_DEADSESSION: |
| 3967 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3968 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3969 | case -NFS4ERR_SEQ_MISORDERED: |
| 3970 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3971 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 3972 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3973 | task->tk_status = 0; |
| 3974 | return -EAGAIN; |
| 3975 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3977 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3978 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3979 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3981 | task->tk_status = 0; |
| 3982 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3983 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | case -NFS4ERR_OLD_STATEID: |
| 3985 | task->tk_status = 0; |
| 3986 | return -EAGAIN; |
| 3987 | } |
| 3988 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3989 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3990 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3991 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3992 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3993 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3994 | task->tk_status = 0; |
| 3995 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3998 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 3999 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4000 | { |
| 4001 | __be32 verf[2]; |
| 4002 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4003 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4004 | /* An impossible timestamp guarantees this value |
| 4005 | * will never match a generated boot time. */ |
| 4006 | verf[0] = 0; |
| 4007 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4008 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4009 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4010 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4011 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4012 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4013 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4014 | } |
| 4015 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4016 | /** |
| 4017 | * nfs4_proc_setclientid - Negotiate client ID |
| 4018 | * @clp: state data structure |
| 4019 | * @program: RPC program for NFSv4 callback service |
| 4020 | * @port: IP port number for NFS4 callback service |
| 4021 | * @cred: RPC credential to use for this call |
| 4022 | * @res: where to place the result |
| 4023 | * |
| 4024 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4025 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4026 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4027 | unsigned short port, struct rpc_cred *cred, |
| 4028 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | { |
| 4030 | nfs4_verifier sc_verifier; |
| 4031 | struct nfs4_setclientid setclientid = { |
| 4032 | .sc_verifier = &sc_verifier, |
| 4033 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4034 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | }; |
| 4036 | struct rpc_message msg = { |
| 4037 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4038 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4039 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4040 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4042 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4044 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4045 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4046 | rcu_read_lock(); |
| 4047 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
| 4048 | sizeof(setclientid.sc_name), "%s/%s %s", |
| 4049 | clp->cl_ipaddr, |
| 4050 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4051 | RPC_DISPLAY_ADDR), |
| 4052 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4053 | RPC_DISPLAY_PROTO)); |
| 4054 | /* cb_client4 */ |
| 4055 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4056 | sizeof(setclientid.sc_netid), |
| 4057 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4058 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4059 | rcu_read_unlock(); |
| 4060 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4061 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4063 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4064 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4065 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4066 | setclientid.sc_name_len, setclientid.sc_name); |
| 4067 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4068 | dprintk("NFS reply setclientid: %d\n", status); |
| 4069 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4072 | /** |
| 4073 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4074 | * @clp: state data structure |
| 4075 | * @res: result of a previous SETCLIENTID |
| 4076 | * @cred: RPC credential to use for this call |
| 4077 | * |
| 4078 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4079 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4080 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4081 | struct nfs4_setclientid_res *arg, |
| 4082 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | { |
| 4084 | struct nfs_fsinfo fsinfo; |
| 4085 | struct rpc_message msg = { |
| 4086 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4087 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4089 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | }; |
| 4091 | unsigned long now; |
| 4092 | int status; |
| 4093 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4094 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4095 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4096 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4098 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | if (status == 0) { |
| 4100 | spin_lock(&clp->cl_lock); |
| 4101 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4102 | clp->cl_last_renewal = now; |
| 4103 | spin_unlock(&clp->cl_lock); |
| 4104 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4105 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | return status; |
| 4107 | } |
| 4108 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4109 | struct nfs4_delegreturndata { |
| 4110 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4111 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4112 | struct nfs_fh fh; |
| 4113 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4114 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4115 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4116 | int rpc_status; |
| 4117 | }; |
| 4118 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4119 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4120 | { |
| 4121 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4122 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4123 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4124 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4125 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4126 | switch (task->tk_status) { |
| 4127 | case -NFS4ERR_STALE_STATEID: |
| 4128 | case -NFS4ERR_EXPIRED: |
| 4129 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4130 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4131 | break; |
| 4132 | default: |
| 4133 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4134 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4135 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4136 | return; |
| 4137 | } |
| 4138 | } |
| 4139 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | static void nfs4_delegreturn_release(void *calldata) |
| 4143 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4144 | kfree(calldata); |
| 4145 | } |
| 4146 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4147 | #if defined(CONFIG_NFS_V4_1) |
| 4148 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4149 | { |
| 4150 | struct nfs4_delegreturndata *d_data; |
| 4151 | |
| 4152 | d_data = (struct nfs4_delegreturndata *)data; |
| 4153 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4154 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4155 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4156 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4157 | return; |
| 4158 | rpc_call_start(task); |
| 4159 | } |
| 4160 | #endif /* CONFIG_NFS_V4_1 */ |
| 4161 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4162 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4163 | #if defined(CONFIG_NFS_V4_1) |
| 4164 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4165 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4166 | .rpc_call_done = nfs4_delegreturn_done, |
| 4167 | .rpc_release = nfs4_delegreturn_release, |
| 4168 | }; |
| 4169 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4170 | 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] | 4171 | { |
| 4172 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4173 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4174 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4175 | struct rpc_message msg = { |
| 4176 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4177 | .rpc_cred = cred, |
| 4178 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4179 | struct rpc_task_setup task_setup_data = { |
| 4180 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4181 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4182 | .callback_ops = &nfs4_delegreturn_ops, |
| 4183 | .flags = RPC_TASK_ASYNC, |
| 4184 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4185 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4186 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4187 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4188 | if (data == NULL) |
| 4189 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4190 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4191 | data->args.fhandle = &data->fh; |
| 4192 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4193 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4194 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4195 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4196 | data->res.fattr = &data->fattr; |
| 4197 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4198 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4199 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4200 | data->rpc_status = 0; |
| 4201 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4202 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4203 | msg.rpc_argp = &data->args; |
| 4204 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4205 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4206 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4207 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4208 | if (!issync) |
| 4209 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4210 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4211 | if (status != 0) |
| 4212 | goto out; |
| 4213 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4214 | if (status == 0) |
| 4215 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4216 | else |
| 4217 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4218 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4219 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4220 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4223 | 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] | 4224 | { |
| 4225 | struct nfs_server *server = NFS_SERVER(inode); |
| 4226 | struct nfs4_exception exception = { }; |
| 4227 | int err; |
| 4228 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4229 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | switch (err) { |
| 4231 | case -NFS4ERR_STALE_STATEID: |
| 4232 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | case 0: |
| 4234 | return 0; |
| 4235 | } |
| 4236 | err = nfs4_handle_exception(server, err, &exception); |
| 4237 | } while (exception.retry); |
| 4238 | return err; |
| 4239 | } |
| 4240 | |
| 4241 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4242 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4243 | |
| 4244 | /* |
| 4245 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4246 | */ |
| 4247 | static unsigned long |
| 4248 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4249 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4250 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | timeout <<= 1; |
| 4252 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4253 | return NFS4_LOCK_MAXTIMEOUT; |
| 4254 | return timeout; |
| 4255 | } |
| 4256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4258 | { |
| 4259 | struct inode *inode = state->inode; |
| 4260 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4261 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4262 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4264 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4266 | struct nfs_lockt_res res = { |
| 4267 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | }; |
| 4269 | struct rpc_message msg = { |
| 4270 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4271 | .rpc_argp = &arg, |
| 4272 | .rpc_resp = &res, |
| 4273 | .rpc_cred = state->owner->so_cred, |
| 4274 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | struct nfs4_lock_state *lsp; |
| 4276 | int status; |
| 4277 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4278 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4279 | status = nfs4_set_lock_state(state, request); |
| 4280 | if (status != 0) |
| 4281 | goto out; |
| 4282 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4283 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4284 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4285 | 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] | 4286 | switch (status) { |
| 4287 | case 0: |
| 4288 | request->fl_type = F_UNLCK; |
| 4289 | break; |
| 4290 | case -NFS4ERR_DENIED: |
| 4291 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4293 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4294 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | return status; |
| 4296 | } |
| 4297 | |
| 4298 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4299 | { |
| 4300 | struct nfs4_exception exception = { }; |
| 4301 | int err; |
| 4302 | |
| 4303 | do { |
| 4304 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4305 | _nfs4_proc_getlk(state, cmd, request), |
| 4306 | &exception); |
| 4307 | } while (exception.retry); |
| 4308 | return err; |
| 4309 | } |
| 4310 | |
| 4311 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4312 | { |
| 4313 | int res = 0; |
| 4314 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4315 | case FL_POSIX: |
| 4316 | res = posix_lock_file_wait(file, fl); |
| 4317 | break; |
| 4318 | case FL_FLOCK: |
| 4319 | res = flock_lock_file_wait(file, fl); |
| 4320 | break; |
| 4321 | default: |
| 4322 | BUG(); |
| 4323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | return res; |
| 4325 | } |
| 4326 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4327 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4328 | struct nfs_locku_args arg; |
| 4329 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4330 | struct nfs4_lock_state *lsp; |
| 4331 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4332 | struct file_lock fl; |
| 4333 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4334 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4335 | }; |
| 4336 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4337 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4338 | struct nfs_open_context *ctx, |
| 4339 | struct nfs4_lock_state *lsp, |
| 4340 | struct nfs_seqid *seqid) |
| 4341 | { |
| 4342 | struct nfs4_unlockdata *p; |
| 4343 | struct inode *inode = lsp->ls_state->inode; |
| 4344 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4345 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4346 | if (p == NULL) |
| 4347 | return NULL; |
| 4348 | p->arg.fh = NFS_FH(inode); |
| 4349 | p->arg.fl = &p->fl; |
| 4350 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4351 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4352 | p->arg.stateid = &lsp->ls_stateid; |
| 4353 | p->lsp = lsp; |
| 4354 | atomic_inc(&lsp->ls_count); |
| 4355 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4356 | p->ctx = get_nfs_open_context(ctx); |
| 4357 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4358 | p->server = NFS_SERVER(inode); |
| 4359 | return p; |
| 4360 | } |
| 4361 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4362 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4363 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4364 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4365 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4366 | nfs4_put_lock_state(calldata->lsp); |
| 4367 | put_nfs_open_context(calldata->ctx); |
| 4368 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4371 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4372 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4373 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4374 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4375 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4376 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4377 | switch (task->tk_status) { |
| 4378 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4379 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4380 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4381 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4382 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4383 | case -NFS4ERR_BAD_STATEID: |
| 4384 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4385 | case -NFS4ERR_STALE_STATEID: |
| 4386 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4387 | break; |
| 4388 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4389 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4390 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4391 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4392 | } |
| 4393 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4394 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4395 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4396 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4398 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4399 | return; |
| 4400 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4401 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4402 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4403 | return; |
| 4404 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4405 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4406 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4407 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4408 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4409 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4410 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4413 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4414 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4415 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4416 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4417 | }; |
| 4418 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4419 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4420 | struct nfs_open_context *ctx, |
| 4421 | struct nfs4_lock_state *lsp, |
| 4422 | struct nfs_seqid *seqid) |
| 4423 | { |
| 4424 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4425 | struct rpc_message msg = { |
| 4426 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4427 | .rpc_cred = ctx->cred, |
| 4428 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4429 | struct rpc_task_setup task_setup_data = { |
| 4430 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4431 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4432 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4433 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4434 | .flags = RPC_TASK_ASYNC, |
| 4435 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4436 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4437 | /* Ensure this is an unlock - when canceling a lock, the |
| 4438 | * canceled lock is passed in, and it won't be an unlock. |
| 4439 | */ |
| 4440 | fl->fl_type = F_UNLCK; |
| 4441 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4442 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4443 | if (data == NULL) { |
| 4444 | nfs_free_seqid(seqid); |
| 4445 | return ERR_PTR(-ENOMEM); |
| 4446 | } |
| 4447 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4448 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4449 | msg.rpc_argp = &data->arg; |
| 4450 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4451 | task_setup_data.callback_data = data; |
| 4452 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4456 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4457 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4458 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4459 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4460 | struct rpc_task *task; |
| 4461 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4462 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4464 | status = nfs4_set_lock_state(state, request); |
| 4465 | /* Unlock _before_ we do the RPC call */ |
| 4466 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4467 | down_read(&nfsi->rwsem); |
| 4468 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4469 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4470 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4471 | } |
| 4472 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4473 | if (status != 0) |
| 4474 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4475 | /* Is this a delegated lock? */ |
| 4476 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4477 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4478 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4479 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4480 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4481 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4482 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4483 | 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] | 4484 | status = PTR_ERR(task); |
| 4485 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4486 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4487 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4488 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4489 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4490 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4491 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4494 | struct nfs4_lockdata { |
| 4495 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4496 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4497 | struct nfs4_lock_state *lsp; |
| 4498 | struct nfs_open_context *ctx; |
| 4499 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4500 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4501 | int rpc_status; |
| 4502 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4503 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4504 | }; |
| 4505 | |
| 4506 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4507 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4508 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4509 | { |
| 4510 | struct nfs4_lockdata *p; |
| 4511 | struct inode *inode = lsp->ls_state->inode; |
| 4512 | struct nfs_server *server = NFS_SERVER(inode); |
| 4513 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4514 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4515 | if (p == NULL) |
| 4516 | return NULL; |
| 4517 | |
| 4518 | p->arg.fh = NFS_FH(inode); |
| 4519 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4520 | 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] | 4521 | if (p->arg.open_seqid == NULL) |
| 4522 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4523 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4524 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4525 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4526 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4527 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4528 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4529 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4530 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4531 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4532 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4533 | atomic_inc(&lsp->ls_count); |
| 4534 | p->ctx = get_nfs_open_context(ctx); |
| 4535 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4536 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4537 | out_free_seqid: |
| 4538 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4539 | out_free: |
| 4540 | kfree(p); |
| 4541 | return NULL; |
| 4542 | } |
| 4543 | |
| 4544 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4545 | { |
| 4546 | struct nfs4_lockdata *data = calldata; |
| 4547 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4549 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4550 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4551 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4552 | /* Do we need to do an open_to_lock_owner? */ |
| 4553 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4554 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4555 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4556 | data->arg.open_stateid = &state->stateid; |
| 4557 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4558 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4559 | } else |
| 4560 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4561 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4562 | if (nfs4_setup_sequence(data->server, |
| 4563 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4564 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4565 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4566 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4567 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4568 | } |
| 4569 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4570 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4571 | { |
| 4572 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4573 | nfs4_lock_prepare(task, calldata); |
| 4574 | } |
| 4575 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4576 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4577 | { |
| 4578 | struct nfs4_lockdata *data = calldata; |
| 4579 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4580 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4581 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4582 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4583 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4584 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4585 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4586 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4587 | if (data->rpc_status == 0) |
| 4588 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4589 | else |
| 4590 | goto out; |
| 4591 | } |
| 4592 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4593 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4594 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4595 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4596 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4597 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4598 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | static void nfs4_lock_release(void *calldata) |
| 4602 | { |
| 4603 | struct nfs4_lockdata *data = calldata; |
| 4604 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4605 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4606 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4607 | if (data->cancelled != 0) { |
| 4608 | struct rpc_task *task; |
| 4609 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4610 | data->arg.lock_seqid); |
| 4611 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4612 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4613 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4614 | } else |
| 4615 | nfs_free_seqid(data->arg.lock_seqid); |
| 4616 | nfs4_put_lock_state(data->lsp); |
| 4617 | put_nfs_open_context(data->ctx); |
| 4618 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4619 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4623 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4624 | .rpc_call_done = nfs4_lock_done, |
| 4625 | .rpc_release = nfs4_lock_release, |
| 4626 | }; |
| 4627 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4628 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4629 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4630 | .rpc_call_done = nfs4_lock_done, |
| 4631 | .rpc_release = nfs4_lock_release, |
| 4632 | }; |
| 4633 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4634 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4635 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4636 | switch (error) { |
| 4637 | case -NFS4ERR_ADMIN_REVOKED: |
| 4638 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4639 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4640 | if (new_lock_owner != 0 || |
| 4641 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4642 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4643 | break; |
| 4644 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4645 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4646 | case -NFS4ERR_EXPIRED: |
| 4647 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4648 | }; |
| 4649 | } |
| 4650 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4651 | 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] | 4652 | { |
| 4653 | struct nfs4_lockdata *data; |
| 4654 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4655 | struct rpc_message msg = { |
| 4656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4657 | .rpc_cred = state->owner->so_cred, |
| 4658 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4659 | struct rpc_task_setup task_setup_data = { |
| 4660 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4661 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4662 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4663 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4664 | .flags = RPC_TASK_ASYNC, |
| 4665 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4666 | int ret; |
| 4667 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4668 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4669 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4670 | fl->fl_u.nfs4_fl.owner, |
| 4671 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4672 | if (data == NULL) |
| 4673 | return -ENOMEM; |
| 4674 | if (IS_SETLKW(cmd)) |
| 4675 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4676 | if (recovery_type > NFS_LOCK_NEW) { |
| 4677 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4678 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4679 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4680 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4681 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4682 | msg.rpc_argp = &data->arg; |
| 4683 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4684 | task_setup_data.callback_data = data; |
| 4685 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4686 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4687 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4688 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4689 | if (ret == 0) { |
| 4690 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4691 | if (ret) |
| 4692 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4693 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4694 | } else |
| 4695 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4696 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4697 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4698 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4702 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4703 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4704 | struct nfs4_exception exception = { |
| 4705 | .inode = state->inode, |
| 4706 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4707 | int err; |
| 4708 | |
| 4709 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4710 | /* Cache the lock if possible... */ |
| 4711 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4712 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4713 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4714 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4715 | break; |
| 4716 | nfs4_handle_exception(server, err, &exception); |
| 4717 | } while (exception.retry); |
| 4718 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4722 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4723 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4724 | struct nfs4_exception exception = { |
| 4725 | .inode = state->inode, |
| 4726 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4727 | int err; |
| 4728 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4729 | err = nfs4_set_lock_state(state, request); |
| 4730 | if (err != 0) |
| 4731 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4732 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4733 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4734 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4735 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4736 | switch (err) { |
| 4737 | default: |
| 4738 | goto out; |
| 4739 | case -NFS4ERR_GRACE: |
| 4740 | case -NFS4ERR_DELAY: |
| 4741 | nfs4_handle_exception(server, err, &exception); |
| 4742 | err = 0; |
| 4743 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4744 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4745 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4746 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4749 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4750 | /** |
| 4751 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4752 | * |
| 4753 | * @state: NFSv4 state for an inode |
| 4754 | * |
| 4755 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4756 | * Otherwise a negative NFS4ERR value is returned. |
| 4757 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4758 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4759 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4760 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4761 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4762 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4763 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4764 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4765 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4766 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4767 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4768 | /* Free the stateid unless the server |
| 4769 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4770 | if (status != -NFS4ERR_BAD_STATEID) |
| 4771 | nfs41_free_stateid(server, |
| 4772 | &lsp->ls_stateid); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4773 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4774 | ret = status; |
| 4775 | } |
| 4776 | } |
| 4777 | }; |
| 4778 | |
| 4779 | return ret; |
| 4780 | } |
| 4781 | |
| 4782 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4783 | { |
| 4784 | int status = NFS_OK; |
| 4785 | |
| 4786 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4787 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4788 | if (status != NFS_OK) |
| 4789 | status = nfs4_lock_expired(state, request); |
| 4790 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4791 | } |
| 4792 | #endif |
| 4793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4795 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4796 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4797 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4798 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4800 | if ((fl_flags & FL_POSIX) && |
| 4801 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4802 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4803 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4804 | status = nfs4_set_lock_state(state, request); |
| 4805 | if (status != 0) |
| 4806 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4807 | request->fl_flags |= FL_ACCESS; |
| 4808 | status = do_vfs_lock(request->fl_file, request); |
| 4809 | if (status < 0) |
| 4810 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4811 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4812 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4813 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4814 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4815 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4816 | status = do_vfs_lock(request->fl_file, request); |
| 4817 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4818 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4819 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4820 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4821 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4822 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4823 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4824 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4825 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4826 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4827 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4828 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4829 | out: |
| 4830 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | return status; |
| 4832 | } |
| 4833 | |
| 4834 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4835 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4836 | struct nfs4_exception exception = { |
| 4837 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4838 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4839 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | int err; |
| 4841 | |
| 4842 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4843 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4844 | if (err == -NFS4ERR_DENIED) |
| 4845 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4847 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | } while (exception.retry); |
| 4849 | return err; |
| 4850 | } |
| 4851 | |
| 4852 | static int |
| 4853 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4854 | { |
| 4855 | struct nfs_open_context *ctx; |
| 4856 | struct nfs4_state *state; |
| 4857 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4858 | int status; |
| 4859 | |
| 4860 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4861 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | state = ctx->state; |
| 4863 | |
| 4864 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4865 | return -EINVAL; |
| 4866 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4867 | if (IS_GETLK(cmd)) { |
| 4868 | if (state != NULL) |
| 4869 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4870 | return 0; |
| 4871 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | |
| 4873 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4874 | return -EINVAL; |
| 4875 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4876 | if (request->fl_type == F_UNLCK) { |
| 4877 | if (state != NULL) |
| 4878 | return nfs4_proc_unlck(state, cmd, request); |
| 4879 | return 0; |
| 4880 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4882 | if (state == NULL) |
| 4883 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4884 | /* |
| 4885 | * Don't rely on the VFS having checked the file open mode, |
| 4886 | * since it won't do this for flock() locks. |
| 4887 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4888 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4889 | case F_RDLCK: |
| 4890 | if (!(filp->f_mode & FMODE_READ)) |
| 4891 | return -EBADF; |
| 4892 | break; |
| 4893 | case F_WRLCK: |
| 4894 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4895 | return -EBADF; |
| 4896 | } |
| 4897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | do { |
| 4899 | status = nfs4_proc_setlk(state, cmd, request); |
| 4900 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4901 | break; |
| 4902 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4903 | status = -ERESTARTSYS; |
| 4904 | if (signalled()) |
| 4905 | break; |
| 4906 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | return status; |
| 4908 | } |
| 4909 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4910 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4911 | { |
| 4912 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4913 | struct nfs4_exception exception = { }; |
| 4914 | int err; |
| 4915 | |
| 4916 | err = nfs4_set_lock_state(state, fl); |
| 4917 | if (err != 0) |
| 4918 | goto out; |
| 4919 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4920 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4921 | switch (err) { |
| 4922 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4923 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4924 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4925 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4926 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4927 | goto out; |
| 4928 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4929 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4930 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4931 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4932 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4933 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4934 | case -NFS4ERR_BADSESSION: |
| 4935 | case -NFS4ERR_BADSLOT: |
| 4936 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4937 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4938 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4939 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4940 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4941 | case -ERESTARTSYS: |
| 4942 | /* |
| 4943 | * The show must go on: exit, but mark the |
| 4944 | * stateid as needing recovery. |
| 4945 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4946 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4947 | case -NFS4ERR_ADMIN_REVOKED: |
| 4948 | case -NFS4ERR_BAD_STATEID: |
| 4949 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4950 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4951 | err = 0; |
| 4952 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4953 | case -EKEYEXPIRED: |
| 4954 | /* |
| 4955 | * User RPCSEC_GSS context has expired. |
| 4956 | * We cannot recover this stateid now, so |
| 4957 | * skip it and allow recovery thread to |
| 4958 | * proceed. |
| 4959 | */ |
| 4960 | err = 0; |
| 4961 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4962 | case -ENOMEM: |
| 4963 | case -NFS4ERR_DENIED: |
| 4964 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4965 | err = 0; |
| 4966 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4967 | case -NFS4ERR_DELAY: |
| 4968 | break; |
| 4969 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4970 | err = nfs4_handle_exception(server, err, &exception); |
| 4971 | } while (exception.retry); |
| 4972 | out: |
| 4973 | return err; |
| 4974 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4975 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4976 | struct nfs_release_lockowner_data { |
| 4977 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4978 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4979 | struct nfs_release_lockowner_args args; |
| 4980 | }; |
| 4981 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4982 | static void nfs4_release_lockowner_release(void *calldata) |
| 4983 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4984 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4985 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4986 | kfree(calldata); |
| 4987 | } |
| 4988 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4989 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4990 | .rpc_release = nfs4_release_lockowner_release, |
| 4991 | }; |
| 4992 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4993 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4994 | { |
| 4995 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4996 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4997 | struct rpc_message msg = { |
| 4998 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4999 | }; |
| 5000 | |
| 5001 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5002 | return -EINVAL; |
| 5003 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5004 | if (!data) |
| 5005 | return -ENOMEM; |
| 5006 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5007 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5008 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5009 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5010 | data->args.lock_owner.s_dev = server->s_dev; |
| 5011 | msg.rpc_argp = &data->args; |
| 5012 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5013 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5014 | } |
| 5015 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5016 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5017 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5018 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5019 | const void *buf, size_t buflen, |
| 5020 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5021 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5022 | if (strcmp(key, "") != 0) |
| 5023 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5024 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5025 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5028 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5029 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5030 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5031 | if (strcmp(key, "") != 0) |
| 5032 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5033 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5034 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5035 | } |
| 5036 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5037 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5038 | size_t list_len, const char *name, |
| 5039 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5040 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5041 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5042 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5043 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5044 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5045 | |
| 5046 | if (list && len <= list_len) |
| 5047 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5048 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5049 | } |
| 5050 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5051 | /* |
| 5052 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5053 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5054 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5055 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5056 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5057 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5058 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5059 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5060 | return; |
| 5061 | |
| 5062 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5063 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5064 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5065 | fattr->nlink = 2; |
| 5066 | } |
| 5067 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5068 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5069 | const struct qstr *name, |
| 5070 | struct nfs4_fs_locations *fs_locations, |
| 5071 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5072 | { |
| 5073 | struct nfs_server *server = NFS_SERVER(dir); |
| 5074 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5075 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5076 | }; |
| 5077 | struct nfs4_fs_locations_arg args = { |
| 5078 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5079 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5080 | .page = page, |
| 5081 | .bitmask = bitmask, |
| 5082 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5083 | struct nfs4_fs_locations_res res = { |
| 5084 | .fs_locations = fs_locations, |
| 5085 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5086 | struct rpc_message msg = { |
| 5087 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5088 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5089 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5090 | }; |
| 5091 | int status; |
| 5092 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5093 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5094 | |
| 5095 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5096 | * is not supported */ |
| 5097 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5098 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5099 | else |
| 5100 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5101 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5102 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5103 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5104 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5105 | 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] | 5106 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5107 | return status; |
| 5108 | } |
| 5109 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5110 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5111 | const struct qstr *name, |
| 5112 | struct nfs4_fs_locations *fs_locations, |
| 5113 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5114 | { |
| 5115 | struct nfs4_exception exception = { }; |
| 5116 | int err; |
| 5117 | do { |
| 5118 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5119 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5120 | &exception); |
| 5121 | } while (exception.retry); |
| 5122 | return err; |
| 5123 | } |
| 5124 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5125 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5126 | { |
| 5127 | int status; |
| 5128 | struct nfs4_secinfo_arg args = { |
| 5129 | .dir_fh = NFS_FH(dir), |
| 5130 | .name = name, |
| 5131 | }; |
| 5132 | struct nfs4_secinfo_res res = { |
| 5133 | .flavors = flavors, |
| 5134 | }; |
| 5135 | struct rpc_message msg = { |
| 5136 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5137 | .rpc_argp = &args, |
| 5138 | .rpc_resp = &res, |
| 5139 | }; |
| 5140 | |
| 5141 | dprintk("NFS call secinfo %s\n", name->name); |
| 5142 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5143 | dprintk("NFS reply secinfo: %d\n", status); |
| 5144 | return status; |
| 5145 | } |
| 5146 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5147 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5148 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5149 | { |
| 5150 | struct nfs4_exception exception = { }; |
| 5151 | int err; |
| 5152 | do { |
| 5153 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5154 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5155 | &exception); |
| 5156 | } while (exception.retry); |
| 5157 | return err; |
| 5158 | } |
| 5159 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5160 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5161 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5162 | * Check the exchange flags returned by the server for invalid flags, having |
| 5163 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5164 | * DS flags set. |
| 5165 | */ |
| 5166 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5167 | { |
| 5168 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5169 | goto out_inval; |
| 5170 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5171 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5172 | goto out_inval; |
| 5173 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5174 | goto out_inval; |
| 5175 | return NFS_OK; |
| 5176 | out_inval: |
| 5177 | return -NFS4ERR_INVAL; |
| 5178 | } |
| 5179 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5180 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5181 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5182 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5183 | { |
| 5184 | if (a->server_scope_sz == b->server_scope_sz && |
| 5185 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5186 | return true; |
| 5187 | |
| 5188 | return false; |
| 5189 | } |
| 5190 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5191 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5192 | * nfs4_proc_bind_conn_to_session() |
| 5193 | * |
| 5194 | * The 4.1 client currently uses the same TCP connection for the |
| 5195 | * fore and backchannel. |
| 5196 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5197 | 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] | 5198 | { |
| 5199 | int status; |
| 5200 | struct nfs41_bind_conn_to_session_res res; |
| 5201 | struct rpc_message msg = { |
| 5202 | .rpc_proc = |
| 5203 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5204 | .rpc_argp = clp, |
| 5205 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5206 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5207 | }; |
| 5208 | |
| 5209 | dprintk("--> %s\n", __func__); |
| 5210 | BUG_ON(clp == NULL); |
| 5211 | |
| 5212 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5213 | if (unlikely(res.session == NULL)) { |
| 5214 | status = -ENOMEM; |
| 5215 | goto out; |
| 5216 | } |
| 5217 | |
| 5218 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5219 | if (status == 0) { |
| 5220 | if (memcmp(res.session->sess_id.data, |
| 5221 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5222 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5223 | status = -EIO; |
| 5224 | goto out_session; |
| 5225 | } |
| 5226 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5227 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5228 | __func__); |
| 5229 | status = -EIO; |
| 5230 | goto out_session; |
| 5231 | } |
| 5232 | if (res.use_conn_in_rdma_mode) { |
| 5233 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5234 | __func__); |
| 5235 | status = -EIO; |
| 5236 | goto out_session; |
| 5237 | } |
| 5238 | } |
| 5239 | out_session: |
| 5240 | kfree(res.session); |
| 5241 | out: |
| 5242 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5243 | return status; |
| 5244 | } |
| 5245 | |
| 5246 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5247 | * nfs4_proc_exchange_id() |
| 5248 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5249 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5250 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5251 | * Since the clientid has expired, all compounds using sessions |
| 5252 | * associated with the stale clientid will be returning |
| 5253 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5254 | * be in some phase of session reset. |
| 5255 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5256 | 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] | 5257 | { |
| 5258 | nfs4_verifier verifier; |
| 5259 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5260 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5261 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5262 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5263 | }; |
| 5264 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5265 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5266 | }; |
| 5267 | int status; |
| 5268 | struct rpc_message msg = { |
| 5269 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5270 | .rpc_argp = &args, |
| 5271 | .rpc_resp = &res, |
| 5272 | .rpc_cred = cred, |
| 5273 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5274 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5275 | nfs4_init_boot_verifier(clp, &verifier); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5276 | args.id_len = scnprintf(args.id, sizeof(args.id), |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5277 | "%s/%s", |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5278 | clp->cl_ipaddr, |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5279 | clp->cl_rpcclient->cl_nodename); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5280 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5281 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5282 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5283 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5284 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5285 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5286 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5287 | status = -ENOMEM; |
| 5288 | goto out; |
| 5289 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5290 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5291 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5292 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5293 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5294 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5295 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5296 | } |
| 5297 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5298 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5299 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5300 | status = -ENOMEM; |
| 5301 | goto out_server_scope; |
| 5302 | } |
| 5303 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5304 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5305 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5306 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5307 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5308 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5309 | clp->cl_clientid = res.clientid; |
| 5310 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5311 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5312 | clp->cl_seqid = res.seqid; |
| 5313 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5314 | kfree(clp->cl_serverowner); |
| 5315 | clp->cl_serverowner = res.server_owner; |
| 5316 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5317 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5318 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5319 | kfree(clp->cl_implid); |
| 5320 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5321 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5322 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5323 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5324 | res.server_scope)) { |
| 5325 | dprintk("%s: server_scope mismatch detected\n", |
| 5326 | __func__); |
| 5327 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5328 | kfree(clp->cl_serverscope); |
| 5329 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5330 | } |
| 5331 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5332 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5333 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5334 | goto out; |
| 5335 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5336 | } else |
| 5337 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5338 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5339 | out_server_owner: |
| 5340 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5341 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5342 | kfree(res.server_scope); |
| 5343 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5344 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5345 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5346 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5347 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5348 | clp->cl_implid->date.seconds, |
| 5349 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5350 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5351 | return status; |
| 5352 | } |
| 5353 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5354 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5355 | struct rpc_cred *cred) |
| 5356 | { |
| 5357 | struct rpc_message msg = { |
| 5358 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5359 | .rpc_argp = clp, |
| 5360 | .rpc_cred = cred, |
| 5361 | }; |
| 5362 | int status; |
| 5363 | |
| 5364 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5365 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5366 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5367 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5368 | return status; |
| 5369 | } |
| 5370 | |
| 5371 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5372 | struct rpc_cred *cred) |
| 5373 | { |
| 5374 | unsigned int loop; |
| 5375 | int ret; |
| 5376 | |
| 5377 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5378 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5379 | switch (ret) { |
| 5380 | case -NFS4ERR_DELAY: |
| 5381 | case -NFS4ERR_CLIENTID_BUSY: |
| 5382 | ssleep(1); |
| 5383 | break; |
| 5384 | default: |
| 5385 | return ret; |
| 5386 | } |
| 5387 | } |
| 5388 | return 0; |
| 5389 | } |
| 5390 | |
| 5391 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5392 | { |
| 5393 | struct rpc_cred *cred; |
| 5394 | int ret = 0; |
| 5395 | |
| 5396 | if (clp->cl_mvops->minor_version < 1) |
| 5397 | goto out; |
| 5398 | if (clp->cl_exchange_flags == 0) |
| 5399 | goto out; |
| 5400 | cred = nfs4_get_exchange_id_cred(clp); |
| 5401 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5402 | if (cred) |
| 5403 | put_rpccred(cred); |
| 5404 | switch (ret) { |
| 5405 | case 0: |
| 5406 | case -NFS4ERR_STALE_CLIENTID: |
| 5407 | clp->cl_exchange_flags = 0; |
| 5408 | } |
| 5409 | out: |
| 5410 | return ret; |
| 5411 | } |
| 5412 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5413 | struct nfs4_get_lease_time_data { |
| 5414 | struct nfs4_get_lease_time_args *args; |
| 5415 | struct nfs4_get_lease_time_res *res; |
| 5416 | struct nfs_client *clp; |
| 5417 | }; |
| 5418 | |
| 5419 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5420 | void *calldata) |
| 5421 | { |
| 5422 | int ret; |
| 5423 | struct nfs4_get_lease_time_data *data = |
| 5424 | (struct nfs4_get_lease_time_data *)calldata; |
| 5425 | |
| 5426 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5427 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5428 | /* just setup sequence, do not trigger session recovery |
| 5429 | since we're invoked within one */ |
| 5430 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5431 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5432 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5433 | |
| 5434 | BUG_ON(ret == -EAGAIN); |
| 5435 | rpc_call_start(task); |
| 5436 | dprintk("<-- %s\n", __func__); |
| 5437 | } |
| 5438 | |
| 5439 | /* |
| 5440 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5441 | * from sequence operation or clientid errors. |
| 5442 | */ |
| 5443 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5444 | { |
| 5445 | struct nfs4_get_lease_time_data *data = |
| 5446 | (struct nfs4_get_lease_time_data *)calldata; |
| 5447 | |
| 5448 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5449 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5450 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5451 | switch (task->tk_status) { |
| 5452 | case -NFS4ERR_DELAY: |
| 5453 | case -NFS4ERR_GRACE: |
| 5454 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5455 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5456 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5457 | /* fall through */ |
| 5458 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5459 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5460 | return; |
| 5461 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5462 | dprintk("<-- %s\n", __func__); |
| 5463 | } |
| 5464 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5465 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5466 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5467 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5468 | }; |
| 5469 | |
| 5470 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5471 | { |
| 5472 | struct rpc_task *task; |
| 5473 | struct nfs4_get_lease_time_args args; |
| 5474 | struct nfs4_get_lease_time_res res = { |
| 5475 | .lr_fsinfo = fsinfo, |
| 5476 | }; |
| 5477 | struct nfs4_get_lease_time_data data = { |
| 5478 | .args = &args, |
| 5479 | .res = &res, |
| 5480 | .clp = clp, |
| 5481 | }; |
| 5482 | struct rpc_message msg = { |
| 5483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5484 | .rpc_argp = &args, |
| 5485 | .rpc_resp = &res, |
| 5486 | }; |
| 5487 | struct rpc_task_setup task_setup = { |
| 5488 | .rpc_client = clp->cl_rpcclient, |
| 5489 | .rpc_message = &msg, |
| 5490 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5491 | .callback_data = &data, |
| 5492 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5493 | }; |
| 5494 | int status; |
| 5495 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5496 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5497 | dprintk("--> %s\n", __func__); |
| 5498 | task = rpc_run_task(&task_setup); |
| 5499 | |
| 5500 | if (IS_ERR(task)) |
| 5501 | status = PTR_ERR(task); |
| 5502 | else { |
| 5503 | status = task->tk_status; |
| 5504 | rpc_put_task(task); |
| 5505 | } |
| 5506 | dprintk("<-- %s return %d\n", __func__, status); |
| 5507 | |
| 5508 | return status; |
| 5509 | } |
| 5510 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5511 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5512 | { |
| 5513 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5514 | } |
| 5515 | |
| 5516 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5517 | struct nfs4_slot *new, |
| 5518 | u32 max_slots, |
| 5519 | u32 ivalue) |
| 5520 | { |
| 5521 | struct nfs4_slot *old = NULL; |
| 5522 | u32 i; |
| 5523 | |
| 5524 | spin_lock(&tbl->slot_tbl_lock); |
| 5525 | if (new) { |
| 5526 | old = tbl->slots; |
| 5527 | tbl->slots = new; |
| 5528 | tbl->max_slots = max_slots; |
| 5529 | } |
| 5530 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5531 | for (i = 0; i < tbl->max_slots; i++) |
| 5532 | tbl->slots[i].seq_nr = ivalue; |
| 5533 | spin_unlock(&tbl->slot_tbl_lock); |
| 5534 | kfree(old); |
| 5535 | } |
| 5536 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5537 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5538 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5539 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5540 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5541 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5542 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5543 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5544 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5545 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5546 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5547 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5548 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5549 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5550 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5551 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5552 | if (!new) |
| 5553 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5554 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5555 | ret = 0; |
| 5556 | |
| 5557 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5558 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5559 | tbl, tbl->slots, tbl->max_slots); |
| 5560 | out: |
| 5561 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5562 | return ret; |
| 5563 | } |
| 5564 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5565 | /* Destroy the slot table */ |
| 5566 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5567 | { |
| 5568 | if (session->fc_slot_table.slots != NULL) { |
| 5569 | kfree(session->fc_slot_table.slots); |
| 5570 | session->fc_slot_table.slots = NULL; |
| 5571 | } |
| 5572 | if (session->bc_slot_table.slots != NULL) { |
| 5573 | kfree(session->bc_slot_table.slots); |
| 5574 | session->bc_slot_table.slots = NULL; |
| 5575 | } |
| 5576 | return; |
| 5577 | } |
| 5578 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5579 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5580 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5581 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5582 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5583 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5584 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5585 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5586 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5587 | dprintk("--> %s\n", __func__); |
| 5588 | /* Fore channel */ |
| 5589 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5590 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5591 | if (status) /* -ENOMEM */ |
| 5592 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5593 | /* Back channel */ |
| 5594 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5595 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5596 | if (status && tbl->slots == NULL) |
| 5597 | /* Fore and back channel share a connection so get |
| 5598 | * both slot tables or neither */ |
| 5599 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5600 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5604 | { |
| 5605 | struct nfs4_session *session; |
| 5606 | struct nfs4_slot_table *tbl; |
| 5607 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5608 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5609 | if (!session) |
| 5610 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5611 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5612 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5613 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5614 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5615 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5616 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5617 | |
| 5618 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5619 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5620 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5621 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5622 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5623 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5624 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5625 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5626 | session->clp = clp; |
| 5627 | return session; |
| 5628 | } |
| 5629 | |
| 5630 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5631 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5632 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5633 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5634 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5635 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5636 | nfs4_proc_destroy_session(session, cred); |
| 5637 | if (cred) |
| 5638 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5639 | |
| 5640 | rcu_read_lock(); |
| 5641 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5642 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5643 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5644 | __func__, xprt); |
| 5645 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5646 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5647 | kfree(session); |
| 5648 | } |
| 5649 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5650 | /* |
| 5651 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5652 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5653 | * use them. |
| 5654 | * |
| 5655 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5656 | * always set csa_cachethis to FALSE because the current implementation |
| 5657 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5658 | */ |
| 5659 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5660 | { |
| 5661 | struct nfs4_session *session = args->client->cl_session; |
| 5662 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5663 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5664 | |
| 5665 | if (mxrqst_sz == 0) |
| 5666 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5667 | if (mxresp_sz == 0) |
| 5668 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5669 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5670 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5671 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5672 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5673 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5674 | |
| 5675 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5676 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5677 | __func__, |
| 5678 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5679 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5680 | |
| 5681 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5682 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5683 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5684 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5685 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5686 | args->bc_attrs.max_reqs = 1; |
| 5687 | |
| 5688 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5689 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5690 | __func__, |
| 5691 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5692 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5693 | args->bc_attrs.max_reqs); |
| 5694 | } |
| 5695 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5696 | 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] | 5697 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5698 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5699 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5700 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5701 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5702 | return -EINVAL; |
| 5703 | /* |
| 5704 | * Our requested max_ops is the minimum we need; we're not |
| 5705 | * prepared to break up compounds into smaller pieces than that. |
| 5706 | * So, no point even trying to continue if the server won't |
| 5707 | * cooperate: |
| 5708 | */ |
| 5709 | if (rcvd->max_ops < sent->max_ops) |
| 5710 | return -EINVAL; |
| 5711 | if (rcvd->max_reqs == 0) |
| 5712 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5713 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5714 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5715 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5716 | } |
| 5717 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5718 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5719 | { |
| 5720 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5721 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5722 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5723 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5724 | return -EINVAL; |
| 5725 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5726 | return -EINVAL; |
| 5727 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5728 | return -EINVAL; |
| 5729 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5730 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5731 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5732 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5733 | return -EINVAL; |
| 5734 | return 0; |
| 5735 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5736 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5737 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5738 | struct nfs4_session *session) |
| 5739 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5740 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5741 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5742 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5743 | if (ret) |
| 5744 | return ret; |
| 5745 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5746 | } |
| 5747 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5748 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5749 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5750 | { |
| 5751 | struct nfs4_session *session = clp->cl_session; |
| 5752 | struct nfs41_create_session_args args = { |
| 5753 | .client = clp, |
| 5754 | .cb_program = NFS4_CALLBACK, |
| 5755 | }; |
| 5756 | struct nfs41_create_session_res res = { |
| 5757 | .client = clp, |
| 5758 | }; |
| 5759 | struct rpc_message msg = { |
| 5760 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5761 | .rpc_argp = &args, |
| 5762 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5763 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5764 | }; |
| 5765 | int status; |
| 5766 | |
| 5767 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5768 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5769 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5770 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5771 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5772 | if (!status) |
| 5773 | /* Verify the session's negotiated channel_attrs values */ |
| 5774 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5775 | if (!status) { |
| 5776 | /* Increment the clientid slot sequence id */ |
| 5777 | clp->cl_seqid++; |
| 5778 | } |
| 5779 | |
| 5780 | return status; |
| 5781 | } |
| 5782 | |
| 5783 | /* |
| 5784 | * Issues a CREATE_SESSION operation to the server. |
| 5785 | * It is the responsibility of the caller to verify the session is |
| 5786 | * expired before calling this routine. |
| 5787 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5788 | 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] | 5789 | { |
| 5790 | int status; |
| 5791 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5792 | struct nfs4_session *session = clp->cl_session; |
| 5793 | |
| 5794 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5795 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5796 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5797 | if (status) |
| 5798 | goto out; |
| 5799 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5800 | /* Init or reset the session slot tables */ |
| 5801 | status = nfs4_setup_session_slot_tables(session); |
| 5802 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5803 | if (status) |
| 5804 | goto out; |
| 5805 | |
| 5806 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5807 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5808 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5809 | out: |
| 5810 | dprintk("<-- %s\n", __func__); |
| 5811 | return status; |
| 5812 | } |
| 5813 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5814 | /* |
| 5815 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5816 | * The caller must serialize access to this routine. |
| 5817 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5818 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5819 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5820 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5821 | struct rpc_message msg = { |
| 5822 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5823 | .rpc_argp = session, |
| 5824 | .rpc_cred = cred, |
| 5825 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5826 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5827 | |
| 5828 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5829 | |
| 5830 | /* session is still being setup */ |
| 5831 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5832 | return status; |
| 5833 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5834 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5835 | |
| 5836 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5837 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5838 | "Session has been destroyed regardless...\n", status); |
| 5839 | |
| 5840 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5841 | return status; |
| 5842 | } |
| 5843 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5844 | /* |
| 5845 | * With sessions, the client is not marked ready until after a |
| 5846 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 5847 | * |
| 5848 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 5849 | * other versions of NFS can be tried. |
| 5850 | */ |
| 5851 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 5852 | { |
| 5853 | int ret; |
| 5854 | |
| 5855 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 5856 | ret = nfs4_client_recover_expired_lease(clp); |
| 5857 | if (ret) |
| 5858 | return ret; |
| 5859 | } |
| 5860 | if (clp->cl_cons_state < NFS_CS_READY) |
| 5861 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 5862 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5863 | return 0; |
| 5864 | } |
| 5865 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5866 | int nfs4_init_session(struct nfs_server *server) |
| 5867 | { |
| 5868 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5869 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5870 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5871 | |
| 5872 | if (!nfs4_has_session(clp)) |
| 5873 | return 0; |
| 5874 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5875 | session = clp->cl_session; |
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)) { |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5878 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5879 | rsize = server->rsize; |
| 5880 | if (rsize == 0) |
| 5881 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5882 | wsize = server->wsize; |
| 5883 | if (wsize == 0) |
| 5884 | wsize = NFS_MAX_FILE_IO_SIZE; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5885 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5886 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5887 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
| 5888 | } |
| 5889 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5890 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5891 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5892 | } |
| 5893 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5894 | 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] | 5895 | { |
| 5896 | struct nfs4_session *session = clp->cl_session; |
| 5897 | int ret; |
| 5898 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5899 | spin_lock(&clp->cl_lock); |
| 5900 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 5901 | /* |
| 5902 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 5903 | * DS lease to be equal to the MDS lease. |
| 5904 | */ |
| 5905 | clp->cl_lease_time = lease_time; |
| 5906 | clp->cl_last_renewal = jiffies; |
| 5907 | } |
| 5908 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5909 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5910 | ret = nfs41_check_session_ready(clp); |
| 5911 | if (ret) |
| 5912 | return ret; |
| 5913 | /* Test for the DS role */ |
| 5914 | if (!is_ds_client(clp)) |
| 5915 | return -ENODEV; |
| 5916 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5917 | } |
| 5918 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5919 | |
| 5920 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5921 | /* |
| 5922 | * Renew the cl_session lease. |
| 5923 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5924 | struct nfs4_sequence_data { |
| 5925 | struct nfs_client *clp; |
| 5926 | struct nfs4_sequence_args args; |
| 5927 | struct nfs4_sequence_res res; |
| 5928 | }; |
| 5929 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5930 | static void nfs41_sequence_release(void *data) |
| 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; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5934 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5935 | if (atomic_read(&clp->cl_count) > 1) |
| 5936 | nfs4_schedule_state_renewal(clp); |
| 5937 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5938 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5939 | } |
| 5940 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5941 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5942 | { |
| 5943 | switch(task->tk_status) { |
| 5944 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5945 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5946 | return -EAGAIN; |
| 5947 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5948 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5949 | } |
| 5950 | return 0; |
| 5951 | } |
| 5952 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5953 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 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 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5958 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5959 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5960 | |
| 5961 | if (task->tk_status < 0) { |
| 5962 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5963 | if (atomic_read(&clp->cl_count) == 1) |
| 5964 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5965 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5966 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5967 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5968 | return; |
| 5969 | } |
| 5970 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5971 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5972 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5973 | dprintk("<-- %s\n", __func__); |
| 5974 | } |
| 5975 | |
| 5976 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5977 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5978 | struct nfs4_sequence_data *calldata = data; |
| 5979 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5980 | struct nfs4_sequence_args *args; |
| 5981 | struct nfs4_sequence_res *res; |
| 5982 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5983 | args = task->tk_msg.rpc_argp; |
| 5984 | res = task->tk_msg.rpc_resp; |
| 5985 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5986 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5987 | return; |
| 5988 | rpc_call_start(task); |
| 5989 | } |
| 5990 | |
| 5991 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5992 | .rpc_call_done = nfs41_sequence_call_done, |
| 5993 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5994 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5995 | }; |
| 5996 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5997 | 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] | 5998 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5999 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6000 | struct rpc_message msg = { |
| 6001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6002 | .rpc_cred = cred, |
| 6003 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6004 | struct rpc_task_setup task_setup_data = { |
| 6005 | .rpc_client = clp->cl_rpcclient, |
| 6006 | .rpc_message = &msg, |
| 6007 | .callback_ops = &nfs41_sequence_ops, |
| 6008 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6009 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6010 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6011 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6012 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6013 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6014 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6015 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6016 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6017 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6018 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6019 | msg.rpc_argp = &calldata->args; |
| 6020 | msg.rpc_resp = &calldata->res; |
| 6021 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6022 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6023 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6024 | return rpc_run_task(&task_setup_data); |
| 6025 | } |
| 6026 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6027 | 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] | 6028 | { |
| 6029 | struct rpc_task *task; |
| 6030 | int ret = 0; |
| 6031 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6032 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6033 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6034 | task = _nfs41_proc_sequence(clp, cred); |
| 6035 | if (IS_ERR(task)) |
| 6036 | ret = PTR_ERR(task); |
| 6037 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6038 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6039 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6040 | return ret; |
| 6041 | } |
| 6042 | |
| 6043 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6044 | { |
| 6045 | struct rpc_task *task; |
| 6046 | int ret; |
| 6047 | |
| 6048 | task = _nfs41_proc_sequence(clp, cred); |
| 6049 | if (IS_ERR(task)) { |
| 6050 | ret = PTR_ERR(task); |
| 6051 | goto out; |
| 6052 | } |
| 6053 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6054 | if (!ret) { |
| 6055 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6056 | |
| 6057 | if (task->tk_status == 0) |
| 6058 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6059 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6060 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6061 | rpc_put_task(task); |
| 6062 | out: |
| 6063 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6064 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6065 | } |
| 6066 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6067 | struct nfs4_reclaim_complete_data { |
| 6068 | struct nfs_client *clp; |
| 6069 | struct nfs41_reclaim_complete_args arg; |
| 6070 | struct nfs41_reclaim_complete_res res; |
| 6071 | }; |
| 6072 | |
| 6073 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6074 | { |
| 6075 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6076 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6077 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6078 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6079 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6080 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6081 | return; |
| 6082 | |
| 6083 | rpc_call_start(task); |
| 6084 | } |
| 6085 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6086 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6087 | { |
| 6088 | switch(task->tk_status) { |
| 6089 | case 0: |
| 6090 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6091 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6092 | break; |
| 6093 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6094 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6095 | /* fall through */ |
| 6096 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6097 | return -EAGAIN; |
| 6098 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6099 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6100 | } |
| 6101 | return 0; |
| 6102 | } |
| 6103 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6104 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6105 | { |
| 6106 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6107 | struct nfs_client *clp = calldata->clp; |
| 6108 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6109 | |
| 6110 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6111 | if (!nfs41_sequence_done(task, res)) |
| 6112 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6113 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6114 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6115 | rpc_restart_call_prepare(task); |
| 6116 | return; |
| 6117 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6118 | dprintk("<-- %s\n", __func__); |
| 6119 | } |
| 6120 | |
| 6121 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6122 | { |
| 6123 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6124 | |
| 6125 | kfree(calldata); |
| 6126 | } |
| 6127 | |
| 6128 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6129 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6130 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6131 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6132 | }; |
| 6133 | |
| 6134 | /* |
| 6135 | * Issue a global reclaim complete. |
| 6136 | */ |
| 6137 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6138 | { |
| 6139 | struct nfs4_reclaim_complete_data *calldata; |
| 6140 | struct rpc_task *task; |
| 6141 | struct rpc_message msg = { |
| 6142 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6143 | }; |
| 6144 | struct rpc_task_setup task_setup_data = { |
| 6145 | .rpc_client = clp->cl_rpcclient, |
| 6146 | .rpc_message = &msg, |
| 6147 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6148 | .flags = RPC_TASK_ASYNC, |
| 6149 | }; |
| 6150 | int status = -ENOMEM; |
| 6151 | |
| 6152 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6153 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6154 | if (calldata == NULL) |
| 6155 | goto out; |
| 6156 | calldata->clp = clp; |
| 6157 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6158 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6159 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6160 | msg.rpc_argp = &calldata->arg; |
| 6161 | msg.rpc_resp = &calldata->res; |
| 6162 | task_setup_data.callback_data = calldata; |
| 6163 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6164 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6165 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6166 | goto out; |
| 6167 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6168 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6169 | if (status == 0) |
| 6170 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6171 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6172 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6173 | out: |
| 6174 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6175 | return status; |
| 6176 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6177 | |
| 6178 | static void |
| 6179 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6180 | { |
| 6181 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6182 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6183 | |
| 6184 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6185 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6186 | * right now covering the LAYOUTGET we are about to send. |
| 6187 | * However, that is not so catastrophic, and there seems |
| 6188 | * to be no way to prevent it completely. |
| 6189 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6190 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6191 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6192 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6193 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6194 | NFS_I(lgp->args.inode)->layout, |
| 6195 | lgp->args.ctx->state)) { |
| 6196 | rpc_exit(task, NFS4_OK); |
| 6197 | return; |
| 6198 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6199 | rpc_call_start(task); |
| 6200 | } |
| 6201 | |
| 6202 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6203 | { |
| 6204 | struct nfs4_layoutget *lgp = calldata; |
| 6205 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6206 | |
| 6207 | dprintk("--> %s\n", __func__); |
| 6208 | |
| 6209 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 6210 | return; |
| 6211 | |
| 6212 | switch (task->tk_status) { |
| 6213 | case 0: |
| 6214 | break; |
| 6215 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6216 | case -NFS4ERR_RECALLCONFLICT: |
| 6217 | task->tk_status = -NFS4ERR_DELAY; |
| 6218 | /* Fall through */ |
| 6219 | default: |
| 6220 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6221 | rpc_restart_call_prepare(task); |
| 6222 | return; |
| 6223 | } |
| 6224 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6225 | dprintk("<-- %s\n", __func__); |
| 6226 | } |
| 6227 | |
| 6228 | static void nfs4_layoutget_release(void *calldata) |
| 6229 | { |
| 6230 | struct nfs4_layoutget *lgp = calldata; |
| 6231 | |
| 6232 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6233 | put_nfs_open_context(lgp->args.ctx); |
| 6234 | kfree(calldata); |
| 6235 | dprintk("<-- %s\n", __func__); |
| 6236 | } |
| 6237 | |
| 6238 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6239 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6240 | .rpc_call_done = nfs4_layoutget_done, |
| 6241 | .rpc_release = nfs4_layoutget_release, |
| 6242 | }; |
| 6243 | |
| 6244 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 6245 | { |
| 6246 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6247 | struct rpc_task *task; |
| 6248 | struct rpc_message msg = { |
| 6249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6250 | .rpc_argp = &lgp->args, |
| 6251 | .rpc_resp = &lgp->res, |
| 6252 | }; |
| 6253 | struct rpc_task_setup task_setup_data = { |
| 6254 | .rpc_client = server->client, |
| 6255 | .rpc_message = &msg, |
| 6256 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6257 | .callback_data = lgp, |
| 6258 | .flags = RPC_TASK_ASYNC, |
| 6259 | }; |
| 6260 | int status = 0; |
| 6261 | |
| 6262 | dprintk("--> %s\n", __func__); |
| 6263 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6264 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6265 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6266 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6267 | task = rpc_run_task(&task_setup_data); |
| 6268 | if (IS_ERR(task)) |
| 6269 | return PTR_ERR(task); |
| 6270 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6271 | if (status == 0) |
| 6272 | status = task->tk_status; |
| 6273 | if (status == 0) |
| 6274 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6275 | rpc_put_task(task); |
| 6276 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6277 | return status; |
| 6278 | } |
| 6279 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6280 | static void |
| 6281 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6282 | { |
| 6283 | struct nfs4_layoutreturn *lrp = calldata; |
| 6284 | |
| 6285 | dprintk("--> %s\n", __func__); |
| 6286 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6287 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6288 | return; |
| 6289 | rpc_call_start(task); |
| 6290 | } |
| 6291 | |
| 6292 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6293 | { |
| 6294 | struct nfs4_layoutreturn *lrp = calldata; |
| 6295 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6296 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6297 | |
| 6298 | dprintk("--> %s\n", __func__); |
| 6299 | |
| 6300 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6301 | return; |
| 6302 | |
| 6303 | server = NFS_SERVER(lrp->args.inode); |
| 6304 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6305 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6306 | return; |
| 6307 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6308 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6309 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6310 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6311 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6312 | } else |
| 6313 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 6314 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6315 | lo->plh_block_lgets--; |
| 6316 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6317 | dprintk("<-- %s\n", __func__); |
| 6318 | } |
| 6319 | |
| 6320 | static void nfs4_layoutreturn_release(void *calldata) |
| 6321 | { |
| 6322 | struct nfs4_layoutreturn *lrp = calldata; |
| 6323 | |
| 6324 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6325 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6326 | kfree(calldata); |
| 6327 | dprintk("<-- %s\n", __func__); |
| 6328 | } |
| 6329 | |
| 6330 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6331 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6332 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6333 | .rpc_release = nfs4_layoutreturn_release, |
| 6334 | }; |
| 6335 | |
| 6336 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6337 | { |
| 6338 | struct rpc_task *task; |
| 6339 | struct rpc_message msg = { |
| 6340 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6341 | .rpc_argp = &lrp->args, |
| 6342 | .rpc_resp = &lrp->res, |
| 6343 | }; |
| 6344 | struct rpc_task_setup task_setup_data = { |
| 6345 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6346 | .rpc_message = &msg, |
| 6347 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6348 | .callback_data = lrp, |
| 6349 | }; |
| 6350 | int status; |
| 6351 | |
| 6352 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6353 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6354 | task = rpc_run_task(&task_setup_data); |
| 6355 | if (IS_ERR(task)) |
| 6356 | return PTR_ERR(task); |
| 6357 | status = task->tk_status; |
| 6358 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6359 | rpc_put_task(task); |
| 6360 | return status; |
| 6361 | } |
| 6362 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6363 | /* |
| 6364 | * Retrieve the list of Data Server devices from the MDS. |
| 6365 | */ |
| 6366 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6367 | const struct nfs_fh *fh, |
| 6368 | struct pnfs_devicelist *devlist) |
| 6369 | { |
| 6370 | struct nfs4_getdevicelist_args args = { |
| 6371 | .fh = fh, |
| 6372 | .layoutclass = server->pnfs_curr_ld->id, |
| 6373 | }; |
| 6374 | struct nfs4_getdevicelist_res res = { |
| 6375 | .devlist = devlist, |
| 6376 | }; |
| 6377 | struct rpc_message msg = { |
| 6378 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6379 | .rpc_argp = &args, |
| 6380 | .rpc_resp = &res, |
| 6381 | }; |
| 6382 | int status; |
| 6383 | |
| 6384 | dprintk("--> %s\n", __func__); |
| 6385 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6386 | &res.seq_res, 0); |
| 6387 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6388 | return status; |
| 6389 | } |
| 6390 | |
| 6391 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6392 | const struct nfs_fh *fh, |
| 6393 | struct pnfs_devicelist *devlist) |
| 6394 | { |
| 6395 | struct nfs4_exception exception = { }; |
| 6396 | int err; |
| 6397 | |
| 6398 | do { |
| 6399 | err = nfs4_handle_exception(server, |
| 6400 | _nfs4_getdevicelist(server, fh, devlist), |
| 6401 | &exception); |
| 6402 | } while (exception.retry); |
| 6403 | |
| 6404 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6405 | err, devlist->num_devs); |
| 6406 | |
| 6407 | return err; |
| 6408 | } |
| 6409 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6410 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6411 | static int |
| 6412 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6413 | { |
| 6414 | struct nfs4_getdeviceinfo_args args = { |
| 6415 | .pdev = pdev, |
| 6416 | }; |
| 6417 | struct nfs4_getdeviceinfo_res res = { |
| 6418 | .pdev = pdev, |
| 6419 | }; |
| 6420 | struct rpc_message msg = { |
| 6421 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6422 | .rpc_argp = &args, |
| 6423 | .rpc_resp = &res, |
| 6424 | }; |
| 6425 | int status; |
| 6426 | |
| 6427 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6428 | 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] | 6429 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6430 | |
| 6431 | return status; |
| 6432 | } |
| 6433 | |
| 6434 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6435 | { |
| 6436 | struct nfs4_exception exception = { }; |
| 6437 | int err; |
| 6438 | |
| 6439 | do { |
| 6440 | err = nfs4_handle_exception(server, |
| 6441 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6442 | &exception); |
| 6443 | } while (exception.retry); |
| 6444 | return err; |
| 6445 | } |
| 6446 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6447 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6448 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6449 | { |
| 6450 | struct nfs4_layoutcommit_data *data = calldata; |
| 6451 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6452 | |
| 6453 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6454 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6455 | return; |
| 6456 | rpc_call_start(task); |
| 6457 | } |
| 6458 | |
| 6459 | static void |
| 6460 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6461 | { |
| 6462 | struct nfs4_layoutcommit_data *data = calldata; |
| 6463 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6464 | |
| 6465 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6466 | return; |
| 6467 | |
| 6468 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6469 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6470 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6471 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6472 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6473 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6474 | break; |
| 6475 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6476 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6477 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6478 | break; |
| 6479 | default: |
| 6480 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6481 | rpc_restart_call_prepare(task); |
| 6482 | return; |
| 6483 | } |
| 6484 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6485 | } |
| 6486 | |
| 6487 | static void nfs4_layoutcommit_release(void *calldata) |
| 6488 | { |
| 6489 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6490 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6491 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6492 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6493 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6494 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6495 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6496 | list_del_init(&lseg->pls_lc_list); |
| 6497 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6498 | &lseg->pls_flags)) |
| 6499 | put_lseg(lseg); |
| 6500 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6501 | |
| 6502 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6503 | smp_mb__after_clear_bit(); |
| 6504 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6505 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6506 | put_rpccred(data->cred); |
| 6507 | kfree(data); |
| 6508 | } |
| 6509 | |
| 6510 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6511 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6512 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6513 | .rpc_release = nfs4_layoutcommit_release, |
| 6514 | }; |
| 6515 | |
| 6516 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6517 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6518 | { |
| 6519 | struct rpc_message msg = { |
| 6520 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6521 | .rpc_argp = &data->args, |
| 6522 | .rpc_resp = &data->res, |
| 6523 | .rpc_cred = data->cred, |
| 6524 | }; |
| 6525 | struct rpc_task_setup task_setup_data = { |
| 6526 | .task = &data->task, |
| 6527 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6528 | .rpc_message = &msg, |
| 6529 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6530 | .callback_data = data, |
| 6531 | .flags = RPC_TASK_ASYNC, |
| 6532 | }; |
| 6533 | struct rpc_task *task; |
| 6534 | int status = 0; |
| 6535 | |
| 6536 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6537 | "lbw: %llu inode %lu\n", |
| 6538 | data->task.tk_pid, sync, |
| 6539 | data->args.lastbytewritten, |
| 6540 | data->args.inode->i_ino); |
| 6541 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6542 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6543 | task = rpc_run_task(&task_setup_data); |
| 6544 | if (IS_ERR(task)) |
| 6545 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6546 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6547 | goto out; |
| 6548 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6549 | if (status != 0) |
| 6550 | goto out; |
| 6551 | status = task->tk_status; |
| 6552 | out: |
| 6553 | dprintk("%s: status %d\n", __func__, status); |
| 6554 | rpc_put_task(task); |
| 6555 | return status; |
| 6556 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6557 | |
| 6558 | static int |
| 6559 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6560 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6561 | { |
| 6562 | struct nfs41_secinfo_no_name_args args = { |
| 6563 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6564 | }; |
| 6565 | struct nfs4_secinfo_res res = { |
| 6566 | .flavors = flavors, |
| 6567 | }; |
| 6568 | struct rpc_message msg = { |
| 6569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6570 | .rpc_argp = &args, |
| 6571 | .rpc_resp = &res, |
| 6572 | }; |
| 6573 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6574 | } |
| 6575 | |
| 6576 | static int |
| 6577 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6578 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6579 | { |
| 6580 | struct nfs4_exception exception = { }; |
| 6581 | int err; |
| 6582 | do { |
| 6583 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6584 | switch (err) { |
| 6585 | case 0: |
| 6586 | case -NFS4ERR_WRONGSEC: |
| 6587 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6588 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6589 | default: |
| 6590 | err = nfs4_handle_exception(server, err, &exception); |
| 6591 | } |
| 6592 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6593 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6594 | return err; |
| 6595 | } |
| 6596 | |
| 6597 | static int |
| 6598 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6599 | struct nfs_fsinfo *info) |
| 6600 | { |
| 6601 | int err; |
| 6602 | struct page *page; |
| 6603 | rpc_authflavor_t flavor; |
| 6604 | struct nfs4_secinfo_flavors *flavors; |
| 6605 | |
| 6606 | page = alloc_page(GFP_KERNEL); |
| 6607 | if (!page) { |
| 6608 | err = -ENOMEM; |
| 6609 | goto out; |
| 6610 | } |
| 6611 | |
| 6612 | flavors = page_address(page); |
| 6613 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6614 | |
| 6615 | /* |
| 6616 | * Fall back on "guess and check" method if |
| 6617 | * the server doesn't support SECINFO_NO_NAME |
| 6618 | */ |
| 6619 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6620 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6621 | goto out_freepage; |
| 6622 | } |
| 6623 | if (err) |
| 6624 | goto out_freepage; |
| 6625 | |
| 6626 | flavor = nfs_find_best_sec(flavors); |
| 6627 | if (err == 0) |
| 6628 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6629 | |
| 6630 | out_freepage: |
| 6631 | put_page(page); |
| 6632 | if (err == -EACCES) |
| 6633 | return -EPERM; |
| 6634 | out: |
| 6635 | return err; |
| 6636 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6637 | |
| 6638 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6639 | { |
| 6640 | int status; |
| 6641 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6642 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6643 | }; |
| 6644 | struct nfs41_test_stateid_res res; |
| 6645 | struct rpc_message msg = { |
| 6646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6647 | .rpc_argp = &args, |
| 6648 | .rpc_resp = &res, |
| 6649 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6650 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6651 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6652 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6653 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6654 | if (status != NFS_OK) { |
| 6655 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6656 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6657 | } |
| 6658 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6659 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6660 | } |
| 6661 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6662 | /** |
| 6663 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6664 | * |
| 6665 | * @server: server / transport on which to perform the operation |
| 6666 | * @stateid: state ID to test |
| 6667 | * |
| 6668 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6669 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6670 | * failed or the state ID is not currently valid. |
| 6671 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6672 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6673 | { |
| 6674 | struct nfs4_exception exception = { }; |
| 6675 | int err; |
| 6676 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6677 | err = _nfs41_test_stateid(server, stateid); |
| 6678 | if (err != -NFS4ERR_DELAY) |
| 6679 | break; |
| 6680 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6681 | } while (exception.retry); |
| 6682 | return err; |
| 6683 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6684 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6685 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6686 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6687 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6688 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6689 | }; |
| 6690 | struct nfs41_free_stateid_res res; |
| 6691 | struct rpc_message msg = { |
| 6692 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6693 | .rpc_argp = &args, |
| 6694 | .rpc_resp = &res, |
| 6695 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6696 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6697 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6698 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6699 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6700 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6701 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6702 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6703 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6704 | } |
| 6705 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6706 | /** |
| 6707 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6708 | * |
| 6709 | * @server: server / transport on which to perform the operation |
| 6710 | * @stateid: state ID to release |
| 6711 | * |
| 6712 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6713 | * negative NFS4ERR value is returned. |
| 6714 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6715 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6716 | { |
| 6717 | struct nfs4_exception exception = { }; |
| 6718 | int err; |
| 6719 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6720 | err = _nfs4_free_stateid(server, stateid); |
| 6721 | if (err != -NFS4ERR_DELAY) |
| 6722 | break; |
| 6723 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6724 | } while (exception.retry); |
| 6725 | return err; |
| 6726 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6727 | |
| 6728 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6729 | const nfs4_stateid *s2) |
| 6730 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6731 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6732 | return false; |
| 6733 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6734 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6735 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6736 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6737 | return true; |
| 6738 | |
| 6739 | return false; |
| 6740 | } |
| 6741 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6742 | #endif /* CONFIG_NFS_V4_1 */ |
| 6743 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6744 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6745 | const nfs4_stateid *s2) |
| 6746 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6747 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6748 | } |
| 6749 | |
| 6750 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6751 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6752 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6753 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6754 | .recover_open = nfs4_open_reclaim, |
| 6755 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6756 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6757 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6758 | }; |
| 6759 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6760 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6761 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6762 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6763 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6764 | .recover_open = nfs4_open_reclaim, |
| 6765 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6766 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6767 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6768 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6769 | }; |
| 6770 | #endif /* CONFIG_NFS_V4_1 */ |
| 6771 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6772 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6773 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6774 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6775 | .recover_open = nfs4_open_expired, |
| 6776 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6777 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6778 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6779 | }; |
| 6780 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6781 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6782 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6783 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6784 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6785 | .recover_open = nfs41_open_expired, |
| 6786 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6787 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6788 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6789 | }; |
| 6790 | #endif /* CONFIG_NFS_V4_1 */ |
| 6791 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6792 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6793 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6794 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6795 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6796 | }; |
| 6797 | |
| 6798 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6799 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6800 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6801 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6802 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6803 | }; |
| 6804 | #endif |
| 6805 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6806 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6807 | .minor_version = 0, |
| 6808 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6809 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6810 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6811 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6812 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6813 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6814 | }; |
| 6815 | |
| 6816 | #if defined(CONFIG_NFS_V4_1) |
| 6817 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6818 | .minor_version = 1, |
| 6819 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6820 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6821 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6822 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6823 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6824 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6825 | }; |
| 6826 | #endif |
| 6827 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6828 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6829 | [0] = &nfs_v4_0_minor_ops, |
| 6830 | #if defined(CONFIG_NFS_V4_1) |
| 6831 | [1] = &nfs_v4_1_minor_ops, |
| 6832 | #endif |
| 6833 | }; |
| 6834 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6835 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6836 | .create = nfs_create, |
| 6837 | .lookup = nfs_lookup, |
| 6838 | .atomic_open = nfs_atomic_open, |
| 6839 | .link = nfs_link, |
| 6840 | .unlink = nfs_unlink, |
| 6841 | .symlink = nfs_symlink, |
| 6842 | .mkdir = nfs_mkdir, |
| 6843 | .rmdir = nfs_rmdir, |
| 6844 | .mknod = nfs_mknod, |
| 6845 | .rename = nfs_rename, |
| 6846 | .permission = nfs_permission, |
| 6847 | .getattr = nfs_getattr, |
| 6848 | .setattr = nfs_setattr, |
| 6849 | .getxattr = generic_getxattr, |
| 6850 | .setxattr = generic_setxattr, |
| 6851 | .listxattr = generic_listxattr, |
| 6852 | .removexattr = generic_removexattr, |
| 6853 | }; |
| 6854 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6855 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6856 | .permission = nfs_permission, |
| 6857 | .getattr = nfs_getattr, |
| 6858 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6859 | .getxattr = generic_getxattr, |
| 6860 | .setxattr = generic_setxattr, |
| 6861 | .listxattr = generic_listxattr, |
| 6862 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6863 | }; |
| 6864 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6865 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | .version = 4, /* protocol version */ |
| 6867 | .dentry_ops = &nfs4_dentry_operations, |
| 6868 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6869 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6870 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6871 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6872 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6873 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6874 | .getattr = nfs4_proc_getattr, |
| 6875 | .setattr = nfs4_proc_setattr, |
| 6876 | .lookup = nfs4_proc_lookup, |
| 6877 | .access = nfs4_proc_access, |
| 6878 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | .create = nfs4_proc_create, |
| 6880 | .remove = nfs4_proc_remove, |
| 6881 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6882 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6883 | .unlink_done = nfs4_proc_unlink_done, |
| 6884 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6885 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6886 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6887 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6888 | .link = nfs4_proc_link, |
| 6889 | .symlink = nfs4_proc_symlink, |
| 6890 | .mkdir = nfs4_proc_mkdir, |
| 6891 | .rmdir = nfs4_proc_remove, |
| 6892 | .readdir = nfs4_proc_readdir, |
| 6893 | .mknod = nfs4_proc_mknod, |
| 6894 | .statfs = nfs4_proc_statfs, |
| 6895 | .fsinfo = nfs4_proc_fsinfo, |
| 6896 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6897 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6898 | .decode_dirent = nfs4_decode_dirent, |
| 6899 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 6900 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6901 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6902 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6903 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 6904 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6905 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6906 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6907 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6908 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6909 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6910 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6911 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6912 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6913 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 6914 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 6915 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 6916 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6917 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 6918 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame^] | 6919 | .create_server = nfs4_create_server, |
| 6920 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6921 | }; |
| 6922 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6923 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6924 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6925 | .list = nfs4_xattr_list_nfs4_acl, |
| 6926 | .get = nfs4_xattr_get_nfs4_acl, |
| 6927 | .set = nfs4_xattr_set_nfs4_acl, |
| 6928 | }; |
| 6929 | |
| 6930 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6931 | &nfs4_xattr_nfs4_acl_handler, |
| 6932 | NULL |
| 6933 | }; |
| 6934 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6935 | module_param(max_session_slots, ushort, 0644); |
| 6936 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6937 | "requests the client will negotiate"); |
| 6938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6939 | /* |
| 6940 | * Local variables: |
| 6941 | * c-basic-offset: 8 |
| 6942 | * End: |
| 6943 | */ |