Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 46 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 55 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 56 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 57 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 58 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 59 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 61 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 63 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 64 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 65 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 66 | #include "pnfs.h" |
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 | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 105 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 107 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 108 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 110 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* |
| 114 | * This is our standard bitmap for GETATTR requests. |
| 115 | */ |
| 116 | const u32 nfs4_fattr_bitmap[2] = { |
| 117 | FATTR4_WORD0_TYPE |
| 118 | | FATTR4_WORD0_CHANGE |
| 119 | | FATTR4_WORD0_SIZE |
| 120 | | FATTR4_WORD0_FSID |
| 121 | | FATTR4_WORD0_FILEID, |
| 122 | FATTR4_WORD1_MODE |
| 123 | | FATTR4_WORD1_NUMLINKS |
| 124 | | FATTR4_WORD1_OWNER |
| 125 | | FATTR4_WORD1_OWNER_GROUP |
| 126 | | FATTR4_WORD1_RAWDEV |
| 127 | | FATTR4_WORD1_SPACE_USED |
| 128 | | FATTR4_WORD1_TIME_ACCESS |
| 129 | | FATTR4_WORD1_TIME_METADATA |
| 130 | | FATTR4_WORD1_TIME_MODIFY |
| 131 | }; |
| 132 | |
| 133 | const u32 nfs4_statfs_bitmap[2] = { |
| 134 | FATTR4_WORD0_FILES_AVAIL |
| 135 | | FATTR4_WORD0_FILES_FREE |
| 136 | | FATTR4_WORD0_FILES_TOTAL, |
| 137 | FATTR4_WORD1_SPACE_AVAIL |
| 138 | | FATTR4_WORD1_SPACE_FREE |
| 139 | | FATTR4_WORD1_SPACE_TOTAL |
| 140 | }; |
| 141 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 142 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | FATTR4_WORD0_MAXLINK |
| 144 | | FATTR4_WORD0_MAXNAME, |
| 145 | 0 |
| 146 | }; |
| 147 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 148 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | | FATTR4_WORD0_MAXREAD |
| 150 | | FATTR4_WORD0_MAXWRITE |
| 151 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 152 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 153 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 154 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 157 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 158 | FATTR4_WORD0_TYPE |
| 159 | | FATTR4_WORD0_CHANGE |
| 160 | | FATTR4_WORD0_SIZE |
| 161 | | FATTR4_WORD0_FSID |
| 162 | | FATTR4_WORD0_FILEID |
| 163 | | FATTR4_WORD0_FS_LOCATIONS, |
| 164 | FATTR4_WORD1_MODE |
| 165 | | FATTR4_WORD1_NUMLINKS |
| 166 | | FATTR4_WORD1_OWNER |
| 167 | | FATTR4_WORD1_OWNER_GROUP |
| 168 | | FATTR4_WORD1_RAWDEV |
| 169 | | FATTR4_WORD1_SPACE_USED |
| 170 | | FATTR4_WORD1_TIME_ACCESS |
| 171 | | FATTR4_WORD1_TIME_METADATA |
| 172 | | FATTR4_WORD1_TIME_MODIFY |
| 173 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 174 | }; |
| 175 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 176 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | struct nfs4_readdir_arg *readdir) |
| 178 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 179 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | BUG_ON(readdir->count < 80); |
| 182 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 183 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | readdir->cookie = 0; |
| 189 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 190 | if (cookie == 2) |
| 191 | return; |
| 192 | |
| 193 | /* |
| 194 | * NFSv4 servers do not return entries for '.' and '..' |
| 195 | * Therefore, we fake these entries here. We let '.' |
| 196 | * have cookie 0 and '..' have cookie 1. Note that |
| 197 | * when talking to the server, we always send cookie 0 |
| 198 | * instead of 1 or 2. |
| 199 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 200 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if (cookie == 0) { |
| 203 | *p++ = xdr_one; /* next */ |
| 204 | *p++ = xdr_zero; /* cookie, first word */ |
| 205 | *p++ = xdr_one; /* cookie, second word */ |
| 206 | *p++ = xdr_one; /* entry len */ |
| 207 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 208 | p++; |
| 209 | *p++ = xdr_one; /* bitmap length */ |
| 210 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 211 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 212 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | *p++ = xdr_one; /* next */ |
| 216 | *p++ = xdr_zero; /* cookie, first word */ |
| 217 | *p++ = xdr_two; /* cookie, second word */ |
| 218 | *p++ = xdr_two; /* entry len */ |
| 219 | memcpy(p, "..\0\0", 4); /* entry */ |
| 220 | p++; |
| 221 | *p++ = xdr_one; /* bitmap length */ |
| 222 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 223 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 224 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | readdir->pgbase = (char *)p - (char *)start; |
| 227 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 228 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 231 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 232 | { |
| 233 | int res; |
| 234 | |
| 235 | might_sleep(); |
| 236 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 237 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 238 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 239 | return res; |
| 240 | } |
| 241 | |
| 242 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 243 | { |
| 244 | int res = 0; |
| 245 | |
| 246 | might_sleep(); |
| 247 | |
| 248 | if (*timeout <= 0) |
| 249 | *timeout = NFS4_POLL_RETRY_MIN; |
| 250 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 251 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 252 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 253 | if (fatal_signal_pending(current)) |
| 254 | res = -ERESTARTSYS; |
| 255 | *timeout <<= 1; |
| 256 | return res; |
| 257 | } |
| 258 | |
| 259 | /* This is the error handling routine for processes that are allowed |
| 260 | * to sleep. |
| 261 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 262 | 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] | 263 | { |
| 264 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 265 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 266 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 267 | int ret = errorcode; |
| 268 | |
| 269 | exception->retry = 0; |
| 270 | switch(errorcode) { |
| 271 | case 0: |
| 272 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 273 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 274 | if (inode && nfs_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 275 | nfs_inode_return_delegation(inode); |
| 276 | exception->retry = 1; |
| 277 | return 0; |
| 278 | } |
| 279 | if (state == NULL) |
| 280 | break; |
| 281 | nfs4_schedule_stateid_recovery(server, state); |
| 282 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 283 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 284 | case -NFS4ERR_ADMIN_REVOKED: |
| 285 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 286 | if (state == NULL) |
| 287 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 288 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 289 | nfs4_schedule_stateid_recovery(server, state); |
| 290 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 291 | case -NFS4ERR_EXPIRED: |
| 292 | if (state != NULL) |
| 293 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 294 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 295 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 296 | nfs4_schedule_lease_recovery(clp); |
| 297 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 298 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 299 | case -NFS4ERR_BADSESSION: |
| 300 | case -NFS4ERR_BADSLOT: |
| 301 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 302 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 303 | case -NFS4ERR_DEADSESSION: |
| 304 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 305 | case -NFS4ERR_SEQ_MISORDERED: |
| 306 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 307 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 308 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 309 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 310 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 311 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 312 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 313 | if (exception->timeout > HZ) { |
| 314 | /* We have retried a decent amount, time to |
| 315 | * fail |
| 316 | */ |
| 317 | ret = -EBUSY; |
| 318 | break; |
| 319 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 320 | case -NFS4ERR_GRACE: |
| 321 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 322 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 323 | ret = nfs4_delay(server->client, &exception->timeout); |
| 324 | if (ret != 0) |
| 325 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 326 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 327 | case -NFS4ERR_OLD_STATEID: |
| 328 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 329 | break; |
| 330 | case -NFS4ERR_BADOWNER: |
| 331 | /* The following works around a Linux server bug! */ |
| 332 | case -NFS4ERR_BADNAME: |
| 333 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 334 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 335 | exception->retry = 1; |
| 336 | printk(KERN_WARNING "NFS: v4 server %s " |
| 337 | "does not accept raw " |
| 338 | "uid/gids. " |
| 339 | "Reenabling the idmapper.\n", |
| 340 | server->nfs_client->cl_hostname); |
| 341 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 342 | } |
| 343 | /* We failed to handle the error */ |
| 344 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 345 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 346 | ret = nfs4_wait_clnt_recover(clp); |
| 347 | if (ret == 0) |
| 348 | exception->retry = 1; |
| 349 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 353 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | spin_lock(&clp->cl_lock); |
| 356 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 357 | clp->cl_last_renewal = timestamp; |
| 358 | spin_unlock(&clp->cl_lock); |
| 359 | } |
| 360 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 361 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 362 | { |
| 363 | do_renew_lease(server->nfs_client, timestamp); |
| 364 | } |
| 365 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 366 | #if defined(CONFIG_NFS_V4_1) |
| 367 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 368 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 369 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 370 | * |
| 371 | * freeing a slot is trivially done by clearing its respective bit |
| 372 | * in the bitmap. |
| 373 | * If the freed slotid equals highest_used_slotid we want to update it |
| 374 | * so that the server would be able to size down the slot table if needed, |
| 375 | * otherwise we know that the highest_used_slotid is still in use. |
| 376 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 377 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 378 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 379 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 380 | * |
| 381 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 382 | */ |
| 383 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 384 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 385 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 386 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 387 | /* clear used bit in bitmap */ |
| 388 | __clear_bit(slotid, tbl->used_slots); |
| 389 | |
| 390 | /* update highest_used_slotid when it is freed */ |
| 391 | if (slotid == tbl->highest_used_slotid) { |
| 392 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 393 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 394 | tbl->highest_used_slotid = slotid; |
| 395 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 396 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 397 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 398 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 399 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 400 | } |
| 401 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 402 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 403 | { |
| 404 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 405 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 406 | } |
| 407 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 408 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 409 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 410 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 411 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 412 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 413 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 414 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 415 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 419 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 420 | return; |
| 421 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 422 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 423 | complete(&ses->fc_slot_table.complete); |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Signal state manager thread if session back channel is drained |
| 428 | */ |
| 429 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 430 | { |
| 431 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 432 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 433 | return; |
| 434 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 435 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 438 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 439 | { |
| 440 | struct nfs4_slot_table *tbl; |
| 441 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 442 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 443 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 444 | /* just wake up the next guy waiting since |
| 445 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 446 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 447 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 448 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 449 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 450 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 451 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 452 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 453 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 454 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 457 | 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] | 458 | { |
| 459 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 461 | |
| 462 | /* |
| 463 | * sr_status remains 1 if an RPC level error occurred. The server |
| 464 | * may or may not have processed the sequence operation.. |
| 465 | * Proceed as if the server received and processed the sequence |
| 466 | * operation. |
| 467 | */ |
| 468 | if (res->sr_status == 1) |
| 469 | res->sr_status = NFS_OK; |
| 470 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 471 | /* don't increment the sequence number if the task wasn't sent */ |
| 472 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 473 | goto out; |
| 474 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 475 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 476 | switch (res->sr_status) { |
| 477 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 478 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 479 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 480 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 481 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 483 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 484 | if (res->sr_status_flags != 0) |
| 485 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 486 | break; |
| 487 | case -NFS4ERR_DELAY: |
| 488 | /* The server detected a resend of the RPC call and |
| 489 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 490 | * of RFC5661. |
| 491 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 492 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 493 | __func__, |
| 494 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 495 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | goto out_retry; |
| 497 | default: |
| 498 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 499 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 500 | } |
| 501 | out: |
| 502 | /* The session may be reset by one of the error handlers. */ |
| 503 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 504 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 505 | return 1; |
| 506 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 507 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 508 | goto out; |
| 509 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 510 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 511 | } |
| 512 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | static int nfs4_sequence_done(struct rpc_task *task, |
| 514 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 515 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 516 | if (res->sr_session == NULL) |
| 517 | return 1; |
| 518 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 521 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 522 | * nfs4_find_slot - efficiently look for a free slot |
| 523 | * |
| 524 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 525 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 526 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 527 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 528 | * |
| 529 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 530 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 531 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 532 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 533 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 534 | u32 slotid; |
| 535 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 536 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 537 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 538 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 539 | tbl->max_slots); |
| 540 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 541 | if (slotid >= tbl->max_slots) |
| 542 | goto out; |
| 543 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 544 | if (slotid > tbl->highest_used_slotid || |
| 545 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 546 | tbl->highest_used_slotid = slotid; |
| 547 | ret_id = slotid; |
| 548 | out: |
| 549 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 550 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 551 | return ret_id; |
| 552 | } |
| 553 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 554 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 555 | struct nfs4_sequence_res *res, int cache_reply) |
| 556 | { |
| 557 | args->sa_session = NULL; |
| 558 | args->sa_cache_this = 0; |
| 559 | if (cache_reply) |
| 560 | args->sa_cache_this = 1; |
| 561 | res->sr_session = NULL; |
| 562 | res->sr_slot = NULL; |
| 563 | } |
| 564 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 565 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 566 | struct nfs4_sequence_args *args, |
| 567 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 568 | struct rpc_task *task) |
| 569 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 570 | struct nfs4_slot *slot; |
| 571 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 572 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 573 | |
| 574 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 575 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 576 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 577 | return 0; |
| 578 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 579 | tbl = &session->fc_slot_table; |
| 580 | |
| 581 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 582 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 583 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 584 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 585 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 586 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 587 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 588 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 591 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 592 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 593 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 594 | spin_unlock(&tbl->slot_tbl_lock); |
| 595 | dprintk("%s enforce FIFO order\n", __func__); |
| 596 | return -EAGAIN; |
| 597 | } |
| 598 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 599 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 600 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 601 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 602 | spin_unlock(&tbl->slot_tbl_lock); |
| 603 | dprintk("<-- %s: no free slots\n", __func__); |
| 604 | return -EAGAIN; |
| 605 | } |
| 606 | spin_unlock(&tbl->slot_tbl_lock); |
| 607 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 608 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 609 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 610 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 611 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 612 | |
| 613 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 614 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 615 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 616 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 617 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 618 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 619 | /* |
| 620 | * sr_status is only set in decode_sequence, and so will remain |
| 621 | * set to 1 if an rpc level failure occurs. |
| 622 | */ |
| 623 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | return 0; |
| 625 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 626 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 627 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 628 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 629 | struct nfs4_sequence_args *args, |
| 630 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 631 | struct rpc_task *task) |
| 632 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 633 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | int ret = 0; |
| 635 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 636 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 638 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 639 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 640 | __func__, session->clp, session, res->sr_slot ? |
| 641 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 642 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 643 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 644 | out: |
| 645 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 650 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 651 | struct nfs4_sequence_args *seq_args; |
| 652 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | }; |
| 654 | |
| 655 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 656 | { |
| 657 | struct nfs41_call_sync_data *data = calldata; |
| 658 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 659 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 660 | |
| 661 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 662 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | return; |
| 664 | rpc_call_start(task); |
| 665 | } |
| 666 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 667 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 668 | { |
| 669 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 670 | nfs41_call_sync_prepare(task, calldata); |
| 671 | } |
| 672 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 673 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 674 | { |
| 675 | struct nfs41_call_sync_data *data = calldata; |
| 676 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 677 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 680 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 682 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | }; |
| 684 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 685 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 686 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 687 | .rpc_call_done = nfs41_call_sync_done, |
| 688 | }; |
| 689 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 690 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 691 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 692 | struct rpc_message *msg, |
| 693 | struct nfs4_sequence_args *args, |
| 694 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 695 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | { |
| 697 | int ret; |
| 698 | struct rpc_task *task; |
| 699 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 700 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 701 | .seq_args = args, |
| 702 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 703 | }; |
| 704 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 705 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 706 | .rpc_message = msg, |
| 707 | .callback_ops = &nfs41_call_sync_ops, |
| 708 | .callback_data = &data |
| 709 | }; |
| 710 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 711 | if (privileged) |
| 712 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 713 | task = rpc_run_task(&task_setup); |
| 714 | if (IS_ERR(task)) |
| 715 | ret = PTR_ERR(task); |
| 716 | else { |
| 717 | ret = task->tk_status; |
| 718 | rpc_put_task(task); |
| 719 | } |
| 720 | return ret; |
| 721 | } |
| 722 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 723 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 724 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | struct rpc_message *msg, |
| 726 | struct nfs4_sequence_args *args, |
| 727 | struct nfs4_sequence_res *res, |
| 728 | int cache_reply) |
| 729 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 730 | nfs41_init_sequence(args, res, cache_reply); |
| 731 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 732 | } |
| 733 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 734 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 735 | static inline |
| 736 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 737 | struct nfs4_sequence_res *res, int cache_reply) |
| 738 | { |
| 739 | } |
| 740 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 741 | static int nfs4_sequence_done(struct rpc_task *task, |
| 742 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 743 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 744 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 745 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 746 | #endif /* CONFIG_NFS_V4_1 */ |
| 747 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 748 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 749 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 750 | struct rpc_message *msg, |
| 751 | struct nfs4_sequence_args *args, |
| 752 | struct nfs4_sequence_res *res, |
| 753 | int cache_reply) |
| 754 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 755 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 756 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 759 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 760 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 761 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 762 | struct rpc_message *msg, |
| 763 | struct nfs4_sequence_args *args, |
| 764 | struct nfs4_sequence_res *res, |
| 765 | int cache_reply) |
| 766 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 767 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 768 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 769 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 770 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 771 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 773 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 775 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 776 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 777 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 778 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 779 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 780 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 783 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 784 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 785 | struct nfs_openargs o_arg; |
| 786 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 787 | struct nfs_open_confirmargs c_arg; |
| 788 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 789 | struct nfs4_string owner_name; |
| 790 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 792 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 793 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 794 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 795 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 797 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 798 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 799 | int rpc_status; |
| 800 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 801 | }; |
| 802 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 803 | |
| 804 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 805 | { |
| 806 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 807 | p->o_res.seqid = p->o_arg.seqid; |
| 808 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 809 | p->o_res.server = p->o_arg.server; |
| 810 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 811 | 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] | 812 | } |
| 813 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 814 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 815 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 816 | const struct iattr *attrs, |
| 817 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 819 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | struct inode *dir = parent->d_inode; |
| 821 | struct nfs_server *server = NFS_SERVER(dir); |
| 822 | struct nfs4_opendata *p; |
| 823 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 824 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | if (p == NULL) |
| 826 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 827 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | if (p->o_arg.seqid == NULL) |
| 829 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 830 | nfs_sb_active(dentry->d_sb); |
| 831 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 832 | p->dir = parent; |
| 833 | p->owner = sp; |
| 834 | atomic_inc(&sp->so_count); |
| 835 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 836 | p->o_arg.open_flags = flags; |
| 837 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 838 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 839 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 840 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 841 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 842 | p->o_arg.server = server; |
| 843 | p->o_arg.bitmask = server->attr_bitmask; |
| 844 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 845 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 846 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 847 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 848 | p->o_arg.u.attrs = &p->attrs; |
| 849 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 850 | |
| 851 | verf[0] = jiffies; |
| 852 | verf[1] = current->pid; |
| 853 | memcpy(p->o_arg.u.verifier.data, verf, |
| 854 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 856 | p->c_arg.fh = &p->o_res.fh; |
| 857 | p->c_arg.stateid = &p->o_res.stateid; |
| 858 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 859 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 860 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 861 | return p; |
| 862 | err_free: |
| 863 | kfree(p); |
| 864 | err: |
| 865 | dput(parent); |
| 866 | return NULL; |
| 867 | } |
| 868 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 869 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 870 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 871 | struct nfs4_opendata *p = container_of(kref, |
| 872 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 873 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 874 | |
| 875 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 876 | if (p->state != NULL) |
| 877 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 878 | nfs4_put_state_owner(p->owner); |
| 879 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 880 | dput(p->dentry); |
| 881 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 882 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 883 | kfree(p); |
| 884 | } |
| 885 | |
| 886 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 887 | { |
| 888 | if (p != NULL) |
| 889 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 890 | } |
| 891 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 892 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 893 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 894 | int ret; |
| 895 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 896 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 897 | return ret; |
| 898 | } |
| 899 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | 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] | 901 | { |
| 902 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 904 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | goto out; |
| 906 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 907 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 908 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 909 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 910 | break; |
| 911 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 912 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 913 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 914 | break; |
| 915 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 916 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 917 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 918 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 919 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 920 | return ret; |
| 921 | } |
| 922 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 923 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 924 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 925 | if (delegation == NULL) |
| 926 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 928 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 929 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 930 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 931 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 932 | return 1; |
| 933 | } |
| 934 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 935 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 936 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 938 | case FMODE_WRITE: |
| 939 | state->n_wronly++; |
| 940 | break; |
| 941 | case FMODE_READ: |
| 942 | state->n_rdonly++; |
| 943 | break; |
| 944 | case FMODE_READ|FMODE_WRITE: |
| 945 | state->n_rdwr++; |
| 946 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 948 | } |
| 949 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 950 | 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] | 951 | { |
| 952 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 953 | nfs4_stateid_copy(&state->stateid, stateid); |
| 954 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 956 | case FMODE_READ: |
| 957 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 958 | break; |
| 959 | case FMODE_WRITE: |
| 960 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 961 | break; |
| 962 | case FMODE_READ|FMODE_WRITE: |
| 963 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 964 | } |
| 965 | } |
| 966 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 967 | 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] | 968 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 969 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 971 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 972 | } |
| 973 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 974 | 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] | 975 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 976 | /* |
| 977 | * Protect the call to nfs4_state_set_mode_locked and |
| 978 | * serialise the stateid update |
| 979 | */ |
| 980 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 981 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 982 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 983 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 984 | } |
| 985 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 986 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 987 | write_sequnlock(&state->seqlock); |
| 988 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 990 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | 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] | 994 | { |
| 995 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 996 | struct nfs_delegation *deleg_cur; |
| 997 | int ret = 0; |
| 998 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1000 | |
| 1001 | rcu_read_lock(); |
| 1002 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1003 | if (deleg_cur == NULL) |
| 1004 | goto no_delegation; |
| 1005 | |
| 1006 | spin_lock(&deleg_cur->lock); |
| 1007 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1008 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1009 | goto no_delegation_unlock; |
| 1010 | |
| 1011 | if (delegation == NULL) |
| 1012 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1013 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1014 | goto no_delegation_unlock; |
| 1015 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1016 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1018 | ret = 1; |
| 1019 | no_delegation_unlock: |
| 1020 | spin_unlock(&deleg_cur->lock); |
| 1021 | no_delegation: |
| 1022 | rcu_read_unlock(); |
| 1023 | |
| 1024 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1026 | ret = 1; |
| 1027 | } |
| 1028 | |
| 1029 | return ret; |
| 1030 | } |
| 1031 | |
| 1032 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1034 | { |
| 1035 | struct nfs_delegation *delegation; |
| 1036 | |
| 1037 | rcu_read_lock(); |
| 1038 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1039 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1040 | rcu_read_unlock(); |
| 1041 | return; |
| 1042 | } |
| 1043 | rcu_read_unlock(); |
| 1044 | nfs_inode_return_delegation(inode); |
| 1045 | } |
| 1046 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1047 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | { |
| 1049 | struct nfs4_state *state = opendata->state; |
| 1050 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1051 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1052 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1054 | nfs4_stateid stateid; |
| 1055 | int ret = -EAGAIN; |
| 1056 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1057 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1058 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1059 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1060 | if (can_open_cached(state, fmode, open_mode)) { |
| 1061 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1062 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1063 | goto out_return_state; |
| 1064 | } |
| 1065 | spin_unlock(&state->owner->so_lock); |
| 1066 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1067 | rcu_read_lock(); |
| 1068 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1069 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1070 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1071 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1072 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1073 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1074 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1075 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1076 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1077 | if (ret != 0) |
| 1078 | goto out; |
| 1079 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1080 | |
| 1081 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1082 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1083 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1084 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | out: |
| 1086 | return ERR_PTR(ret); |
| 1087 | out_return_state: |
| 1088 | atomic_inc(&state->count); |
| 1089 | return state; |
| 1090 | } |
| 1091 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1092 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1093 | { |
| 1094 | struct inode *inode; |
| 1095 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1096 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1097 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1098 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1099 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1100 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1101 | goto out; |
| 1102 | } |
| 1103 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1104 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1105 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1106 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1107 | 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] | 1108 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1109 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1110 | goto err; |
| 1111 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1112 | state = nfs4_get_open_state(inode, data->owner); |
| 1113 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1114 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1115 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1116 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1117 | int delegation_flags = 0; |
| 1118 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1119 | rcu_read_lock(); |
| 1120 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1121 | if (delegation) |
| 1122 | delegation_flags = delegation->flags; |
| 1123 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1124 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1125 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1126 | "returning a delegation for " |
| 1127 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1128 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1129 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1130 | nfs_inode_set_delegation(state->inode, |
| 1131 | data->owner->so_cred, |
| 1132 | &data->o_res); |
| 1133 | else |
| 1134 | nfs_inode_reclaim_delegation(state->inode, |
| 1135 | data->owner->so_cred, |
| 1136 | &data->o_res); |
| 1137 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1138 | |
| 1139 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1141 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1142 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1143 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1144 | err_put_inode: |
| 1145 | iput(inode); |
| 1146 | err: |
| 1147 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1150 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1151 | { |
| 1152 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1153 | struct nfs_open_context *ctx; |
| 1154 | |
| 1155 | spin_lock(&state->inode->i_lock); |
| 1156 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1157 | if (ctx->state != state) |
| 1158 | continue; |
| 1159 | get_nfs_open_context(ctx); |
| 1160 | spin_unlock(&state->inode->i_lock); |
| 1161 | return ctx; |
| 1162 | } |
| 1163 | spin_unlock(&state->inode->i_lock); |
| 1164 | return ERR_PTR(-ENOENT); |
| 1165 | } |
| 1166 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1167 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1168 | { |
| 1169 | struct nfs4_opendata *opendata; |
| 1170 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1171 | 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] | 1172 | if (opendata == NULL) |
| 1173 | return ERR_PTR(-ENOMEM); |
| 1174 | opendata->state = state; |
| 1175 | atomic_inc(&state->count); |
| 1176 | return opendata; |
| 1177 | } |
| 1178 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1179 | 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] | 1180 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1181 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1182 | int ret; |
| 1183 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1184 | opendata->o_arg.open_flags = 0; |
| 1185 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1187 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1188 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1189 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1190 | if (ret != 0) |
| 1191 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1192 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1193 | if (IS_ERR(newstate)) |
| 1194 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1195 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1196 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1201 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1202 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1203 | int ret; |
| 1204 | |
| 1205 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1206 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1207 | smp_rmb(); |
| 1208 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1209 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1210 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1211 | if (ret != 0) |
| 1212 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1213 | if (newstate != state) |
| 1214 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1215 | } |
| 1216 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1217 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1218 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1219 | if (ret != 0) |
| 1220 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1221 | if (newstate != state) |
| 1222 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1223 | } |
| 1224 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1225 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1226 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1227 | if (ret != 0) |
| 1228 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1229 | if (newstate != state) |
| 1230 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1231 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1232 | /* |
| 1233 | * We may have performed cached opens for all three recoveries. |
| 1234 | * Check if we need to update the current stateid. |
| 1235 | */ |
| 1236 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1237 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1238 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1239 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1240 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1241 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1242 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1243 | return 0; |
| 1244 | } |
| 1245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | /* |
| 1247 | * OPEN_RECLAIM: |
| 1248 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1250 | 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] | 1251 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1252 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1254 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | int status; |
| 1256 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1257 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1258 | if (IS_ERR(opendata)) |
| 1259 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1260 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1261 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1262 | rcu_read_lock(); |
| 1263 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1264 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1265 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1266 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1267 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1268 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1269 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | return status; |
| 1271 | } |
| 1272 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1273 | 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] | 1274 | { |
| 1275 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1276 | struct nfs4_exception exception = { }; |
| 1277 | int err; |
| 1278 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1279 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1280 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1281 | break; |
| 1282 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | } while (exception.retry); |
| 1284 | return err; |
| 1285 | } |
| 1286 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1287 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1288 | { |
| 1289 | struct nfs_open_context *ctx; |
| 1290 | int ret; |
| 1291 | |
| 1292 | ctx = nfs4_state_find_open_context(state); |
| 1293 | if (IS_ERR(ctx)) |
| 1294 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1295 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1296 | put_nfs_open_context(ctx); |
| 1297 | return ret; |
| 1298 | } |
| 1299 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1300 | 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] | 1301 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1302 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1303 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1305 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1306 | if (IS_ERR(opendata)) |
| 1307 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1308 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1309 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1310 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1311 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1312 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1315 | 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] | 1316 | { |
| 1317 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1318 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | int err; |
| 1320 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1321 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | switch (err) { |
| 1323 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1324 | case -ENOENT: |
| 1325 | case -ESTALE: |
| 1326 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1327 | case -NFS4ERR_BADSESSION: |
| 1328 | case -NFS4ERR_BADSLOT: |
| 1329 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1330 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1331 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1332 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1333 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | case -NFS4ERR_STALE_CLIENTID: |
| 1335 | case -NFS4ERR_STALE_STATEID: |
| 1336 | case -NFS4ERR_EXPIRED: |
| 1337 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1338 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1339 | goto out; |
| 1340 | case -ERESTARTSYS: |
| 1341 | /* |
| 1342 | * The show must go on: exit, but mark the |
| 1343 | * stateid as needing recovery. |
| 1344 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1345 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1346 | case -NFS4ERR_ADMIN_REVOKED: |
| 1347 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1348 | nfs_inode_find_state_and_recover(state->inode, |
| 1349 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1350 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1351 | case -EKEYEXPIRED: |
| 1352 | /* |
| 1353 | * User RPCSEC_GSS context has expired. |
| 1354 | * We cannot recover this stateid now, so |
| 1355 | * skip it and allow recovery thread to |
| 1356 | * proceed. |
| 1357 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1358 | case -ENOMEM: |
| 1359 | err = 0; |
| 1360 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | } |
| 1362 | err = nfs4_handle_exception(server, err, &exception); |
| 1363 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1364 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | return err; |
| 1366 | } |
| 1367 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1368 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1369 | { |
| 1370 | struct nfs4_opendata *data = calldata; |
| 1371 | |
| 1372 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1373 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1374 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1375 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1376 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1377 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1378 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static void nfs4_open_confirm_release(void *calldata) |
| 1382 | { |
| 1383 | struct nfs4_opendata *data = calldata; |
| 1384 | struct nfs4_state *state = NULL; |
| 1385 | |
| 1386 | /* If this request hasn't been cancelled, do nothing */ |
| 1387 | if (data->cancelled == 0) |
| 1388 | goto out_free; |
| 1389 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1390 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1391 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1392 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1393 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1394 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1395 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1396 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1400 | .rpc_call_done = nfs4_open_confirm_done, |
| 1401 | .rpc_release = nfs4_open_confirm_release, |
| 1402 | }; |
| 1403 | |
| 1404 | /* |
| 1405 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1406 | */ |
| 1407 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1408 | { |
| 1409 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1410 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1411 | struct rpc_message msg = { |
| 1412 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1413 | .rpc_argp = &data->c_arg, |
| 1414 | .rpc_resp = &data->c_res, |
| 1415 | .rpc_cred = data->owner->so_cred, |
| 1416 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1417 | struct rpc_task_setup task_setup_data = { |
| 1418 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1419 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1420 | .callback_ops = &nfs4_open_confirm_ops, |
| 1421 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1422 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1423 | .flags = RPC_TASK_ASYNC, |
| 1424 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | int status; |
| 1426 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1427 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1428 | data->rpc_done = 0; |
| 1429 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1430 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1431 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1432 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1433 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1434 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1435 | if (status != 0) { |
| 1436 | data->cancelled = 1; |
| 1437 | smp_wmb(); |
| 1438 | } else |
| 1439 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1440 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | return status; |
| 1442 | } |
| 1443 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1444 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1446 | struct nfs4_opendata *data = calldata; |
| 1447 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1448 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1449 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1450 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1451 | /* |
| 1452 | * Check if we still need to send an OPEN call, or if we can use |
| 1453 | * a delegation instead. |
| 1454 | */ |
| 1455 | if (data->state != NULL) { |
| 1456 | struct nfs_delegation *delegation; |
| 1457 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1458 | 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] | 1459 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1460 | rcu_read_lock(); |
| 1461 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1462 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1463 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1464 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1465 | rcu_read_unlock(); |
| 1466 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1467 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1468 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1469 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1470 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1471 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1472 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1473 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1474 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1475 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1476 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1477 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1478 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1479 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1480 | unlock_no_action: |
| 1481 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1482 | out_no_action: |
| 1483 | task->tk_action = NULL; |
| 1484 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1487 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1488 | { |
| 1489 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1490 | nfs4_open_prepare(task, calldata); |
| 1491 | } |
| 1492 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1493 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1494 | { |
| 1495 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1497 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1498 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1499 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1500 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1501 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1502 | if (task->tk_status == 0) { |
| 1503 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1504 | case S_IFREG: |
| 1505 | break; |
| 1506 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1507 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1508 | break; |
| 1509 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1510 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1511 | break; |
| 1512 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1513 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1514 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1515 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1516 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1517 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1518 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1519 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1520 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1521 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1522 | static void nfs4_open_release(void *calldata) |
| 1523 | { |
| 1524 | struct nfs4_opendata *data = calldata; |
| 1525 | struct nfs4_state *state = NULL; |
| 1526 | |
| 1527 | /* If this request hasn't been cancelled, do nothing */ |
| 1528 | if (data->cancelled == 0) |
| 1529 | goto out_free; |
| 1530 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1531 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1532 | goto out_free; |
| 1533 | /* In case we need an open_confirm, no cleanup! */ |
| 1534 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1535 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1536 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1537 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1538 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1539 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1540 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1544 | .rpc_call_prepare = nfs4_open_prepare, |
| 1545 | .rpc_call_done = nfs4_open_done, |
| 1546 | .rpc_release = nfs4_open_release, |
| 1547 | }; |
| 1548 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1549 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1550 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1551 | .rpc_call_done = nfs4_open_done, |
| 1552 | .rpc_release = nfs4_open_release, |
| 1553 | }; |
| 1554 | |
| 1555 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1556 | { |
| 1557 | struct inode *dir = data->dir->d_inode; |
| 1558 | struct nfs_server *server = NFS_SERVER(dir); |
| 1559 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1560 | struct nfs_openres *o_res = &data->o_res; |
| 1561 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1562 | struct rpc_message msg = { |
| 1563 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1564 | .rpc_argp = o_arg, |
| 1565 | .rpc_resp = o_res, |
| 1566 | .rpc_cred = data->owner->so_cred, |
| 1567 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1568 | struct rpc_task_setup task_setup_data = { |
| 1569 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1570 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1571 | .callback_ops = &nfs4_open_ops, |
| 1572 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1573 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1574 | .flags = RPC_TASK_ASYNC, |
| 1575 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1576 | int status; |
| 1577 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1578 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1579 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1580 | data->rpc_done = 0; |
| 1581 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1582 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1583 | if (isrecover) |
| 1584 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1585 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1586 | if (IS_ERR(task)) |
| 1587 | return PTR_ERR(task); |
| 1588 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1589 | if (status != 0) { |
| 1590 | data->cancelled = 1; |
| 1591 | smp_wmb(); |
| 1592 | } else |
| 1593 | status = data->rpc_status; |
| 1594 | rpc_put_task(task); |
| 1595 | |
| 1596 | return status; |
| 1597 | } |
| 1598 | |
| 1599 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1600 | { |
| 1601 | struct inode *dir = data->dir->d_inode; |
| 1602 | struct nfs_openres *o_res = &data->o_res; |
| 1603 | int status; |
| 1604 | |
| 1605 | status = nfs4_run_open_task(data, 1); |
| 1606 | if (status != 0 || !data->rpc_done) |
| 1607 | return status; |
| 1608 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1609 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1610 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1611 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1612 | status = _nfs4_proc_open_confirm(data); |
| 1613 | if (status != 0) |
| 1614 | return status; |
| 1615 | } |
| 1616 | |
| 1617 | return status; |
| 1618 | } |
| 1619 | |
| 1620 | /* |
| 1621 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1622 | */ |
| 1623 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1624 | { |
| 1625 | struct inode *dir = data->dir->d_inode; |
| 1626 | struct nfs_server *server = NFS_SERVER(dir); |
| 1627 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1628 | struct nfs_openres *o_res = &data->o_res; |
| 1629 | int status; |
| 1630 | |
| 1631 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1632 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1633 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1634 | if (status != 0) { |
| 1635 | if (status == -NFS4ERR_BADNAME && |
| 1636 | !(o_arg->open_flags & O_CREAT)) |
| 1637 | return -ENOENT; |
| 1638 | return status; |
| 1639 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1640 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1641 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1642 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1643 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1644 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1645 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1646 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1648 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1650 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | } |
| 1652 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1653 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1654 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1657 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1658 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1659 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1660 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1661 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1662 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1663 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1664 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1665 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1666 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1667 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1668 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1669 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1670 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1671 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1672 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1673 | } |
| 1674 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1675 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1676 | { |
| 1677 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1678 | } |
| 1679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | /* |
| 1681 | * OPEN_EXPIRED: |
| 1682 | * reclaim state on the server after a network partition. |
| 1683 | * Assumes caller holds the appropriate lock |
| 1684 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1685 | 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] | 1686 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1687 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1688 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1690 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1691 | if (IS_ERR(opendata)) |
| 1692 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1693 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1694 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1695 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1696 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1697 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1700 | 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] | 1701 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1702 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1703 | struct nfs4_exception exception = { }; |
| 1704 | int err; |
| 1705 | |
| 1706 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1707 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1708 | switch (err) { |
| 1709 | default: |
| 1710 | goto out; |
| 1711 | case -NFS4ERR_GRACE: |
| 1712 | case -NFS4ERR_DELAY: |
| 1713 | nfs4_handle_exception(server, err, &exception); |
| 1714 | err = 0; |
| 1715 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1716 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1717 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1718 | return err; |
| 1719 | } |
| 1720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1722 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1724 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1726 | ctx = nfs4_state_find_open_context(state); |
| 1727 | if (IS_ERR(ctx)) |
| 1728 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1729 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1730 | put_nfs_open_context(ctx); |
| 1731 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1734 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1735 | static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *stateid, unsigned int flags) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1736 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1737 | int status = NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1738 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1739 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1740 | if (state->flags & flags) { |
| 1741 | status = nfs41_test_stateid(server, stateid); |
| 1742 | if (status != NFS_OK) { |
| 1743 | nfs41_free_stateid(server, stateid); |
| 1744 | state->flags &= ~flags; |
| 1745 | } |
| 1746 | } |
| 1747 | return status; |
| 1748 | } |
| 1749 | |
| 1750 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1751 | { |
| 1752 | int deleg_status, open_status; |
| 1753 | int deleg_flags = 1 << NFS_DELEGATED_STATE; |
| 1754 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); |
| 1755 | |
| 1756 | deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); |
| 1757 | open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags); |
| 1758 | |
| 1759 | if ((deleg_status == NFS_OK) && (open_status == NFS_OK)) |
| 1760 | return NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1761 | return nfs4_open_expired(sp, state); |
| 1762 | } |
| 1763 | #endif |
| 1764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1766 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1767 | * fields corresponding to attributes that were used to store the verifier. |
| 1768 | * Make sure we clobber those fields in the later setattr call |
| 1769 | */ |
| 1770 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1771 | { |
| 1772 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1773 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1774 | sattr->ia_valid |= ATTR_ATIME; |
| 1775 | |
| 1776 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1777 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1778 | sattr->ia_valid |= ATTR_MTIME; |
| 1779 | } |
| 1780 | |
| 1781 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1782 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1784 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | { |
| 1786 | struct nfs4_state_owner *sp; |
| 1787 | struct nfs4_state *state = NULL; |
| 1788 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1789 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1790 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1794 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1795 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1797 | goto out_err; |
| 1798 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1799 | status = nfs4_recover_expired_lease(server); |
| 1800 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1801 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1802 | if (dentry->d_inode != NULL) |
| 1803 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1804 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1805 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1806 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1807 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1809 | if (dentry->d_inode != NULL) |
| 1810 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1811 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1812 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1814 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1816 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1817 | status = PTR_ERR(state); |
| 1818 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1819 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1820 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1821 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1822 | |
| 1823 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1824 | nfs4_exclusive_attrset(opendata, sattr); |
| 1825 | |
| 1826 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1827 | status = nfs4_do_setattr(state->inode, cred, |
| 1828 | opendata->o_res.f_attr, sattr, |
| 1829 | state); |
| 1830 | if (status == 0) |
| 1831 | nfs_setattr_update_inode(state->inode, sattr); |
| 1832 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1833 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1834 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | *res = state; |
| 1837 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1838 | err_opendata_put: |
| 1839 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1840 | err_put_state_owner: |
| 1841 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | *res = NULL; |
| 1844 | return status; |
| 1845 | } |
| 1846 | |
| 1847 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1848 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | { |
| 1850 | struct nfs4_exception exception = { }; |
| 1851 | struct nfs4_state *res; |
| 1852 | int status; |
| 1853 | |
| 1854 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1855 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | if (status == 0) |
| 1857 | break; |
| 1858 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1859 | * book-keeping w.r.t. state-changing operations |
| 1860 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1861 | * It is actually a sign of a bug on the client or on the server. |
| 1862 | * |
| 1863 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1864 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | * have unhashed the old state_owner for us, and that we can |
| 1866 | * therefore safely retry using a new one. We should still warn |
| 1867 | * the user though... |
| 1868 | */ |
| 1869 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1870 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1871 | " returned a bad sequence-id error!\n", |
| 1872 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | exception.retry = 1; |
| 1874 | continue; |
| 1875 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1876 | /* |
| 1877 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1878 | * state before it received the OPEN_CONFIRM. |
| 1879 | * Recover by retrying the request as per the discussion |
| 1880 | * on Page 181 of RFC3530. |
| 1881 | */ |
| 1882 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1883 | exception.retry = 1; |
| 1884 | continue; |
| 1885 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1886 | if (status == -EAGAIN) { |
| 1887 | /* We must have found a delegation */ |
| 1888 | exception.retry = 1; |
| 1889 | continue; |
| 1890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1892 | status, &exception)); |
| 1893 | } while (exception.retry); |
| 1894 | return res; |
| 1895 | } |
| 1896 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1897 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1898 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1899 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1901 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1903 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | .iap = sattr, |
| 1905 | .server = server, |
| 1906 | .bitmask = server->attr_bitmask, |
| 1907 | }; |
| 1908 | struct nfs_setattrres res = { |
| 1909 | .fattr = fattr, |
| 1910 | .server = server, |
| 1911 | }; |
| 1912 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1913 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1914 | .rpc_argp = &arg, |
| 1915 | .rpc_resp = &res, |
| 1916 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1918 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1919 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1921 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 1923 | if (state != NULL) { |
| 1924 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 1925 | current->files, current->tgid); |
| 1926 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 1927 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1928 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1929 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1930 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1932 | 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] | 1933 | if (status == 0 && state != NULL) |
| 1934 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1935 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1938 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1939 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1940 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1942 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1943 | struct nfs4_exception exception = { |
| 1944 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 1945 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1946 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | int err; |
| 1948 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 1949 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 1950 | switch (err) { |
| 1951 | case -NFS4ERR_OPENMODE: |
| 1952 | if (state && !(state->state & FMODE_WRITE)) { |
| 1953 | err = -EBADF; |
| 1954 | if (sattr->ia_valid & ATTR_OPEN) |
| 1955 | err = -EACCES; |
| 1956 | goto out; |
| 1957 | } |
| 1958 | } |
| 1959 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 1961 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | return err; |
| 1963 | } |
| 1964 | |
| 1965 | struct nfs4_closedata { |
| 1966 | struct inode *inode; |
| 1967 | struct nfs4_state *state; |
| 1968 | struct nfs_closeargs arg; |
| 1969 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1970 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1971 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1972 | bool roc; |
| 1973 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | }; |
| 1975 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1976 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1977 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1978 | struct nfs4_closedata *calldata = data; |
| 1979 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1980 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1981 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1982 | if (calldata->roc) |
| 1983 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1984 | nfs4_put_open_state(calldata->state); |
| 1985 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1986 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1987 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1988 | kfree(calldata); |
| 1989 | } |
| 1990 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1991 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1992 | fmode_t fmode) |
| 1993 | { |
| 1994 | spin_lock(&state->owner->so_lock); |
| 1995 | if (!(fmode & FMODE_READ)) |
| 1996 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1997 | if (!(fmode & FMODE_WRITE)) |
| 1998 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1999 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2000 | spin_unlock(&state->owner->so_lock); |
| 2001 | } |
| 2002 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2003 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2005 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2008 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2009 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2010 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2011 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | /* hmm. we are done with the inode, and in the process of freeing |
| 2013 | * the state_owner. we keep this around to process errors |
| 2014 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | switch (task->tk_status) { |
| 2016 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2017 | if (calldata->roc) |
| 2018 | pnfs_roc_set_barrier(state->inode, |
| 2019 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2020 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2021 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2022 | nfs4_close_clear_stateid_flags(state, |
| 2023 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | break; |
| 2025 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2026 | case -NFS4ERR_OLD_STATEID: |
| 2027 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2029 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2030 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2032 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2033 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2035 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2036 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2037 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2040 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2042 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2043 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2044 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2045 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2046 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2047 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2048 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2049 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2050 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2051 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2052 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2053 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2054 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2055 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2056 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2057 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2058 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2059 | } |
| 2060 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2061 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2062 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2063 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2064 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2065 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2066 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2067 | |
| 2068 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2069 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2070 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2071 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2072 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2073 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2074 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2075 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2076 | if (calldata->roc && |
| 2077 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2078 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2079 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2080 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2081 | } |
| 2082 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2083 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2084 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2085 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2086 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2087 | &calldata->arg.seq_args, |
| 2088 | &calldata->res.seq_res, |
| 2089 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2090 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2091 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2092 | out: |
| 2093 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2096 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2097 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2098 | .rpc_call_done = nfs4_close_done, |
| 2099 | .rpc_release = nfs4_free_closedata, |
| 2100 | }; |
| 2101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | /* |
| 2103 | * It is possible for data to be read/written from a mem-mapped file |
| 2104 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2105 | * This means that we can't safely call nfsv4 close on a file until |
| 2106 | * the inode is cleared. This in turn means that we are not good |
| 2107 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2108 | * share state even when we are done with one of the three share |
| 2109 | * stateid's in the inode. |
| 2110 | * |
| 2111 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2112 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2113 | 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] | 2114 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2115 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2117 | struct nfs4_state_owner *sp = state->owner; |
| 2118 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2119 | struct rpc_message msg = { |
| 2120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2121 | .rpc_cred = state->owner->so_cred, |
| 2122 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2123 | struct rpc_task_setup task_setup_data = { |
| 2124 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2125 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2126 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2127 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2128 | .flags = RPC_TASK_ASYNC, |
| 2129 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2130 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2132 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2134 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2135 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2136 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2138 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2139 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2141 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2142 | if (calldata->arg.seqid == NULL) |
| 2143 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2144 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2145 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2146 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2147 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2148 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2149 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2150 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2151 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2152 | msg.rpc_argp = &calldata->arg; |
| 2153 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2154 | task_setup_data.callback_data = calldata; |
| 2155 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2156 | if (IS_ERR(task)) |
| 2157 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2158 | status = 0; |
| 2159 | if (wait) |
| 2160 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2161 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2162 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2163 | out_free_calldata: |
| 2164 | kfree(calldata); |
| 2165 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2166 | if (roc) |
| 2167 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2168 | nfs4_put_open_state(state); |
| 2169 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2170 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2173 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2174 | 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] | 2175 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | struct nfs4_state *state; |
| 2177 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2178 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2179 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2180 | if (IS_ERR(state)) |
| 2181 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2182 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2183 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2186 | 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] | 2187 | { |
| 2188 | if (ctx->state == NULL) |
| 2189 | return; |
| 2190 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2191 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2192 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2193 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
| 2196 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2197 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2198 | struct nfs4_server_caps_arg args = { |
| 2199 | .fhandle = fhandle, |
| 2200 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | struct nfs4_server_caps_res res = {}; |
| 2202 | struct rpc_message msg = { |
| 2203 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2204 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | .rpc_resp = &res, |
| 2206 | }; |
| 2207 | int status; |
| 2208 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2209 | 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] | 2210 | if (status == 0) { |
| 2211 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2212 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2213 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2214 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2215 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2216 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2218 | server->caps |= NFS_CAP_ACLS; |
| 2219 | if (res.has_links != 0) |
| 2220 | server->caps |= NFS_CAP_HARDLINKS; |
| 2221 | if (res.has_symlinks != 0) |
| 2222 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2223 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2224 | server->caps |= NFS_CAP_FILEID; |
| 2225 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2226 | server->caps |= NFS_CAP_MODE; |
| 2227 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2228 | server->caps |= NFS_CAP_NLINK; |
| 2229 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2230 | server->caps |= NFS_CAP_OWNER; |
| 2231 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2232 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2233 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2234 | server->caps |= NFS_CAP_ATIME; |
| 2235 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2236 | server->caps |= NFS_CAP_CTIME; |
| 2237 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2238 | server->caps |= NFS_CAP_MTIME; |
| 2239 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2240 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2241 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2242 | 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] | 2243 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2244 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | return status; |
| 2248 | } |
| 2249 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2250 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | { |
| 2252 | struct nfs4_exception exception = { }; |
| 2253 | int err; |
| 2254 | do { |
| 2255 | err = nfs4_handle_exception(server, |
| 2256 | _nfs4_server_capabilities(server, fhandle), |
| 2257 | &exception); |
| 2258 | } while (exception.retry); |
| 2259 | return err; |
| 2260 | } |
| 2261 | |
| 2262 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2263 | struct nfs_fsinfo *info) |
| 2264 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | struct nfs4_lookup_root_arg args = { |
| 2266 | .bitmask = nfs4_fattr_bitmap, |
| 2267 | }; |
| 2268 | struct nfs4_lookup_res res = { |
| 2269 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2270 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | .fh = fhandle, |
| 2272 | }; |
| 2273 | struct rpc_message msg = { |
| 2274 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2275 | .rpc_argp = &args, |
| 2276 | .rpc_resp = &res, |
| 2277 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2278 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2279 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2280 | 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] | 2281 | } |
| 2282 | |
| 2283 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2284 | struct nfs_fsinfo *info) |
| 2285 | { |
| 2286 | struct nfs4_exception exception = { }; |
| 2287 | int err; |
| 2288 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2289 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2290 | switch (err) { |
| 2291 | case 0: |
| 2292 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2293 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2294 | default: |
| 2295 | err = nfs4_handle_exception(server, err, &exception); |
| 2296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2298 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | return err; |
| 2300 | } |
| 2301 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2302 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2303 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2304 | { |
| 2305 | struct rpc_auth *auth; |
| 2306 | int ret; |
| 2307 | |
| 2308 | auth = rpcauth_create(flavor, server->client); |
| 2309 | if (!auth) { |
| 2310 | ret = -EIO; |
| 2311 | goto out; |
| 2312 | } |
| 2313 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2314 | out: |
| 2315 | return ret; |
| 2316 | } |
| 2317 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2318 | 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] | 2319 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2321 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2322 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2324 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2325 | flav_array[len] = RPC_AUTH_NULL; |
| 2326 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2327 | |
| 2328 | for (i = 0; i < len; i++) { |
| 2329 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2330 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2331 | continue; |
| 2332 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2333 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2334 | /* |
| 2335 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2336 | * to access the mount. It could also mean that we tried to mount |
| 2337 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2338 | * existing mount programs don't handle -EACCES very well so it should |
| 2339 | * be mapped to -EPERM instead. |
| 2340 | */ |
| 2341 | if (status == -EACCES) |
| 2342 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2343 | return status; |
| 2344 | } |
| 2345 | |
| 2346 | /* |
| 2347 | * get the file handle for the "/" directory on the server |
| 2348 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2349 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2350 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2351 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2352 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2353 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2354 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2355 | /* |
| 2356 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2357 | * by nfs4_map_errors() as this function exits. |
| 2358 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2359 | 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] | 2360 | if (status == 0) |
| 2361 | status = nfs4_server_capabilities(server, fhandle); |
| 2362 | if (status == 0) |
| 2363 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2364 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2367 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2368 | struct nfs_fsinfo *info) |
| 2369 | { |
| 2370 | int error; |
| 2371 | struct nfs_fattr *fattr = info->fattr; |
| 2372 | |
| 2373 | error = nfs4_server_capabilities(server, mntfh); |
| 2374 | if (error < 0) { |
| 2375 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2376 | return error; |
| 2377 | } |
| 2378 | |
| 2379 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2380 | if (error < 0) { |
| 2381 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2382 | return error; |
| 2383 | } |
| 2384 | |
| 2385 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2386 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2387 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2388 | |
| 2389 | return error; |
| 2390 | } |
| 2391 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2392 | /* |
| 2393 | * Get locations and (maybe) other attributes of a referral. |
| 2394 | * Note that we'll actually follow the referral later when |
| 2395 | * we detect fsid mismatch in inode revalidation |
| 2396 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2397 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2398 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2399 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2400 | { |
| 2401 | int status = -ENOMEM; |
| 2402 | struct page *page = NULL; |
| 2403 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2404 | |
| 2405 | page = alloc_page(GFP_KERNEL); |
| 2406 | if (page == NULL) |
| 2407 | goto out; |
| 2408 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2409 | if (locations == NULL) |
| 2410 | goto out; |
| 2411 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2412 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2413 | if (status != 0) |
| 2414 | goto out; |
| 2415 | /* Make sure server returned a different fsid for the referral */ |
| 2416 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2417 | dprintk("%s: server did not return a different fsid for" |
| 2418 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2419 | status = -EIO; |
| 2420 | goto out; |
| 2421 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2422 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2423 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2424 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2425 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2426 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2427 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2428 | out: |
| 2429 | if (page) |
| 2430 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2431 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2432 | return status; |
| 2433 | } |
| 2434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2436 | { |
| 2437 | struct nfs4_getattr_arg args = { |
| 2438 | .fh = fhandle, |
| 2439 | .bitmask = server->attr_bitmask, |
| 2440 | }; |
| 2441 | struct nfs4_getattr_res res = { |
| 2442 | .fattr = fattr, |
| 2443 | .server = server, |
| 2444 | }; |
| 2445 | struct rpc_message msg = { |
| 2446 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2447 | .rpc_argp = &args, |
| 2448 | .rpc_resp = &res, |
| 2449 | }; |
| 2450 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2451 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2452 | 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] | 2453 | } |
| 2454 | |
| 2455 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2456 | { |
| 2457 | struct nfs4_exception exception = { }; |
| 2458 | int err; |
| 2459 | do { |
| 2460 | err = nfs4_handle_exception(server, |
| 2461 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2462 | &exception); |
| 2463 | } while (exception.retry); |
| 2464 | return err; |
| 2465 | } |
| 2466 | |
| 2467 | /* |
| 2468 | * The file is not closed if it is opened due to the a request to change |
| 2469 | * the size of the file. The open call will not be needed once the |
| 2470 | * VFS layer lookup-intents are implemented. |
| 2471 | * |
| 2472 | * Close is called when the inode is destroyed. |
| 2473 | * If we haven't opened the file for O_WRONLY, we |
| 2474 | * need to in the size_change case to obtain a stateid. |
| 2475 | * |
| 2476 | * Got race? |
| 2477 | * Because OPEN is always done by name in nfsv4, it is |
| 2478 | * possible that we opened a different file by the same |
| 2479 | * name. We can recognize this race condition, but we |
| 2480 | * can't do anything about it besides returning an error. |
| 2481 | * |
| 2482 | * This will be fixed with VFS changes (lookup-intent). |
| 2483 | */ |
| 2484 | static int |
| 2485 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2486 | struct iattr *sattr) |
| 2487 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2488 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2489 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2490 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | int status; |
| 2492 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2493 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2494 | pnfs_return_layout(inode); |
| 2495 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2496 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2498 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2499 | if (sattr->ia_valid & ATTR_FILE) { |
| 2500 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2501 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2502 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2503 | if (ctx) { |
| 2504 | cred = ctx->cred; |
| 2505 | state = ctx->state; |
| 2506 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2507 | } |
| 2508 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 2509 | /* Deal with open(O_TRUNC) */ |
| 2510 | if (sattr->ia_valid & ATTR_OPEN) |
| 2511 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2512 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2513 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2514 | if (status == 0) |
| 2515 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | return status; |
| 2517 | } |
| 2518 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2519 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2520 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2521 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2522 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2523 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2524 | int status; |
| 2525 | struct nfs4_lookup_arg args = { |
| 2526 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2527 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2528 | .name = name, |
| 2529 | }; |
| 2530 | struct nfs4_lookup_res res = { |
| 2531 | .server = server, |
| 2532 | .fattr = fattr, |
| 2533 | .fh = fhandle, |
| 2534 | }; |
| 2535 | struct rpc_message msg = { |
| 2536 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2537 | .rpc_argp = &args, |
| 2538 | .rpc_resp = &res, |
| 2539 | }; |
| 2540 | |
| 2541 | nfs_fattr_init(fattr); |
| 2542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2544 | 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] | 2545 | dprintk("NFS reply lookup: %d\n", status); |
| 2546 | return status; |
| 2547 | } |
| 2548 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2549 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2550 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2551 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2552 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2553 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2554 | fattr->nlink = 2; |
| 2555 | } |
| 2556 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2557 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2558 | struct qstr *name, struct nfs_fh *fhandle, |
| 2559 | struct nfs_fattr *fattr) |
| 2560 | { |
| 2561 | struct nfs4_exception exception = { }; |
| 2562 | struct rpc_clnt *client = *clnt; |
| 2563 | int err; |
| 2564 | do { |
| 2565 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2566 | switch (err) { |
| 2567 | case -NFS4ERR_BADNAME: |
| 2568 | err = -ENOENT; |
| 2569 | goto out; |
| 2570 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2571 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2572 | goto out; |
| 2573 | case -NFS4ERR_WRONGSEC: |
| 2574 | err = -EPERM; |
| 2575 | if (client != *clnt) |
| 2576 | goto out; |
| 2577 | |
| 2578 | client = nfs4_create_sec_client(client, dir, name); |
| 2579 | if (IS_ERR(client)) |
| 2580 | return PTR_ERR(client); |
| 2581 | |
| 2582 | exception.retry = 1; |
| 2583 | break; |
| 2584 | default: |
| 2585 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2586 | } |
| 2587 | } while (exception.retry); |
| 2588 | |
| 2589 | out: |
| 2590 | if (err == 0) |
| 2591 | *clnt = client; |
| 2592 | else if (client != *clnt) |
| 2593 | rpc_shutdown_client(client); |
| 2594 | |
| 2595 | return err; |
| 2596 | } |
| 2597 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2598 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2599 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2601 | int status; |
| 2602 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2603 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2604 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2605 | if (client != NFS_CLIENT(dir)) { |
| 2606 | rpc_shutdown_client(client); |
| 2607 | nfs_fixup_secinfo_attributes(fattr); |
| 2608 | } |
| 2609 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2612 | struct rpc_clnt * |
| 2613 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2614 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2615 | { |
| 2616 | int status; |
| 2617 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2618 | |
| 2619 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2620 | if (status < 0) { |
| 2621 | rpc_shutdown_client(client); |
| 2622 | return ERR_PTR(status); |
| 2623 | } |
| 2624 | return client; |
| 2625 | } |
| 2626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2628 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2629 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | struct nfs4_accessargs args = { |
| 2631 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2632 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2634 | struct nfs4_accessres res = { |
| 2635 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2636 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | struct rpc_message msg = { |
| 2638 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2639 | .rpc_argp = &args, |
| 2640 | .rpc_resp = &res, |
| 2641 | .rpc_cred = entry->cred, |
| 2642 | }; |
| 2643 | int mode = entry->mask; |
| 2644 | int status; |
| 2645 | |
| 2646 | /* |
| 2647 | * Determine which access bits we want to ask for... |
| 2648 | */ |
| 2649 | if (mode & MAY_READ) |
| 2650 | args.access |= NFS4_ACCESS_READ; |
| 2651 | if (S_ISDIR(inode->i_mode)) { |
| 2652 | if (mode & MAY_WRITE) |
| 2653 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2654 | if (mode & MAY_EXEC) |
| 2655 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2656 | } else { |
| 2657 | if (mode & MAY_WRITE) |
| 2658 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2659 | if (mode & MAY_EXEC) |
| 2660 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2661 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2662 | |
| 2663 | res.fattr = nfs_alloc_fattr(); |
| 2664 | if (res.fattr == NULL) |
| 2665 | return -ENOMEM; |
| 2666 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2667 | 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] | 2668 | if (!status) { |
| 2669 | entry->mask = 0; |
| 2670 | if (res.access & NFS4_ACCESS_READ) |
| 2671 | entry->mask |= MAY_READ; |
| 2672 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2673 | entry->mask |= MAY_WRITE; |
| 2674 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2675 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2676 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2678 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | return status; |
| 2680 | } |
| 2681 | |
| 2682 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2683 | { |
| 2684 | struct nfs4_exception exception = { }; |
| 2685 | int err; |
| 2686 | do { |
| 2687 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2688 | _nfs4_proc_access(inode, entry), |
| 2689 | &exception); |
| 2690 | } while (exception.retry); |
| 2691 | return err; |
| 2692 | } |
| 2693 | |
| 2694 | /* |
| 2695 | * TODO: For the time being, we don't try to get any attributes |
| 2696 | * along with any of the zero-copy operations READ, READDIR, |
| 2697 | * READLINK, WRITE. |
| 2698 | * |
| 2699 | * In the case of the first three, we want to put the GETATTR |
| 2700 | * after the read-type operation -- this is because it is hard |
| 2701 | * to predict the length of a GETATTR response in v4, and thus |
| 2702 | * align the READ data correctly. This means that the GETATTR |
| 2703 | * may end up partially falling into the page cache, and we should |
| 2704 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2705 | * To do this efficiently, we need to know the total length |
| 2706 | * of data received, which doesn't seem to be available outside |
| 2707 | * of the RPC layer. |
| 2708 | * |
| 2709 | * In the case of WRITE, we also want to put the GETATTR after |
| 2710 | * the operation -- in this case because we want to make sure |
| 2711 | * we get the post-operation mtime and size. This means that |
| 2712 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2713 | * of it which would leave room in the 'tail' iovec. |
| 2714 | * |
| 2715 | * Both of these changes to the XDR layer would in fact be quite |
| 2716 | * minor, but I decided to leave them for a subsequent patch. |
| 2717 | */ |
| 2718 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2719 | unsigned int pgbase, unsigned int pglen) |
| 2720 | { |
| 2721 | struct nfs4_readlink args = { |
| 2722 | .fh = NFS_FH(inode), |
| 2723 | .pgbase = pgbase, |
| 2724 | .pglen = pglen, |
| 2725 | .pages = &page, |
| 2726 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2727 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | struct rpc_message msg = { |
| 2729 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2730 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2731 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | }; |
| 2733 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2734 | 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] | 2735 | } |
| 2736 | |
| 2737 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2738 | unsigned int pgbase, unsigned int pglen) |
| 2739 | { |
| 2740 | struct nfs4_exception exception = { }; |
| 2741 | int err; |
| 2742 | do { |
| 2743 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2744 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2745 | &exception); |
| 2746 | } while (exception.retry); |
| 2747 | return err; |
| 2748 | } |
| 2749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | /* |
| 2751 | * Got race? |
| 2752 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2753 | * Until then, this create/open method is prone to inefficiency and race |
| 2754 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2755 | * placed on the wire. |
| 2756 | * |
| 2757 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2758 | * The file will be opened again in the subsequent VFS open call |
| 2759 | * (nfs4_proc_file_open). |
| 2760 | * |
| 2761 | * The open for read will just hang around to be used by any process that |
| 2762 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2763 | */ |
| 2764 | |
| 2765 | static int |
| 2766 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2767 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2769 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2771 | struct rpc_cred *cred = NULL; |
| 2772 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | int status = 0; |
| 2774 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2775 | if (ctx != NULL) { |
| 2776 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2777 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2778 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2780 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2781 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2782 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | if (IS_ERR(state)) { |
| 2784 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2785 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2787 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2788 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2789 | if (ctx != NULL) |
| 2790 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2791 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2792 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | out: |
| 2794 | return status; |
| 2795 | } |
| 2796 | |
| 2797 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2798 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2799 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2800 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2802 | .name.len = name->len, |
| 2803 | .name.name = name->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2805 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2806 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2807 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2809 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2810 | .rpc_argp = &args, |
| 2811 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2813 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2814 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2815 | 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] | 2816 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2817 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | return status; |
| 2819 | } |
| 2820 | |
| 2821 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2822 | { |
| 2823 | struct nfs4_exception exception = { }; |
| 2824 | int err; |
| 2825 | do { |
| 2826 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2827 | _nfs4_proc_remove(dir, name), |
| 2828 | &exception); |
| 2829 | } while (exception.retry); |
| 2830 | return err; |
| 2831 | } |
| 2832 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2833 | 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] | 2834 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2835 | struct nfs_server *server = NFS_SERVER(dir); |
| 2836 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2837 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2839 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2841 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2844 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2845 | { |
| 2846 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2847 | &data->args.seq_args, |
| 2848 | &data->res.seq_res, |
| 2849 | task)) |
| 2850 | return; |
| 2851 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2854 | 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] | 2855 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2856 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2857 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2858 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2859 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2860 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2861 | return 0; |
| 2862 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2863 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2866 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2867 | { |
| 2868 | struct nfs_server *server = NFS_SERVER(dir); |
| 2869 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2870 | struct nfs_renameres *res = msg->rpc_resp; |
| 2871 | |
| 2872 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2873 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2874 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2875 | } |
| 2876 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2877 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2878 | { |
| 2879 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2880 | &data->args.seq_args, |
| 2881 | &data->res.seq_res, |
| 2882 | task)) |
| 2883 | return; |
| 2884 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2888 | struct inode *new_dir) |
| 2889 | { |
| 2890 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2891 | |
| 2892 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2893 | return 0; |
| 2894 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2895 | return 0; |
| 2896 | |
| 2897 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2898 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2899 | return 1; |
| 2900 | } |
| 2901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2903 | struct inode *new_dir, struct qstr *new_name) |
| 2904 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2905 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2906 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | .old_dir = NFS_FH(old_dir), |
| 2908 | .new_dir = NFS_FH(new_dir), |
| 2909 | .old_name = old_name, |
| 2910 | .new_name = new_name, |
| 2911 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2912 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2913 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2914 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | struct rpc_message msg = { |
| 2916 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2917 | .rpc_argp = &arg, |
| 2918 | .rpc_resp = &res, |
| 2919 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2920 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2922 | 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] | 2923 | if (!status) { |
| 2924 | update_changeattr(old_dir, &res.old_cinfo); |
| 2925 | update_changeattr(new_dir, &res.new_cinfo); |
| 2926 | } |
| 2927 | return status; |
| 2928 | } |
| 2929 | |
| 2930 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2931 | struct inode *new_dir, struct qstr *new_name) |
| 2932 | { |
| 2933 | struct nfs4_exception exception = { }; |
| 2934 | int err; |
| 2935 | do { |
| 2936 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2937 | _nfs4_proc_rename(old_dir, old_name, |
| 2938 | new_dir, new_name), |
| 2939 | &exception); |
| 2940 | } while (exception.retry); |
| 2941 | return err; |
| 2942 | } |
| 2943 | |
| 2944 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2945 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2946 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | struct nfs4_link_arg arg = { |
| 2948 | .fh = NFS_FH(inode), |
| 2949 | .dir_fh = NFS_FH(dir), |
| 2950 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2951 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2953 | struct nfs4_link_res res = { |
| 2954 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2955 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | struct rpc_message msg = { |
| 2957 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2958 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2959 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2961 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2963 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2964 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2965 | goto out; |
| 2966 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2967 | 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] | 2968 | if (!status) { |
| 2969 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2970 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2971 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2972 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2973 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | return status; |
| 2975 | } |
| 2976 | |
| 2977 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2978 | { |
| 2979 | struct nfs4_exception exception = { }; |
| 2980 | int err; |
| 2981 | do { |
| 2982 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2983 | _nfs4_proc_link(inode, dir, name), |
| 2984 | &exception); |
| 2985 | } while (exception.retry); |
| 2986 | return err; |
| 2987 | } |
| 2988 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2989 | struct nfs4_createdata { |
| 2990 | struct rpc_message msg; |
| 2991 | struct nfs4_create_arg arg; |
| 2992 | struct nfs4_create_res res; |
| 2993 | struct nfs_fh fh; |
| 2994 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2995 | }; |
| 2996 | |
| 2997 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2998 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2999 | { |
| 3000 | struct nfs4_createdata *data; |
| 3001 | |
| 3002 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3003 | if (data != NULL) { |
| 3004 | struct nfs_server *server = NFS_SERVER(dir); |
| 3005 | |
| 3006 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3007 | data->msg.rpc_argp = &data->arg; |
| 3008 | data->msg.rpc_resp = &data->res; |
| 3009 | data->arg.dir_fh = NFS_FH(dir); |
| 3010 | data->arg.server = server; |
| 3011 | data->arg.name = name; |
| 3012 | data->arg.attrs = sattr; |
| 3013 | data->arg.ftype = ftype; |
| 3014 | data->arg.bitmask = server->attr_bitmask; |
| 3015 | data->res.server = server; |
| 3016 | data->res.fh = &data->fh; |
| 3017 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3018 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3019 | } |
| 3020 | return data; |
| 3021 | } |
| 3022 | |
| 3023 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3024 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3025 | 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] | 3026 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3027 | if (status == 0) { |
| 3028 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3029 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3030 | } |
| 3031 | return status; |
| 3032 | } |
| 3033 | |
| 3034 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3035 | { |
| 3036 | kfree(data); |
| 3037 | } |
| 3038 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3039 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3040 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3042 | struct nfs4_createdata *data; |
| 3043 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3045 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3046 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3047 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3048 | status = -ENOMEM; |
| 3049 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3050 | if (data == NULL) |
| 3051 | goto out; |
| 3052 | |
| 3053 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3054 | data->arg.u.symlink.pages = &page; |
| 3055 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3057 | status = nfs4_do_create(dir, dentry, data); |
| 3058 | |
| 3059 | nfs4_free_createdata(data); |
| 3060 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | return status; |
| 3062 | } |
| 3063 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3064 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3065 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | { |
| 3067 | struct nfs4_exception exception = { }; |
| 3068 | int err; |
| 3069 | do { |
| 3070 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3071 | _nfs4_proc_symlink(dir, dentry, page, |
| 3072 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | &exception); |
| 3074 | } while (exception.retry); |
| 3075 | return err; |
| 3076 | } |
| 3077 | |
| 3078 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3079 | struct iattr *sattr) |
| 3080 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3081 | struct nfs4_createdata *data; |
| 3082 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3084 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3085 | if (data == NULL) |
| 3086 | goto out; |
| 3087 | |
| 3088 | status = nfs4_do_create(dir, dentry, data); |
| 3089 | |
| 3090 | nfs4_free_createdata(data); |
| 3091 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | return status; |
| 3093 | } |
| 3094 | |
| 3095 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3096 | struct iattr *sattr) |
| 3097 | { |
| 3098 | struct nfs4_exception exception = { }; |
| 3099 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3100 | |
| 3101 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | do { |
| 3103 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3104 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3105 | &exception); |
| 3106 | } while (exception.retry); |
| 3107 | return err; |
| 3108 | } |
| 3109 | |
| 3110 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3111 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | { |
| 3113 | struct inode *dir = dentry->d_inode; |
| 3114 | struct nfs4_readdir_arg args = { |
| 3115 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3116 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | .pgbase = 0, |
| 3118 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3119 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3120 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | }; |
| 3122 | struct nfs4_readdir_res res; |
| 3123 | struct rpc_message msg = { |
| 3124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3125 | .rpc_argp = &args, |
| 3126 | .rpc_resp = &res, |
| 3127 | .rpc_cred = cred, |
| 3128 | }; |
| 3129 | int status; |
| 3130 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3131 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3132 | dentry->d_parent->d_name.name, |
| 3133 | dentry->d_name.name, |
| 3134 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3136 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3137 | 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] | 3138 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3140 | status += args.pgbase; |
| 3141 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3142 | |
| 3143 | nfs_invalidate_atime(dir); |
| 3144 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3145 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | return status; |
| 3147 | } |
| 3148 | |
| 3149 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3150 | u64 cookie, struct page **pages, unsigned int count, int plus) |
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(dentry->d_inode), |
| 3156 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3157 | pages, count, plus), |
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_mknod(struct inode *dir, struct dentry *dentry, |
| 3164 | struct iattr *sattr, dev_t rdev) |
| 3165 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3166 | struct nfs4_createdata *data; |
| 3167 | int mode = sattr->ia_mode; |
| 3168 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
| 3170 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3171 | 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] | 3172 | |
| 3173 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3174 | if (data == NULL) |
| 3175 | goto out; |
| 3176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3178 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3180 | data->arg.ftype = NF4BLK; |
| 3181 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3182 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | } |
| 3184 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3185 | data->arg.ftype = NF4CHR; |
| 3186 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3187 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3190 | status = nfs4_do_create(dir, dentry, data); |
| 3191 | |
| 3192 | nfs4_free_createdata(data); |
| 3193 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | return status; |
| 3195 | } |
| 3196 | |
| 3197 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3198 | struct iattr *sattr, dev_t rdev) |
| 3199 | { |
| 3200 | struct nfs4_exception exception = { }; |
| 3201 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3202 | |
| 3203 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | do { |
| 3205 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3206 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3207 | &exception); |
| 3208 | } while (exception.retry); |
| 3209 | return err; |
| 3210 | } |
| 3211 | |
| 3212 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3213 | struct nfs_fsstat *fsstat) |
| 3214 | { |
| 3215 | struct nfs4_statfs_arg args = { |
| 3216 | .fh = fhandle, |
| 3217 | .bitmask = server->attr_bitmask, |
| 3218 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3219 | struct nfs4_statfs_res res = { |
| 3220 | .fsstat = fsstat, |
| 3221 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | struct rpc_message msg = { |
| 3223 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3224 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3225 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | }; |
| 3227 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3228 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3229 | 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] | 3230 | } |
| 3231 | |
| 3232 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3233 | { |
| 3234 | struct nfs4_exception exception = { }; |
| 3235 | int err; |
| 3236 | do { |
| 3237 | err = nfs4_handle_exception(server, |
| 3238 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3239 | &exception); |
| 3240 | } while (exception.retry); |
| 3241 | return err; |
| 3242 | } |
| 3243 | |
| 3244 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3245 | struct nfs_fsinfo *fsinfo) |
| 3246 | { |
| 3247 | struct nfs4_fsinfo_arg args = { |
| 3248 | .fh = fhandle, |
| 3249 | .bitmask = server->attr_bitmask, |
| 3250 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3251 | struct nfs4_fsinfo_res res = { |
| 3252 | .fsinfo = fsinfo, |
| 3253 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | struct rpc_message msg = { |
| 3255 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3256 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3257 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | }; |
| 3259 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3260 | 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] | 3261 | } |
| 3262 | |
| 3263 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3264 | { |
| 3265 | struct nfs4_exception exception = { }; |
| 3266 | int err; |
| 3267 | |
| 3268 | do { |
| 3269 | err = nfs4_handle_exception(server, |
| 3270 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3271 | &exception); |
| 3272 | } while (exception.retry); |
| 3273 | return err; |
| 3274 | } |
| 3275 | |
| 3276 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3277 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3278 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3280 | } |
| 3281 | |
| 3282 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3283 | struct nfs_pathconf *pathconf) |
| 3284 | { |
| 3285 | struct nfs4_pathconf_arg args = { |
| 3286 | .fh = fhandle, |
| 3287 | .bitmask = server->attr_bitmask, |
| 3288 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3289 | struct nfs4_pathconf_res res = { |
| 3290 | .pathconf = pathconf, |
| 3291 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | struct rpc_message msg = { |
| 3293 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3294 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3295 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | }; |
| 3297 | |
| 3298 | /* None of the pathconf attributes are mandatory to implement */ |
| 3299 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3300 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3301 | return 0; |
| 3302 | } |
| 3303 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3304 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3305 | 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] | 3306 | } |
| 3307 | |
| 3308 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3309 | struct nfs_pathconf *pathconf) |
| 3310 | { |
| 3311 | struct nfs4_exception exception = { }; |
| 3312 | int err; |
| 3313 | |
| 3314 | do { |
| 3315 | err = nfs4_handle_exception(server, |
| 3316 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3317 | &exception); |
| 3318 | } while (exception.retry); |
| 3319 | return err; |
| 3320 | } |
| 3321 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3322 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3323 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3324 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3325 | } |
| 3326 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3327 | 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] | 3328 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3329 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3331 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3332 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3333 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3335 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3336 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3338 | renew_lease(server, data->timestamp); |
| 3339 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3342 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3343 | { |
| 3344 | |
| 3345 | dprintk("--> %s\n", __func__); |
| 3346 | |
| 3347 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3348 | return -EAGAIN; |
| 3349 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3350 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3351 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3354 | 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] | 3355 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3357 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3358 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3359 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3362 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3363 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3364 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3365 | &data->args.seq_args, |
| 3366 | &data->res.seq_res, |
| 3367 | task)) |
| 3368 | return; |
| 3369 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3372 | 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] | 3373 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3374 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3376 | 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] | 3377 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3378 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3380 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3382 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3383 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3384 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3387 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3388 | { |
| 3389 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3390 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3391 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3392 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3393 | } |
| 3394 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3395 | static |
| 3396 | bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data) |
| 3397 | { |
| 3398 | const struct nfs_pgio_header *hdr = data->header; |
| 3399 | |
| 3400 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3401 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3402 | return false; |
| 3403 | /* Otherwise, request attributes if and only if we don't hold |
| 3404 | * a delegation |
| 3405 | */ |
| 3406 | return nfs_have_delegation(hdr->inode, FMODE_READ) == 0; |
| 3407 | } |
| 3408 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3409 | 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] | 3410 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3411 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3412 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3413 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3414 | data->args.bitmask = NULL; |
| 3415 | data->res.fattr = NULL; |
| 3416 | } else |
| 3417 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3418 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3419 | if (!data->write_done_cb) |
| 3420 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3421 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | data->timestamp = jiffies; |
| 3423 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3424 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3425 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3428 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3429 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3430 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3431 | &data->args.seq_args, |
| 3432 | &data->res.seq_res, |
| 3433 | task)) |
| 3434 | return; |
| 3435 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3438 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3439 | { |
| 3440 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3441 | &data->args.seq_args, |
| 3442 | &data->res.seq_res, |
| 3443 | task)) |
| 3444 | return; |
| 3445 | rpc_call_start(task); |
| 3446 | } |
| 3447 | |
| 3448 | 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] | 3449 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3451 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3452 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3453 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3454 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3456 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3459 | 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] | 3460 | { |
| 3461 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3462 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3463 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3464 | } |
| 3465 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3466 | 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] | 3467 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3468 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3469 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3470 | if (data->commit_done_cb == NULL) |
| 3471 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3472 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3473 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3474 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3477 | struct nfs4_renewdata { |
| 3478 | struct nfs_client *client; |
| 3479 | unsigned long timestamp; |
| 3480 | }; |
| 3481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | /* |
| 3483 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3484 | * standalone procedure for queueing an asynchronous RENEW. |
| 3485 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3486 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3487 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3488 | struct nfs4_renewdata *data = calldata; |
| 3489 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3490 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3491 | if (atomic_read(&clp->cl_count) > 1) |
| 3492 | nfs4_schedule_state_renewal(clp); |
| 3493 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3494 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3495 | } |
| 3496 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3497 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3499 | struct nfs4_renewdata *data = calldata; |
| 3500 | struct nfs_client *clp = data->client; |
| 3501 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | |
| 3503 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3504 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3505 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3506 | return; |
| 3507 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3508 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3509 | return; |
| 3510 | } |
| 3511 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3513 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3516 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3517 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3518 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3519 | }; |
| 3520 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3521 | 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] | 3522 | { |
| 3523 | struct rpc_message msg = { |
| 3524 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3525 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3526 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3528 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3530 | if (renew_flags == 0) |
| 3531 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3532 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3533 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3534 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3535 | if (data == NULL) |
| 3536 | return -ENOMEM; |
| 3537 | data->client = clp; |
| 3538 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3540 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3543 | 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] | 3544 | { |
| 3545 | struct rpc_message msg = { |
| 3546 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3547 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3548 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | }; |
| 3550 | unsigned long now = jiffies; |
| 3551 | int status; |
| 3552 | |
| 3553 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3554 | if (status < 0) |
| 3555 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3556 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | return 0; |
| 3558 | } |
| 3559 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3560 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3561 | { |
| 3562 | return (server->caps & NFS_CAP_ACLS) |
| 3563 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3564 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3565 | } |
| 3566 | |
| 3567 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3568 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3569 | * the stack. |
| 3570 | */ |
| 3571 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3572 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3573 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3574 | struct page **pages, unsigned int *pgbase) |
| 3575 | { |
| 3576 | struct page *newpage, **spages; |
| 3577 | int rc = 0; |
| 3578 | size_t len; |
| 3579 | spages = pages; |
| 3580 | |
| 3581 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3582 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3583 | newpage = alloc_page(GFP_KERNEL); |
| 3584 | |
| 3585 | if (newpage == NULL) |
| 3586 | goto unwind; |
| 3587 | memcpy(page_address(newpage), buf, len); |
| 3588 | buf += len; |
| 3589 | buflen -= len; |
| 3590 | *pages++ = newpage; |
| 3591 | rc++; |
| 3592 | } while (buflen != 0); |
| 3593 | |
| 3594 | return rc; |
| 3595 | |
| 3596 | unwind: |
| 3597 | for(; rc > 0; rc--) |
| 3598 | __free_page(spages[rc-1]); |
| 3599 | return -ENOMEM; |
| 3600 | } |
| 3601 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3602 | struct nfs4_cached_acl { |
| 3603 | int cached; |
| 3604 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3605 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3606 | }; |
| 3607 | |
| 3608 | 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] | 3609 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3610 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3611 | |
| 3612 | spin_lock(&inode->i_lock); |
| 3613 | kfree(nfsi->nfs4_acl); |
| 3614 | nfsi->nfs4_acl = acl; |
| 3615 | spin_unlock(&inode->i_lock); |
| 3616 | } |
| 3617 | |
| 3618 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3619 | { |
| 3620 | nfs4_set_cached_acl(inode, NULL); |
| 3621 | } |
| 3622 | |
| 3623 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3624 | { |
| 3625 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3626 | struct nfs4_cached_acl *acl; |
| 3627 | int ret = -ENOENT; |
| 3628 | |
| 3629 | spin_lock(&inode->i_lock); |
| 3630 | acl = nfsi->nfs4_acl; |
| 3631 | if (acl == NULL) |
| 3632 | goto out; |
| 3633 | if (buf == NULL) /* user is just asking for length */ |
| 3634 | goto out_len; |
| 3635 | if (acl->cached == 0) |
| 3636 | goto out; |
| 3637 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3638 | if (acl->len > buflen) |
| 3639 | goto out; |
| 3640 | memcpy(buf, acl->data, acl->len); |
| 3641 | out_len: |
| 3642 | ret = acl->len; |
| 3643 | out: |
| 3644 | spin_unlock(&inode->i_lock); |
| 3645 | return ret; |
| 3646 | } |
| 3647 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3648 | 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] | 3649 | { |
| 3650 | struct nfs4_cached_acl *acl; |
| 3651 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3652 | if (pages && acl_len <= PAGE_SIZE) { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3653 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3654 | if (acl == NULL) |
| 3655 | goto out; |
| 3656 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3657 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3658 | } else { |
| 3659 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3660 | if (acl == NULL) |
| 3661 | goto out; |
| 3662 | acl->cached = 0; |
| 3663 | } |
| 3664 | acl->len = acl_len; |
| 3665 | out: |
| 3666 | nfs4_set_cached_acl(inode, acl); |
| 3667 | } |
| 3668 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3669 | /* |
| 3670 | * The getxattr API returns the required buffer length when called with a |
| 3671 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3672 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3673 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3674 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3675 | * the cache. If not so, we throw away the page, and cache the required |
| 3676 | * length. The next getxattr call will then produce another round trip to |
| 3677 | * the server, this time with the input buf of the required size. |
| 3678 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3679 | 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] | 3680 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3681 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3682 | struct nfs_getaclargs args = { |
| 3683 | .fh = NFS_FH(inode), |
| 3684 | .acl_pages = pages, |
| 3685 | .acl_len = buflen, |
| 3686 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3687 | struct nfs_getaclres res = { |
| 3688 | .acl_len = buflen, |
| 3689 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3690 | struct rpc_message msg = { |
| 3691 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3692 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3693 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3694 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3695 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3696 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3697 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3698 | /* As long as we're doing a round trip to the server anyway, |
| 3699 | * let's be prepared for a page of acl data. */ |
| 3700 | if (npages == 0) |
| 3701 | npages = 1; |
| 3702 | |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3703 | /* Add an extra page to handle the bitmap returned */ |
| 3704 | npages++; |
| 3705 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3706 | for (i = 0; i < npages; i++) { |
| 3707 | pages[i] = alloc_page(GFP_KERNEL); |
| 3708 | if (!pages[i]) |
| 3709 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3710 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3711 | |
| 3712 | /* for decoding across pages */ |
| 3713 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3714 | if (!res.acl_scratch) |
| 3715 | goto out_free; |
| 3716 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3717 | args.acl_len = npages * PAGE_SIZE; |
| 3718 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3719 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3720 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3721 | * the page we send as a guess */ |
| 3722 | if (buf == NULL) |
| 3723 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3724 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3725 | 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] | 3726 | __func__, buf, buflen, npages, args.acl_len); |
| 3727 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3728 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3729 | if (ret) |
| 3730 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3731 | |
| 3732 | acl_len = res.acl_len - res.acl_data_offset; |
| 3733 | if (acl_len > args.acl_len) |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3734 | nfs4_write_cached_acl(inode, NULL, 0, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3735 | else |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3736 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3737 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3738 | if (buf) { |
| 3739 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3740 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3741 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3742 | _copy_from_pages(buf, pages, res.acl_data_offset, |
Sachin Prabhu | 20e0fa9 | 2012-03-22 16:46:28 +0000 | [diff] [blame] | 3743 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3744 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3745 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3746 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3747 | for (i = 0; i < npages; i++) |
| 3748 | if (pages[i]) |
| 3749 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3750 | if (res.acl_scratch) |
| 3751 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3752 | return ret; |
| 3753 | } |
| 3754 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3755 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3756 | { |
| 3757 | struct nfs4_exception exception = { }; |
| 3758 | ssize_t ret; |
| 3759 | do { |
| 3760 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3761 | if (ret >= 0) |
| 3762 | break; |
| 3763 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3764 | } while (exception.retry); |
| 3765 | return ret; |
| 3766 | } |
| 3767 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3768 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3769 | { |
| 3770 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3771 | int ret; |
| 3772 | |
| 3773 | if (!nfs4_server_supports_acls(server)) |
| 3774 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3775 | ret = nfs_revalidate_inode(server, inode); |
| 3776 | if (ret < 0) |
| 3777 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3778 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3779 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3780 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3781 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3782 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3783 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3784 | return ret; |
| 3785 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3788 | 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] | 3789 | { |
| 3790 | struct nfs_server *server = NFS_SERVER(inode); |
| 3791 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3792 | struct nfs_setaclargs arg = { |
| 3793 | .fh = NFS_FH(inode), |
| 3794 | .acl_pages = pages, |
| 3795 | .acl_len = buflen, |
| 3796 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3797 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3798 | struct rpc_message msg = { |
| 3799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3800 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3801 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3802 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3803 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3804 | |
| 3805 | if (!nfs4_server_supports_acls(server)) |
| 3806 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3807 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3808 | if (i < 0) |
| 3809 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3810 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3811 | 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] | 3812 | |
| 3813 | /* |
| 3814 | * Free each page after tx, so the only ref left is |
| 3815 | * held by the network stack |
| 3816 | */ |
| 3817 | for (; i > 0; i--) |
| 3818 | put_page(pages[i-1]); |
| 3819 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3820 | /* |
| 3821 | * Acl update can result in inode attribute update. |
| 3822 | * so mark the attribute cache invalid. |
| 3823 | */ |
| 3824 | spin_lock(&inode->i_lock); |
| 3825 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3826 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3827 | nfs_access_zap_cache(inode); |
| 3828 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3829 | return ret; |
| 3830 | } |
| 3831 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3832 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3833 | { |
| 3834 | struct nfs4_exception exception = { }; |
| 3835 | int err; |
| 3836 | do { |
| 3837 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3838 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3839 | &exception); |
| 3840 | } while (exception.retry); |
| 3841 | return err; |
| 3842 | } |
| 3843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3845 | 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] | 3846 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3847 | struct nfs_client *clp = server->nfs_client; |
| 3848 | |
| 3849 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | return 0; |
| 3851 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3852 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3853 | case -NFS4ERR_ADMIN_REVOKED: |
| 3854 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3855 | if (state == NULL) |
| 3856 | break; |
| 3857 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3858 | case -NFS4ERR_OPENMODE: |
| 3859 | if (state == NULL) |
| 3860 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3861 | nfs4_schedule_stateid_recovery(server, state); |
| 3862 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3863 | case -NFS4ERR_EXPIRED: |
| 3864 | if (state != NULL) |
| 3865 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3867 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3868 | nfs4_schedule_lease_recovery(clp); |
| 3869 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3870 | #if defined(CONFIG_NFS_V4_1) |
| 3871 | case -NFS4ERR_BADSESSION: |
| 3872 | case -NFS4ERR_BADSLOT: |
| 3873 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3874 | case -NFS4ERR_DEADSESSION: |
| 3875 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3876 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3877 | case -NFS4ERR_SEQ_MISORDERED: |
| 3878 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3879 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3880 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3881 | task->tk_status = 0; |
| 3882 | return -EAGAIN; |
| 3883 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3885 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3886 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3887 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3889 | task->tk_status = 0; |
| 3890 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3891 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3892 | case -NFS4ERR_OLD_STATEID: |
| 3893 | task->tk_status = 0; |
| 3894 | return -EAGAIN; |
| 3895 | } |
| 3896 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3897 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3898 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3899 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3900 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3901 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3902 | task->tk_status = 0; |
| 3903 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | } |
| 3905 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3906 | static void nfs4_construct_boot_verifier(struct nfs_client *clp, |
| 3907 | nfs4_verifier *bootverf) |
| 3908 | { |
| 3909 | __be32 verf[2]; |
| 3910 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame^] | 3911 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 3912 | /* An impossible timestamp guarantees this value |
| 3913 | * will never match a generated boot time. */ |
| 3914 | verf[0] = 0; |
| 3915 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 3916 | } else { |
| 3917 | verf[0] = (__be32)clp->cl_boot_time.tv_sec; |
| 3918 | verf[1] = (__be32)clp->cl_boot_time.tv_nsec; |
| 3919 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3920 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 3921 | } |
| 3922 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3923 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3924 | unsigned short port, struct rpc_cred *cred, |
| 3925 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | { |
| 3927 | nfs4_verifier sc_verifier; |
| 3928 | struct nfs4_setclientid setclientid = { |
| 3929 | .sc_verifier = &sc_verifier, |
| 3930 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3931 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | }; |
| 3933 | struct rpc_message msg = { |
| 3934 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3935 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3936 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3937 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | int loop = 0; |
| 3940 | int status; |
| 3941 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3942 | nfs4_construct_boot_verifier(clp, &sc_verifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | |
| 3944 | for(;;) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3945 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3947 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3948 | clp->cl_ipaddr, |
| 3949 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3950 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3951 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3952 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3953 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | clp->cl_id_uniquifier); |
| 3955 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3956 | sizeof(setclientid.sc_netid), |
| 3957 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3958 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3960 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | clp->cl_ipaddr, port >> 8, port & 255); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3962 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3964 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | if (status != -NFS4ERR_CLID_INUSE) |
| 3966 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3967 | if (loop != 0) { |
| 3968 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3970 | } |
| 3971 | ++loop; |
| 3972 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | } |
| 3974 | return status; |
| 3975 | } |
| 3976 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3977 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3978 | struct nfs4_setclientid_res *arg, |
| 3979 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | { |
| 3981 | struct nfs_fsinfo fsinfo; |
| 3982 | struct rpc_message msg = { |
| 3983 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3984 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3986 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | }; |
| 3988 | unsigned long now; |
| 3989 | int status; |
| 3990 | |
| 3991 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3992 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | if (status == 0) { |
| 3994 | spin_lock(&clp->cl_lock); |
| 3995 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3996 | clp->cl_last_renewal = now; |
| 3997 | spin_unlock(&clp->cl_lock); |
| 3998 | } |
| 3999 | return status; |
| 4000 | } |
| 4001 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4002 | struct nfs4_delegreturndata { |
| 4003 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4004 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4005 | struct nfs_fh fh; |
| 4006 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4007 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4008 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4009 | int rpc_status; |
| 4010 | }; |
| 4011 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4012 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4013 | { |
| 4014 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4015 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4016 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4017 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4018 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4019 | switch (task->tk_status) { |
| 4020 | case -NFS4ERR_STALE_STATEID: |
| 4021 | case -NFS4ERR_EXPIRED: |
| 4022 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4023 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4024 | break; |
| 4025 | default: |
| 4026 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4027 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4028 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4029 | return; |
| 4030 | } |
| 4031 | } |
| 4032 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | static void nfs4_delegreturn_release(void *calldata) |
| 4036 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4037 | kfree(calldata); |
| 4038 | } |
| 4039 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4040 | #if defined(CONFIG_NFS_V4_1) |
| 4041 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4042 | { |
| 4043 | struct nfs4_delegreturndata *d_data; |
| 4044 | |
| 4045 | d_data = (struct nfs4_delegreturndata *)data; |
| 4046 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4047 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4048 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4049 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4050 | return; |
| 4051 | rpc_call_start(task); |
| 4052 | } |
| 4053 | #endif /* CONFIG_NFS_V4_1 */ |
| 4054 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4055 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4056 | #if defined(CONFIG_NFS_V4_1) |
| 4057 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4058 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4059 | .rpc_call_done = nfs4_delegreturn_done, |
| 4060 | .rpc_release = nfs4_delegreturn_release, |
| 4061 | }; |
| 4062 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4063 | 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] | 4064 | { |
| 4065 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4066 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4067 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4068 | struct rpc_message msg = { |
| 4069 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4070 | .rpc_cred = cred, |
| 4071 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4072 | struct rpc_task_setup task_setup_data = { |
| 4073 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4074 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4075 | .callback_ops = &nfs4_delegreturn_ops, |
| 4076 | .flags = RPC_TASK_ASYNC, |
| 4077 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4078 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4079 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4080 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4081 | if (data == NULL) |
| 4082 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4083 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4084 | data->args.fhandle = &data->fh; |
| 4085 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4086 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4087 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4088 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4089 | data->res.fattr = &data->fattr; |
| 4090 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4091 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4092 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4093 | data->rpc_status = 0; |
| 4094 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4095 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4096 | msg.rpc_argp = &data->args; |
| 4097 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4098 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4099 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4100 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4101 | if (!issync) |
| 4102 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4103 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4104 | if (status != 0) |
| 4105 | goto out; |
| 4106 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4107 | if (status == 0) |
| 4108 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4109 | else |
| 4110 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4111 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4112 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4113 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4116 | 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] | 4117 | { |
| 4118 | struct nfs_server *server = NFS_SERVER(inode); |
| 4119 | struct nfs4_exception exception = { }; |
| 4120 | int err; |
| 4121 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4122 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | switch (err) { |
| 4124 | case -NFS4ERR_STALE_STATEID: |
| 4125 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | case 0: |
| 4127 | return 0; |
| 4128 | } |
| 4129 | err = nfs4_handle_exception(server, err, &exception); |
| 4130 | } while (exception.retry); |
| 4131 | return err; |
| 4132 | } |
| 4133 | |
| 4134 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4135 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4136 | |
| 4137 | /* |
| 4138 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4139 | */ |
| 4140 | static unsigned long |
| 4141 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4142 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4143 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | timeout <<= 1; |
| 4145 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4146 | return NFS4_LOCK_MAXTIMEOUT; |
| 4147 | return timeout; |
| 4148 | } |
| 4149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4151 | { |
| 4152 | struct inode *inode = state->inode; |
| 4153 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4154 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4155 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4157 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4159 | struct nfs_lockt_res res = { |
| 4160 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | }; |
| 4162 | struct rpc_message msg = { |
| 4163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4164 | .rpc_argp = &arg, |
| 4165 | .rpc_resp = &res, |
| 4166 | .rpc_cred = state->owner->so_cred, |
| 4167 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | struct nfs4_lock_state *lsp; |
| 4169 | int status; |
| 4170 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4171 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4172 | status = nfs4_set_lock_state(state, request); |
| 4173 | if (status != 0) |
| 4174 | goto out; |
| 4175 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4176 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4177 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4178 | 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] | 4179 | switch (status) { |
| 4180 | case 0: |
| 4181 | request->fl_type = F_UNLCK; |
| 4182 | break; |
| 4183 | case -NFS4ERR_DENIED: |
| 4184 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4186 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4187 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | return status; |
| 4189 | } |
| 4190 | |
| 4191 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4192 | { |
| 4193 | struct nfs4_exception exception = { }; |
| 4194 | int err; |
| 4195 | |
| 4196 | do { |
| 4197 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4198 | _nfs4_proc_getlk(state, cmd, request), |
| 4199 | &exception); |
| 4200 | } while (exception.retry); |
| 4201 | return err; |
| 4202 | } |
| 4203 | |
| 4204 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4205 | { |
| 4206 | int res = 0; |
| 4207 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4208 | case FL_POSIX: |
| 4209 | res = posix_lock_file_wait(file, fl); |
| 4210 | break; |
| 4211 | case FL_FLOCK: |
| 4212 | res = flock_lock_file_wait(file, fl); |
| 4213 | break; |
| 4214 | default: |
| 4215 | BUG(); |
| 4216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | return res; |
| 4218 | } |
| 4219 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4220 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4221 | struct nfs_locku_args arg; |
| 4222 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4223 | struct nfs4_lock_state *lsp; |
| 4224 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4225 | struct file_lock fl; |
| 4226 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4227 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4228 | }; |
| 4229 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4230 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4231 | struct nfs_open_context *ctx, |
| 4232 | struct nfs4_lock_state *lsp, |
| 4233 | struct nfs_seqid *seqid) |
| 4234 | { |
| 4235 | struct nfs4_unlockdata *p; |
| 4236 | struct inode *inode = lsp->ls_state->inode; |
| 4237 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4238 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4239 | if (p == NULL) |
| 4240 | return NULL; |
| 4241 | p->arg.fh = NFS_FH(inode); |
| 4242 | p->arg.fl = &p->fl; |
| 4243 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4244 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4245 | p->arg.stateid = &lsp->ls_stateid; |
| 4246 | p->lsp = lsp; |
| 4247 | atomic_inc(&lsp->ls_count); |
| 4248 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4249 | p->ctx = get_nfs_open_context(ctx); |
| 4250 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4251 | p->server = NFS_SERVER(inode); |
| 4252 | return p; |
| 4253 | } |
| 4254 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4255 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4256 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4257 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4258 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4259 | nfs4_put_lock_state(calldata->lsp); |
| 4260 | put_nfs_open_context(calldata->ctx); |
| 4261 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4264 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4265 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4266 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4267 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4268 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4269 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4270 | switch (task->tk_status) { |
| 4271 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4272 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4273 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4274 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4275 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4276 | case -NFS4ERR_BAD_STATEID: |
| 4277 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4278 | case -NFS4ERR_STALE_STATEID: |
| 4279 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4280 | break; |
| 4281 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4282 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4283 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4284 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4287 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4288 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4289 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4291 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4292 | return; |
| 4293 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4294 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4295 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4296 | return; |
| 4297 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4298 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4299 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4300 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4301 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4302 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4303 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4306 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4307 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4308 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4309 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4310 | }; |
| 4311 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4312 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4313 | struct nfs_open_context *ctx, |
| 4314 | struct nfs4_lock_state *lsp, |
| 4315 | struct nfs_seqid *seqid) |
| 4316 | { |
| 4317 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4318 | struct rpc_message msg = { |
| 4319 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4320 | .rpc_cred = ctx->cred, |
| 4321 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4322 | struct rpc_task_setup task_setup_data = { |
| 4323 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4324 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4325 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4326 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4327 | .flags = RPC_TASK_ASYNC, |
| 4328 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4329 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4330 | /* Ensure this is an unlock - when canceling a lock, the |
| 4331 | * canceled lock is passed in, and it won't be an unlock. |
| 4332 | */ |
| 4333 | fl->fl_type = F_UNLCK; |
| 4334 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4335 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4336 | if (data == NULL) { |
| 4337 | nfs_free_seqid(seqid); |
| 4338 | return ERR_PTR(-ENOMEM); |
| 4339 | } |
| 4340 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4341 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4342 | msg.rpc_argp = &data->arg; |
| 4343 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4344 | task_setup_data.callback_data = data; |
| 4345 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4346 | } |
| 4347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4349 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4350 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4351 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4352 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4353 | struct rpc_task *task; |
| 4354 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4355 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4357 | status = nfs4_set_lock_state(state, request); |
| 4358 | /* Unlock _before_ we do the RPC call */ |
| 4359 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4360 | down_read(&nfsi->rwsem); |
| 4361 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4362 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4363 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4364 | } |
| 4365 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4366 | if (status != 0) |
| 4367 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4368 | /* Is this a delegated lock? */ |
| 4369 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4370 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4371 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4372 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4373 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4374 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4375 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4376 | 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] | 4377 | status = PTR_ERR(task); |
| 4378 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4379 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4380 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4381 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4382 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4383 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4384 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4387 | struct nfs4_lockdata { |
| 4388 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4389 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4390 | struct nfs4_lock_state *lsp; |
| 4391 | struct nfs_open_context *ctx; |
| 4392 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4393 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4394 | int rpc_status; |
| 4395 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4396 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4397 | }; |
| 4398 | |
| 4399 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4400 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4401 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4402 | { |
| 4403 | struct nfs4_lockdata *p; |
| 4404 | struct inode *inode = lsp->ls_state->inode; |
| 4405 | struct nfs_server *server = NFS_SERVER(inode); |
| 4406 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4407 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4408 | if (p == NULL) |
| 4409 | return NULL; |
| 4410 | |
| 4411 | p->arg.fh = NFS_FH(inode); |
| 4412 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4413 | 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] | 4414 | if (p->arg.open_seqid == NULL) |
| 4415 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4416 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4417 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4418 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4419 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4420 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4421 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4422 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4423 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4424 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4425 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4426 | atomic_inc(&lsp->ls_count); |
| 4427 | p->ctx = get_nfs_open_context(ctx); |
| 4428 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4429 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4430 | out_free_seqid: |
| 4431 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4432 | out_free: |
| 4433 | kfree(p); |
| 4434 | return NULL; |
| 4435 | } |
| 4436 | |
| 4437 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4438 | { |
| 4439 | struct nfs4_lockdata *data = calldata; |
| 4440 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4442 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4443 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4444 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4445 | /* Do we need to do an open_to_lock_owner? */ |
| 4446 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4447 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4448 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4449 | data->arg.open_stateid = &state->stateid; |
| 4450 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4451 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4452 | } else |
| 4453 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4454 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4455 | if (nfs4_setup_sequence(data->server, |
| 4456 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4457 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4458 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4459 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4460 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4461 | } |
| 4462 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4463 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4464 | { |
| 4465 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4466 | nfs4_lock_prepare(task, calldata); |
| 4467 | } |
| 4468 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4469 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4470 | { |
| 4471 | struct nfs4_lockdata *data = calldata; |
| 4472 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4473 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4474 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4475 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4476 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4477 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4478 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4479 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4480 | if (data->rpc_status == 0) |
| 4481 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4482 | else |
| 4483 | goto out; |
| 4484 | } |
| 4485 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4486 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4487 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4488 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4489 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4490 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4491 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | static void nfs4_lock_release(void *calldata) |
| 4495 | { |
| 4496 | struct nfs4_lockdata *data = calldata; |
| 4497 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4498 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4499 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4500 | if (data->cancelled != 0) { |
| 4501 | struct rpc_task *task; |
| 4502 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4503 | data->arg.lock_seqid); |
| 4504 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4505 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4506 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4507 | } else |
| 4508 | nfs_free_seqid(data->arg.lock_seqid); |
| 4509 | nfs4_put_lock_state(data->lsp); |
| 4510 | put_nfs_open_context(data->ctx); |
| 4511 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4512 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4516 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4517 | .rpc_call_done = nfs4_lock_done, |
| 4518 | .rpc_release = nfs4_lock_release, |
| 4519 | }; |
| 4520 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4521 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4522 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4523 | .rpc_call_done = nfs4_lock_done, |
| 4524 | .rpc_release = nfs4_lock_release, |
| 4525 | }; |
| 4526 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4527 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4528 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4529 | switch (error) { |
| 4530 | case -NFS4ERR_ADMIN_REVOKED: |
| 4531 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4532 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4533 | if (new_lock_owner != 0 || |
| 4534 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4535 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4536 | break; |
| 4537 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4538 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4539 | case -NFS4ERR_EXPIRED: |
| 4540 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4541 | }; |
| 4542 | } |
| 4543 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4544 | 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] | 4545 | { |
| 4546 | struct nfs4_lockdata *data; |
| 4547 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4548 | struct rpc_message msg = { |
| 4549 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4550 | .rpc_cred = state->owner->so_cred, |
| 4551 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4552 | struct rpc_task_setup task_setup_data = { |
| 4553 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4554 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4555 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4556 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4557 | .flags = RPC_TASK_ASYNC, |
| 4558 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4559 | int ret; |
| 4560 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4561 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4562 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4563 | fl->fl_u.nfs4_fl.owner, |
| 4564 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4565 | if (data == NULL) |
| 4566 | return -ENOMEM; |
| 4567 | if (IS_SETLKW(cmd)) |
| 4568 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4569 | if (recovery_type > NFS_LOCK_NEW) { |
| 4570 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4571 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4572 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4573 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4574 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4575 | msg.rpc_argp = &data->arg; |
| 4576 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4577 | task_setup_data.callback_data = data; |
| 4578 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4579 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4580 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4581 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4582 | if (ret == 0) { |
| 4583 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4584 | if (ret) |
| 4585 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4586 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4587 | } else |
| 4588 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4589 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4590 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4591 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4595 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4596 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4597 | struct nfs4_exception exception = { |
| 4598 | .inode = state->inode, |
| 4599 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4600 | int err; |
| 4601 | |
| 4602 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4603 | /* Cache the lock if possible... */ |
| 4604 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4605 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4606 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4607 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4608 | break; |
| 4609 | nfs4_handle_exception(server, err, &exception); |
| 4610 | } while (exception.retry); |
| 4611 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4615 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4616 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4617 | struct nfs4_exception exception = { |
| 4618 | .inode = state->inode, |
| 4619 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4620 | int err; |
| 4621 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4622 | err = nfs4_set_lock_state(state, request); |
| 4623 | if (err != 0) |
| 4624 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4625 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4626 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4627 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4628 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4629 | switch (err) { |
| 4630 | default: |
| 4631 | goto out; |
| 4632 | case -NFS4ERR_GRACE: |
| 4633 | case -NFS4ERR_DELAY: |
| 4634 | nfs4_handle_exception(server, err, &exception); |
| 4635 | err = 0; |
| 4636 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4637 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4638 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4639 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4642 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4643 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4644 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4645 | int status, ret = NFS_OK; |
| 4646 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4647 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4648 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4649 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4650 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4651 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4652 | if (status != NFS_OK) { |
| 4653 | nfs41_free_stateid(server, &lsp->ls_stateid); |
| 4654 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4655 | ret = status; |
| 4656 | } |
| 4657 | } |
| 4658 | }; |
| 4659 | |
| 4660 | return ret; |
| 4661 | } |
| 4662 | |
| 4663 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4664 | { |
| 4665 | int status = NFS_OK; |
| 4666 | |
| 4667 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4668 | status = nfs41_check_expired_locks(state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4669 | if (status == NFS_OK) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4670 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4671 | return nfs4_lock_expired(state, request); |
| 4672 | } |
| 4673 | #endif |
| 4674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4676 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4677 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4678 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4679 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4681 | if ((fl_flags & FL_POSIX) && |
| 4682 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4683 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4684 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4685 | status = nfs4_set_lock_state(state, request); |
| 4686 | if (status != 0) |
| 4687 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4688 | request->fl_flags |= FL_ACCESS; |
| 4689 | status = do_vfs_lock(request->fl_file, request); |
| 4690 | if (status < 0) |
| 4691 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4692 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4693 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4694 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4695 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4696 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4697 | status = do_vfs_lock(request->fl_file, request); |
| 4698 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4699 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4700 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4701 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4702 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4703 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4704 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4705 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4706 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4707 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4708 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4709 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4710 | out: |
| 4711 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | return status; |
| 4713 | } |
| 4714 | |
| 4715 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4716 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4717 | struct nfs4_exception exception = { |
| 4718 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4719 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4720 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | int err; |
| 4722 | |
| 4723 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4724 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4725 | if (err == -NFS4ERR_DENIED) |
| 4726 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4728 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | } while (exception.retry); |
| 4730 | return err; |
| 4731 | } |
| 4732 | |
| 4733 | static int |
| 4734 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4735 | { |
| 4736 | struct nfs_open_context *ctx; |
| 4737 | struct nfs4_state *state; |
| 4738 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4739 | int status; |
| 4740 | |
| 4741 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4742 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | state = ctx->state; |
| 4744 | |
| 4745 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4746 | return -EINVAL; |
| 4747 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4748 | if (IS_GETLK(cmd)) { |
| 4749 | if (state != NULL) |
| 4750 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4751 | return 0; |
| 4752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | |
| 4754 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4755 | return -EINVAL; |
| 4756 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4757 | if (request->fl_type == F_UNLCK) { |
| 4758 | if (state != NULL) |
| 4759 | return nfs4_proc_unlck(state, cmd, request); |
| 4760 | return 0; |
| 4761 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4763 | if (state == NULL) |
| 4764 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4765 | /* |
| 4766 | * Don't rely on the VFS having checked the file open mode, |
| 4767 | * since it won't do this for flock() locks. |
| 4768 | */ |
| 4769 | switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) { |
| 4770 | case F_RDLCK: |
| 4771 | if (!(filp->f_mode & FMODE_READ)) |
| 4772 | return -EBADF; |
| 4773 | break; |
| 4774 | case F_WRLCK: |
| 4775 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4776 | return -EBADF; |
| 4777 | } |
| 4778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | do { |
| 4780 | status = nfs4_proc_setlk(state, cmd, request); |
| 4781 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4782 | break; |
| 4783 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4784 | status = -ERESTARTSYS; |
| 4785 | if (signalled()) |
| 4786 | break; |
| 4787 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | return status; |
| 4789 | } |
| 4790 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4791 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4792 | { |
| 4793 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4794 | struct nfs4_exception exception = { }; |
| 4795 | int err; |
| 4796 | |
| 4797 | err = nfs4_set_lock_state(state, fl); |
| 4798 | if (err != 0) |
| 4799 | goto out; |
| 4800 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4801 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4802 | switch (err) { |
| 4803 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4804 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4805 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4806 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4807 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4808 | goto out; |
| 4809 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4810 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4811 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4812 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4813 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4814 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4815 | case -NFS4ERR_BADSESSION: |
| 4816 | case -NFS4ERR_BADSLOT: |
| 4817 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4818 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4819 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4820 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4821 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4822 | case -ERESTARTSYS: |
| 4823 | /* |
| 4824 | * The show must go on: exit, but mark the |
| 4825 | * stateid as needing recovery. |
| 4826 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4827 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4828 | case -NFS4ERR_ADMIN_REVOKED: |
| 4829 | case -NFS4ERR_BAD_STATEID: |
| 4830 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4831 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4832 | err = 0; |
| 4833 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4834 | case -EKEYEXPIRED: |
| 4835 | /* |
| 4836 | * User RPCSEC_GSS context has expired. |
| 4837 | * We cannot recover this stateid now, so |
| 4838 | * skip it and allow recovery thread to |
| 4839 | * proceed. |
| 4840 | */ |
| 4841 | err = 0; |
| 4842 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4843 | case -ENOMEM: |
| 4844 | case -NFS4ERR_DENIED: |
| 4845 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4846 | err = 0; |
| 4847 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4848 | case -NFS4ERR_DELAY: |
| 4849 | break; |
| 4850 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4851 | err = nfs4_handle_exception(server, err, &exception); |
| 4852 | } while (exception.retry); |
| 4853 | out: |
| 4854 | return err; |
| 4855 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4856 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4857 | struct nfs_release_lockowner_data { |
| 4858 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4859 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4860 | struct nfs_release_lockowner_args args; |
| 4861 | }; |
| 4862 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4863 | static void nfs4_release_lockowner_release(void *calldata) |
| 4864 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4865 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4866 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4867 | kfree(calldata); |
| 4868 | } |
| 4869 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4870 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4871 | .rpc_release = nfs4_release_lockowner_release, |
| 4872 | }; |
| 4873 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4874 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4875 | { |
| 4876 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4877 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4878 | struct rpc_message msg = { |
| 4879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4880 | }; |
| 4881 | |
| 4882 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4883 | return -EINVAL; |
| 4884 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 4885 | if (!data) |
| 4886 | return -ENOMEM; |
| 4887 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4888 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4889 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4890 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 4891 | data->args.lock_owner.s_dev = server->s_dev; |
| 4892 | msg.rpc_argp = &data->args; |
| 4893 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 4894 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4895 | } |
| 4896 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4897 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4898 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4899 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4900 | const void *buf, size_t buflen, |
| 4901 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4902 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4903 | if (strcmp(key, "") != 0) |
| 4904 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4905 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4906 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4909 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4910 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4911 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4912 | if (strcmp(key, "") != 0) |
| 4913 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4914 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4915 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4918 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4919 | size_t list_len, const char *name, |
| 4920 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4921 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4922 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4923 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4924 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4925 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4926 | |
| 4927 | if (list && len <= list_len) |
| 4928 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4929 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4932 | /* |
| 4933 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4934 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4935 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4936 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4937 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4938 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4939 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4940 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4941 | return; |
| 4942 | |
| 4943 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4944 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4945 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4946 | fattr->nlink = 2; |
| 4947 | } |
| 4948 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4949 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 4950 | const struct qstr *name, |
| 4951 | struct nfs4_fs_locations *fs_locations, |
| 4952 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4953 | { |
| 4954 | struct nfs_server *server = NFS_SERVER(dir); |
| 4955 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4956 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4957 | }; |
| 4958 | struct nfs4_fs_locations_arg args = { |
| 4959 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4960 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4961 | .page = page, |
| 4962 | .bitmask = bitmask, |
| 4963 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4964 | struct nfs4_fs_locations_res res = { |
| 4965 | .fs_locations = fs_locations, |
| 4966 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4967 | struct rpc_message msg = { |
| 4968 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4969 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4970 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4971 | }; |
| 4972 | int status; |
| 4973 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4974 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4975 | |
| 4976 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4977 | * is not supported */ |
| 4978 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4979 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4980 | else |
| 4981 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4982 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4983 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4984 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4985 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4986 | 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] | 4987 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4988 | return status; |
| 4989 | } |
| 4990 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4991 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 4992 | const struct qstr *name, |
| 4993 | struct nfs4_fs_locations *fs_locations, |
| 4994 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 4995 | { |
| 4996 | struct nfs4_exception exception = { }; |
| 4997 | int err; |
| 4998 | do { |
| 4999 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5000 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5001 | &exception); |
| 5002 | } while (exception.retry); |
| 5003 | return err; |
| 5004 | } |
| 5005 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5006 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5007 | { |
| 5008 | int status; |
| 5009 | struct nfs4_secinfo_arg args = { |
| 5010 | .dir_fh = NFS_FH(dir), |
| 5011 | .name = name, |
| 5012 | }; |
| 5013 | struct nfs4_secinfo_res res = { |
| 5014 | .flavors = flavors, |
| 5015 | }; |
| 5016 | struct rpc_message msg = { |
| 5017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5018 | .rpc_argp = &args, |
| 5019 | .rpc_resp = &res, |
| 5020 | }; |
| 5021 | |
| 5022 | dprintk("NFS call secinfo %s\n", name->name); |
| 5023 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5024 | dprintk("NFS reply secinfo: %d\n", status); |
| 5025 | return status; |
| 5026 | } |
| 5027 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5028 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5029 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5030 | { |
| 5031 | struct nfs4_exception exception = { }; |
| 5032 | int err; |
| 5033 | do { |
| 5034 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5035 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5036 | &exception); |
| 5037 | } while (exception.retry); |
| 5038 | return err; |
| 5039 | } |
| 5040 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5041 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5042 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5043 | * Check the exchange flags returned by the server for invalid flags, having |
| 5044 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5045 | * DS flags set. |
| 5046 | */ |
| 5047 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5048 | { |
| 5049 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5050 | goto out_inval; |
| 5051 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5052 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5053 | goto out_inval; |
| 5054 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5055 | goto out_inval; |
| 5056 | return NFS_OK; |
| 5057 | out_inval: |
| 5058 | return -NFS4ERR_INVAL; |
| 5059 | } |
| 5060 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5061 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5062 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5063 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5064 | { |
| 5065 | if (a->server_scope_sz == b->server_scope_sz && |
| 5066 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5067 | return true; |
| 5068 | |
| 5069 | return false; |
| 5070 | } |
| 5071 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5072 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5073 | * nfs4_proc_exchange_id() |
| 5074 | * |
| 5075 | * Since the clientid has expired, all compounds using sessions |
| 5076 | * associated with the stale clientid will be returning |
| 5077 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5078 | * be in some phase of session reset. |
| 5079 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5080 | 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] | 5081 | { |
| 5082 | nfs4_verifier verifier; |
| 5083 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5084 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5085 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5086 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5087 | }; |
| 5088 | struct nfs41_exchange_id_res res = { |
| 5089 | .client = clp, |
| 5090 | }; |
| 5091 | int status; |
| 5092 | struct rpc_message msg = { |
| 5093 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5094 | .rpc_argp = &args, |
| 5095 | .rpc_resp = &res, |
| 5096 | .rpc_cred = cred, |
| 5097 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5098 | |
| 5099 | dprintk("--> %s\n", __func__); |
| 5100 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5101 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5102 | nfs4_construct_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5103 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5104 | args.id_len = scnprintf(args.id, sizeof(args.id), |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5105 | "%s/%s/%u", |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5106 | clp->cl_ipaddr, |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5107 | clp->cl_rpcclient->cl_nodename, |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5108 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5109 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5110 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
| 5111 | GFP_KERNEL); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5112 | if (unlikely(res.server_scope == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5113 | status = -ENOMEM; |
| 5114 | goto out; |
| 5115 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5116 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5117 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_KERNEL); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5118 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5119 | status = -ENOMEM; |
| 5120 | goto out_server_scope; |
| 5121 | } |
| 5122 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5123 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5124 | if (status == 0) |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5125 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5126 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5127 | if (status == 0) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5128 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5129 | kfree(clp->cl_implid); |
| 5130 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5131 | } else |
| 5132 | kfree(res.impl_id); |
| 5133 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5134 | if (status == 0) { |
| 5135 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5136 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5137 | res.server_scope)) { |
| 5138 | dprintk("%s: server_scope mismatch detected\n", |
| 5139 | __func__); |
| 5140 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5141 | kfree(clp->cl_serverscope); |
| 5142 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5143 | } |
| 5144 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5145 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5146 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5147 | goto out; |
| 5148 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5149 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5150 | |
| 5151 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5152 | kfree(res.server_scope); |
| 5153 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5154 | if (clp->cl_implid != NULL) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5155 | dprintk("%s: Server Implementation ID: " |
| 5156 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5157 | __func__, clp->cl_implid->domain, clp->cl_implid->name, |
| 5158 | clp->cl_implid->date.seconds, |
| 5159 | clp->cl_implid->date.nseconds); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5160 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5161 | return status; |
| 5162 | } |
| 5163 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5164 | struct nfs4_get_lease_time_data { |
| 5165 | struct nfs4_get_lease_time_args *args; |
| 5166 | struct nfs4_get_lease_time_res *res; |
| 5167 | struct nfs_client *clp; |
| 5168 | }; |
| 5169 | |
| 5170 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5171 | void *calldata) |
| 5172 | { |
| 5173 | int ret; |
| 5174 | struct nfs4_get_lease_time_data *data = |
| 5175 | (struct nfs4_get_lease_time_data *)calldata; |
| 5176 | |
| 5177 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5178 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5179 | /* just setup sequence, do not trigger session recovery |
| 5180 | since we're invoked within one */ |
| 5181 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5182 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5183 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5184 | |
| 5185 | BUG_ON(ret == -EAGAIN); |
| 5186 | rpc_call_start(task); |
| 5187 | dprintk("<-- %s\n", __func__); |
| 5188 | } |
| 5189 | |
| 5190 | /* |
| 5191 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5192 | * from sequence operation or clientid errors. |
| 5193 | */ |
| 5194 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5195 | { |
| 5196 | struct nfs4_get_lease_time_data *data = |
| 5197 | (struct nfs4_get_lease_time_data *)calldata; |
| 5198 | |
| 5199 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5200 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5201 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5202 | switch (task->tk_status) { |
| 5203 | case -NFS4ERR_DELAY: |
| 5204 | case -NFS4ERR_GRACE: |
| 5205 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5206 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5207 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5208 | /* fall through */ |
| 5209 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5210 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5211 | return; |
| 5212 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5213 | dprintk("<-- %s\n", __func__); |
| 5214 | } |
| 5215 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5216 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5217 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5218 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5219 | }; |
| 5220 | |
| 5221 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5222 | { |
| 5223 | struct rpc_task *task; |
| 5224 | struct nfs4_get_lease_time_args args; |
| 5225 | struct nfs4_get_lease_time_res res = { |
| 5226 | .lr_fsinfo = fsinfo, |
| 5227 | }; |
| 5228 | struct nfs4_get_lease_time_data data = { |
| 5229 | .args = &args, |
| 5230 | .res = &res, |
| 5231 | .clp = clp, |
| 5232 | }; |
| 5233 | struct rpc_message msg = { |
| 5234 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5235 | .rpc_argp = &args, |
| 5236 | .rpc_resp = &res, |
| 5237 | }; |
| 5238 | struct rpc_task_setup task_setup = { |
| 5239 | .rpc_client = clp->cl_rpcclient, |
| 5240 | .rpc_message = &msg, |
| 5241 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5242 | .callback_data = &data, |
| 5243 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5244 | }; |
| 5245 | int status; |
| 5246 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5247 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5248 | dprintk("--> %s\n", __func__); |
| 5249 | task = rpc_run_task(&task_setup); |
| 5250 | |
| 5251 | if (IS_ERR(task)) |
| 5252 | status = PTR_ERR(task); |
| 5253 | else { |
| 5254 | status = task->tk_status; |
| 5255 | rpc_put_task(task); |
| 5256 | } |
| 5257 | dprintk("<-- %s return %d\n", __func__, status); |
| 5258 | |
| 5259 | return status; |
| 5260 | } |
| 5261 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5262 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5263 | { |
| 5264 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5265 | } |
| 5266 | |
| 5267 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5268 | struct nfs4_slot *new, |
| 5269 | u32 max_slots, |
| 5270 | u32 ivalue) |
| 5271 | { |
| 5272 | struct nfs4_slot *old = NULL; |
| 5273 | u32 i; |
| 5274 | |
| 5275 | spin_lock(&tbl->slot_tbl_lock); |
| 5276 | if (new) { |
| 5277 | old = tbl->slots; |
| 5278 | tbl->slots = new; |
| 5279 | tbl->max_slots = max_slots; |
| 5280 | } |
| 5281 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5282 | for (i = 0; i < tbl->max_slots; i++) |
| 5283 | tbl->slots[i].seq_nr = ivalue; |
| 5284 | spin_unlock(&tbl->slot_tbl_lock); |
| 5285 | kfree(old); |
| 5286 | } |
| 5287 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5288 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5289 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5290 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5291 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5292 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5293 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5294 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5295 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5296 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5297 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5298 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5299 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5300 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5301 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5302 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5303 | if (!new) |
| 5304 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5305 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5306 | ret = 0; |
| 5307 | |
| 5308 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5309 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5310 | tbl, tbl->slots, tbl->max_slots); |
| 5311 | out: |
| 5312 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5313 | return ret; |
| 5314 | } |
| 5315 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5316 | /* Destroy the slot table */ |
| 5317 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5318 | { |
| 5319 | if (session->fc_slot_table.slots != NULL) { |
| 5320 | kfree(session->fc_slot_table.slots); |
| 5321 | session->fc_slot_table.slots = NULL; |
| 5322 | } |
| 5323 | if (session->bc_slot_table.slots != NULL) { |
| 5324 | kfree(session->bc_slot_table.slots); |
| 5325 | session->bc_slot_table.slots = NULL; |
| 5326 | } |
| 5327 | return; |
| 5328 | } |
| 5329 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5330 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5331 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5332 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5333 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5334 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5335 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5336 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5337 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5338 | dprintk("--> %s\n", __func__); |
| 5339 | /* Fore channel */ |
| 5340 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5341 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5342 | if (status) /* -ENOMEM */ |
| 5343 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5344 | /* Back channel */ |
| 5345 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5346 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5347 | if (status && tbl->slots == NULL) |
| 5348 | /* Fore and back channel share a connection so get |
| 5349 | * both slot tables or neither */ |
| 5350 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5351 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5355 | { |
| 5356 | struct nfs4_session *session; |
| 5357 | struct nfs4_slot_table *tbl; |
| 5358 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5359 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5360 | if (!session) |
| 5361 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5362 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5363 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5364 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5365 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5366 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5367 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5368 | |
| 5369 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5370 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5371 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5372 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5373 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5374 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5375 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5376 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5377 | session->clp = clp; |
| 5378 | return session; |
| 5379 | } |
| 5380 | |
| 5381 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5382 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5383 | struct rpc_xprt *xprt; |
| 5384 | |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5385 | nfs4_proc_destroy_session(session); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5386 | |
| 5387 | rcu_read_lock(); |
| 5388 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5389 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5390 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5391 | __func__, xprt); |
| 5392 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5393 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5394 | kfree(session); |
| 5395 | } |
| 5396 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5397 | /* |
| 5398 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5399 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5400 | * use them. |
| 5401 | * |
| 5402 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5403 | * always set csa_cachethis to FALSE because the current implementation |
| 5404 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5405 | */ |
| 5406 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5407 | { |
| 5408 | struct nfs4_session *session = args->client->cl_session; |
| 5409 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5410 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5411 | |
| 5412 | if (mxrqst_sz == 0) |
| 5413 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5414 | if (mxresp_sz == 0) |
| 5415 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5416 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5417 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5418 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5419 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5420 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5421 | |
| 5422 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5423 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5424 | __func__, |
| 5425 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5426 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5427 | |
| 5428 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5429 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5430 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5431 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5432 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5433 | args->bc_attrs.max_reqs = 1; |
| 5434 | |
| 5435 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5436 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5437 | __func__, |
| 5438 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5439 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5440 | args->bc_attrs.max_reqs); |
| 5441 | } |
| 5442 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5443 | 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] | 5444 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5445 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5446 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5447 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5448 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5449 | return -EINVAL; |
| 5450 | /* |
| 5451 | * Our requested max_ops is the minimum we need; we're not |
| 5452 | * prepared to break up compounds into smaller pieces than that. |
| 5453 | * So, no point even trying to continue if the server won't |
| 5454 | * cooperate: |
| 5455 | */ |
| 5456 | if (rcvd->max_ops < sent->max_ops) |
| 5457 | return -EINVAL; |
| 5458 | if (rcvd->max_reqs == 0) |
| 5459 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5460 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5461 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5462 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5463 | } |
| 5464 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5465 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5466 | { |
| 5467 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5468 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5469 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5470 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5471 | return -EINVAL; |
| 5472 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5473 | return -EINVAL; |
| 5474 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5475 | return -EINVAL; |
| 5476 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5477 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5478 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5479 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5480 | return -EINVAL; |
| 5481 | return 0; |
| 5482 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5483 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5484 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5485 | struct nfs4_session *session) |
| 5486 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5487 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5488 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5489 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5490 | if (ret) |
| 5491 | return ret; |
| 5492 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5493 | } |
| 5494 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5495 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5496 | { |
| 5497 | struct nfs4_session *session = clp->cl_session; |
| 5498 | struct nfs41_create_session_args args = { |
| 5499 | .client = clp, |
| 5500 | .cb_program = NFS4_CALLBACK, |
| 5501 | }; |
| 5502 | struct nfs41_create_session_res res = { |
| 5503 | .client = clp, |
| 5504 | }; |
| 5505 | struct rpc_message msg = { |
| 5506 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5507 | .rpc_argp = &args, |
| 5508 | .rpc_resp = &res, |
| 5509 | }; |
| 5510 | int status; |
| 5511 | |
| 5512 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5513 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5514 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5515 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5516 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5517 | if (!status) |
| 5518 | /* Verify the session's negotiated channel_attrs values */ |
| 5519 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5520 | if (!status) { |
| 5521 | /* Increment the clientid slot sequence id */ |
| 5522 | clp->cl_seqid++; |
| 5523 | } |
| 5524 | |
| 5525 | return status; |
| 5526 | } |
| 5527 | |
| 5528 | /* |
| 5529 | * Issues a CREATE_SESSION operation to the server. |
| 5530 | * It is the responsibility of the caller to verify the session is |
| 5531 | * expired before calling this routine. |
| 5532 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5533 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5534 | { |
| 5535 | int status; |
| 5536 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5537 | struct nfs4_session *session = clp->cl_session; |
| 5538 | |
| 5539 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5540 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5541 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5542 | if (status) |
| 5543 | goto out; |
| 5544 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5545 | /* Init or reset the session slot tables */ |
| 5546 | status = nfs4_setup_session_slot_tables(session); |
| 5547 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5548 | if (status) |
| 5549 | goto out; |
| 5550 | |
| 5551 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5552 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5553 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5554 | out: |
| 5555 | dprintk("<-- %s\n", __func__); |
| 5556 | return status; |
| 5557 | } |
| 5558 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5559 | /* |
| 5560 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5561 | * The caller must serialize access to this routine. |
| 5562 | */ |
| 5563 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5564 | { |
| 5565 | int status = 0; |
| 5566 | struct rpc_message msg; |
| 5567 | |
| 5568 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5569 | |
| 5570 | /* session is still being setup */ |
| 5571 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5572 | return status; |
| 5573 | |
| 5574 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5575 | msg.rpc_argp = session; |
| 5576 | msg.rpc_resp = NULL; |
| 5577 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5578 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5579 | |
| 5580 | if (status) |
| 5581 | printk(KERN_WARNING |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 5582 | "NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5583 | "Session has been destroyed regardless...\n", status); |
| 5584 | |
| 5585 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5586 | return status; |
| 5587 | } |
| 5588 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5589 | int nfs4_init_session(struct nfs_server *server) |
| 5590 | { |
| 5591 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5592 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5593 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5594 | int ret; |
| 5595 | |
| 5596 | if (!nfs4_has_session(clp)) |
| 5597 | return 0; |
| 5598 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5599 | session = clp->cl_session; |
| 5600 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5601 | return 0; |
| 5602 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5603 | rsize = server->rsize; |
| 5604 | if (rsize == 0) |
| 5605 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5606 | wsize = server->wsize; |
| 5607 | if (wsize == 0) |
| 5608 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5609 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5610 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5611 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5612 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5613 | ret = nfs4_recover_expired_lease(server); |
| 5614 | if (!ret) |
| 5615 | ret = nfs4_check_client_ready(clp); |
| 5616 | return ret; |
| 5617 | } |
| 5618 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5619 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5620 | { |
| 5621 | struct nfs4_session *session = clp->cl_session; |
| 5622 | int ret; |
| 5623 | |
| 5624 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5625 | return 0; |
| 5626 | |
| 5627 | ret = nfs4_client_recover_expired_lease(clp); |
| 5628 | if (!ret) |
| 5629 | /* Test for the DS role */ |
| 5630 | if (!is_ds_client(clp)) |
| 5631 | ret = -ENODEV; |
| 5632 | if (!ret) |
| 5633 | ret = nfs4_check_client_ready(clp); |
| 5634 | return ret; |
| 5635 | |
| 5636 | } |
| 5637 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5638 | |
| 5639 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5640 | /* |
| 5641 | * Renew the cl_session lease. |
| 5642 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5643 | struct nfs4_sequence_data { |
| 5644 | struct nfs_client *clp; |
| 5645 | struct nfs4_sequence_args args; |
| 5646 | struct nfs4_sequence_res res; |
| 5647 | }; |
| 5648 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5649 | static void nfs41_sequence_release(void *data) |
| 5650 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5651 | struct nfs4_sequence_data *calldata = data; |
| 5652 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5653 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5654 | if (atomic_read(&clp->cl_count) > 1) |
| 5655 | nfs4_schedule_state_renewal(clp); |
| 5656 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5657 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5658 | } |
| 5659 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5660 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5661 | { |
| 5662 | switch(task->tk_status) { |
| 5663 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5664 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5665 | return -EAGAIN; |
| 5666 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5667 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5668 | } |
| 5669 | return 0; |
| 5670 | } |
| 5671 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5672 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5673 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5674 | struct nfs4_sequence_data *calldata = data; |
| 5675 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5676 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5677 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5678 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5679 | |
| 5680 | if (task->tk_status < 0) { |
| 5681 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5682 | if (atomic_read(&clp->cl_count) == 1) |
| 5683 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5684 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5685 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5686 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5687 | return; |
| 5688 | } |
| 5689 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5690 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5691 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5692 | dprintk("<-- %s\n", __func__); |
| 5693 | } |
| 5694 | |
| 5695 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5696 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5697 | struct nfs4_sequence_data *calldata = data; |
| 5698 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5699 | struct nfs4_sequence_args *args; |
| 5700 | struct nfs4_sequence_res *res; |
| 5701 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5702 | args = task->tk_msg.rpc_argp; |
| 5703 | res = task->tk_msg.rpc_resp; |
| 5704 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5705 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5706 | return; |
| 5707 | rpc_call_start(task); |
| 5708 | } |
| 5709 | |
| 5710 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5711 | .rpc_call_done = nfs41_sequence_call_done, |
| 5712 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5713 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5714 | }; |
| 5715 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5716 | 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] | 5717 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5718 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5719 | struct rpc_message msg = { |
| 5720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5721 | .rpc_cred = cred, |
| 5722 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5723 | struct rpc_task_setup task_setup_data = { |
| 5724 | .rpc_client = clp->cl_rpcclient, |
| 5725 | .rpc_message = &msg, |
| 5726 | .callback_ops = &nfs41_sequence_ops, |
| 5727 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5728 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5729 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5730 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5731 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5732 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5733 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5734 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5735 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5736 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5737 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5738 | msg.rpc_argp = &calldata->args; |
| 5739 | msg.rpc_resp = &calldata->res; |
| 5740 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5741 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5742 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5743 | return rpc_run_task(&task_setup_data); |
| 5744 | } |
| 5745 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5746 | 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] | 5747 | { |
| 5748 | struct rpc_task *task; |
| 5749 | int ret = 0; |
| 5750 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5751 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5752 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5753 | task = _nfs41_proc_sequence(clp, cred); |
| 5754 | if (IS_ERR(task)) |
| 5755 | ret = PTR_ERR(task); |
| 5756 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5757 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5758 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5759 | return ret; |
| 5760 | } |
| 5761 | |
| 5762 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5763 | { |
| 5764 | struct rpc_task *task; |
| 5765 | int ret; |
| 5766 | |
| 5767 | task = _nfs41_proc_sequence(clp, cred); |
| 5768 | if (IS_ERR(task)) { |
| 5769 | ret = PTR_ERR(task); |
| 5770 | goto out; |
| 5771 | } |
| 5772 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5773 | if (!ret) { |
| 5774 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5775 | |
| 5776 | if (task->tk_status == 0) |
| 5777 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5778 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5779 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5780 | rpc_put_task(task); |
| 5781 | out: |
| 5782 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5783 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5784 | } |
| 5785 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5786 | struct nfs4_reclaim_complete_data { |
| 5787 | struct nfs_client *clp; |
| 5788 | struct nfs41_reclaim_complete_args arg; |
| 5789 | struct nfs41_reclaim_complete_res res; |
| 5790 | }; |
| 5791 | |
| 5792 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5793 | { |
| 5794 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5795 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5796 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5797 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5798 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5799 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5800 | return; |
| 5801 | |
| 5802 | rpc_call_start(task); |
| 5803 | } |
| 5804 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5805 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5806 | { |
| 5807 | switch(task->tk_status) { |
| 5808 | case 0: |
| 5809 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5810 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5811 | break; |
| 5812 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5813 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5814 | /* fall through */ |
| 5815 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5816 | return -EAGAIN; |
| 5817 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5818 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5819 | } |
| 5820 | return 0; |
| 5821 | } |
| 5822 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5823 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5824 | { |
| 5825 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5826 | struct nfs_client *clp = calldata->clp; |
| 5827 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5828 | |
| 5829 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5830 | if (!nfs41_sequence_done(task, res)) |
| 5831 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5832 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5833 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5834 | rpc_restart_call_prepare(task); |
| 5835 | return; |
| 5836 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5837 | dprintk("<-- %s\n", __func__); |
| 5838 | } |
| 5839 | |
| 5840 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5841 | { |
| 5842 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5843 | |
| 5844 | kfree(calldata); |
| 5845 | } |
| 5846 | |
| 5847 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5848 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5849 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5850 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5851 | }; |
| 5852 | |
| 5853 | /* |
| 5854 | * Issue a global reclaim complete. |
| 5855 | */ |
| 5856 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5857 | { |
| 5858 | struct nfs4_reclaim_complete_data *calldata; |
| 5859 | struct rpc_task *task; |
| 5860 | struct rpc_message msg = { |
| 5861 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5862 | }; |
| 5863 | struct rpc_task_setup task_setup_data = { |
| 5864 | .rpc_client = clp->cl_rpcclient, |
| 5865 | .rpc_message = &msg, |
| 5866 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5867 | .flags = RPC_TASK_ASYNC, |
| 5868 | }; |
| 5869 | int status = -ENOMEM; |
| 5870 | |
| 5871 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5872 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5873 | if (calldata == NULL) |
| 5874 | goto out; |
| 5875 | calldata->clp = clp; |
| 5876 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5877 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5878 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5879 | msg.rpc_argp = &calldata->arg; |
| 5880 | msg.rpc_resp = &calldata->res; |
| 5881 | task_setup_data.callback_data = calldata; |
| 5882 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5883 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5884 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5885 | goto out; |
| 5886 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5887 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5888 | if (status == 0) |
| 5889 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5890 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5891 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5892 | out: |
| 5893 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5894 | return status; |
| 5895 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5896 | |
| 5897 | static void |
| 5898 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5899 | { |
| 5900 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5901 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5902 | |
| 5903 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5904 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5905 | * right now covering the LAYOUTGET we are about to send. |
| 5906 | * However, that is not so catastrophic, and there seems |
| 5907 | * to be no way to prevent it completely. |
| 5908 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5909 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5910 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5911 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5912 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5913 | NFS_I(lgp->args.inode)->layout, |
| 5914 | lgp->args.ctx->state)) { |
| 5915 | rpc_exit(task, NFS4_OK); |
| 5916 | return; |
| 5917 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5918 | rpc_call_start(task); |
| 5919 | } |
| 5920 | |
| 5921 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5922 | { |
| 5923 | struct nfs4_layoutget *lgp = calldata; |
| 5924 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5925 | |
| 5926 | dprintk("--> %s\n", __func__); |
| 5927 | |
| 5928 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5929 | return; |
| 5930 | |
| 5931 | switch (task->tk_status) { |
| 5932 | case 0: |
| 5933 | break; |
| 5934 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5935 | case -NFS4ERR_RECALLCONFLICT: |
| 5936 | task->tk_status = -NFS4ERR_DELAY; |
| 5937 | /* Fall through */ |
| 5938 | default: |
| 5939 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5940 | rpc_restart_call_prepare(task); |
| 5941 | return; |
| 5942 | } |
| 5943 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5944 | dprintk("<-- %s\n", __func__); |
| 5945 | } |
| 5946 | |
| 5947 | static void nfs4_layoutget_release(void *calldata) |
| 5948 | { |
| 5949 | struct nfs4_layoutget *lgp = calldata; |
| 5950 | |
| 5951 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5952 | put_nfs_open_context(lgp->args.ctx); |
| 5953 | kfree(calldata); |
| 5954 | dprintk("<-- %s\n", __func__); |
| 5955 | } |
| 5956 | |
| 5957 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5958 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5959 | .rpc_call_done = nfs4_layoutget_done, |
| 5960 | .rpc_release = nfs4_layoutget_release, |
| 5961 | }; |
| 5962 | |
| 5963 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5964 | { |
| 5965 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5966 | struct rpc_task *task; |
| 5967 | struct rpc_message msg = { |
| 5968 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5969 | .rpc_argp = &lgp->args, |
| 5970 | .rpc_resp = &lgp->res, |
| 5971 | }; |
| 5972 | struct rpc_task_setup task_setup_data = { |
| 5973 | .rpc_client = server->client, |
| 5974 | .rpc_message = &msg, |
| 5975 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5976 | .callback_data = lgp, |
| 5977 | .flags = RPC_TASK_ASYNC, |
| 5978 | }; |
| 5979 | int status = 0; |
| 5980 | |
| 5981 | dprintk("--> %s\n", __func__); |
| 5982 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5983 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5984 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5985 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5986 | task = rpc_run_task(&task_setup_data); |
| 5987 | if (IS_ERR(task)) |
| 5988 | return PTR_ERR(task); |
| 5989 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5990 | if (status == 0) |
| 5991 | status = task->tk_status; |
| 5992 | if (status == 0) |
| 5993 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5994 | rpc_put_task(task); |
| 5995 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5996 | return status; |
| 5997 | } |
| 5998 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5999 | static void |
| 6000 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6001 | { |
| 6002 | struct nfs4_layoutreturn *lrp = calldata; |
| 6003 | |
| 6004 | dprintk("--> %s\n", __func__); |
| 6005 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6006 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6007 | return; |
| 6008 | rpc_call_start(task); |
| 6009 | } |
| 6010 | |
| 6011 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6012 | { |
| 6013 | struct nfs4_layoutreturn *lrp = calldata; |
| 6014 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6015 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6016 | |
| 6017 | dprintk("--> %s\n", __func__); |
| 6018 | |
| 6019 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6020 | return; |
| 6021 | |
| 6022 | server = NFS_SERVER(lrp->args.inode); |
| 6023 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6024 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6025 | return; |
| 6026 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6027 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6028 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6029 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6030 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6031 | } else |
| 6032 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 6033 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6034 | lo->plh_block_lgets--; |
| 6035 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6036 | dprintk("<-- %s\n", __func__); |
| 6037 | } |
| 6038 | |
| 6039 | static void nfs4_layoutreturn_release(void *calldata) |
| 6040 | { |
| 6041 | struct nfs4_layoutreturn *lrp = calldata; |
| 6042 | |
| 6043 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6044 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6045 | kfree(calldata); |
| 6046 | dprintk("<-- %s\n", __func__); |
| 6047 | } |
| 6048 | |
| 6049 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6050 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6051 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6052 | .rpc_release = nfs4_layoutreturn_release, |
| 6053 | }; |
| 6054 | |
| 6055 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6056 | { |
| 6057 | struct rpc_task *task; |
| 6058 | struct rpc_message msg = { |
| 6059 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6060 | .rpc_argp = &lrp->args, |
| 6061 | .rpc_resp = &lrp->res, |
| 6062 | }; |
| 6063 | struct rpc_task_setup task_setup_data = { |
| 6064 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6065 | .rpc_message = &msg, |
| 6066 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6067 | .callback_data = lrp, |
| 6068 | }; |
| 6069 | int status; |
| 6070 | |
| 6071 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6072 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6073 | task = rpc_run_task(&task_setup_data); |
| 6074 | if (IS_ERR(task)) |
| 6075 | return PTR_ERR(task); |
| 6076 | status = task->tk_status; |
| 6077 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6078 | rpc_put_task(task); |
| 6079 | return status; |
| 6080 | } |
| 6081 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6082 | /* |
| 6083 | * Retrieve the list of Data Server devices from the MDS. |
| 6084 | */ |
| 6085 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6086 | const struct nfs_fh *fh, |
| 6087 | struct pnfs_devicelist *devlist) |
| 6088 | { |
| 6089 | struct nfs4_getdevicelist_args args = { |
| 6090 | .fh = fh, |
| 6091 | .layoutclass = server->pnfs_curr_ld->id, |
| 6092 | }; |
| 6093 | struct nfs4_getdevicelist_res res = { |
| 6094 | .devlist = devlist, |
| 6095 | }; |
| 6096 | struct rpc_message msg = { |
| 6097 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6098 | .rpc_argp = &args, |
| 6099 | .rpc_resp = &res, |
| 6100 | }; |
| 6101 | int status; |
| 6102 | |
| 6103 | dprintk("--> %s\n", __func__); |
| 6104 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6105 | &res.seq_res, 0); |
| 6106 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6107 | return status; |
| 6108 | } |
| 6109 | |
| 6110 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6111 | const struct nfs_fh *fh, |
| 6112 | struct pnfs_devicelist *devlist) |
| 6113 | { |
| 6114 | struct nfs4_exception exception = { }; |
| 6115 | int err; |
| 6116 | |
| 6117 | do { |
| 6118 | err = nfs4_handle_exception(server, |
| 6119 | _nfs4_getdevicelist(server, fh, devlist), |
| 6120 | &exception); |
| 6121 | } while (exception.retry); |
| 6122 | |
| 6123 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6124 | err, devlist->num_devs); |
| 6125 | |
| 6126 | return err; |
| 6127 | } |
| 6128 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6129 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6130 | static int |
| 6131 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6132 | { |
| 6133 | struct nfs4_getdeviceinfo_args args = { |
| 6134 | .pdev = pdev, |
| 6135 | }; |
| 6136 | struct nfs4_getdeviceinfo_res res = { |
| 6137 | .pdev = pdev, |
| 6138 | }; |
| 6139 | struct rpc_message msg = { |
| 6140 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6141 | .rpc_argp = &args, |
| 6142 | .rpc_resp = &res, |
| 6143 | }; |
| 6144 | int status; |
| 6145 | |
| 6146 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6147 | 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] | 6148 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6149 | |
| 6150 | return status; |
| 6151 | } |
| 6152 | |
| 6153 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6154 | { |
| 6155 | struct nfs4_exception exception = { }; |
| 6156 | int err; |
| 6157 | |
| 6158 | do { |
| 6159 | err = nfs4_handle_exception(server, |
| 6160 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6161 | &exception); |
| 6162 | } while (exception.retry); |
| 6163 | return err; |
| 6164 | } |
| 6165 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6166 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6167 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6168 | { |
| 6169 | struct nfs4_layoutcommit_data *data = calldata; |
| 6170 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6171 | |
| 6172 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6173 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6174 | return; |
| 6175 | rpc_call_start(task); |
| 6176 | } |
| 6177 | |
| 6178 | static void |
| 6179 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6180 | { |
| 6181 | struct nfs4_layoutcommit_data *data = calldata; |
| 6182 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6183 | |
| 6184 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6185 | return; |
| 6186 | |
| 6187 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6188 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6189 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6190 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6191 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6192 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6193 | break; |
| 6194 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6195 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6196 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6197 | break; |
| 6198 | default: |
| 6199 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6200 | rpc_restart_call_prepare(task); |
| 6201 | return; |
| 6202 | } |
| 6203 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | static void nfs4_layoutcommit_release(void *calldata) |
| 6207 | { |
| 6208 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6209 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6210 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6211 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6212 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6213 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6214 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6215 | list_del_init(&lseg->pls_lc_list); |
| 6216 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6217 | &lseg->pls_flags)) |
| 6218 | put_lseg(lseg); |
| 6219 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6220 | |
| 6221 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6222 | smp_mb__after_clear_bit(); |
| 6223 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6224 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6225 | put_rpccred(data->cred); |
| 6226 | kfree(data); |
| 6227 | } |
| 6228 | |
| 6229 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6230 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6231 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6232 | .rpc_release = nfs4_layoutcommit_release, |
| 6233 | }; |
| 6234 | |
| 6235 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6236 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6237 | { |
| 6238 | struct rpc_message msg = { |
| 6239 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6240 | .rpc_argp = &data->args, |
| 6241 | .rpc_resp = &data->res, |
| 6242 | .rpc_cred = data->cred, |
| 6243 | }; |
| 6244 | struct rpc_task_setup task_setup_data = { |
| 6245 | .task = &data->task, |
| 6246 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6247 | .rpc_message = &msg, |
| 6248 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6249 | .callback_data = data, |
| 6250 | .flags = RPC_TASK_ASYNC, |
| 6251 | }; |
| 6252 | struct rpc_task *task; |
| 6253 | int status = 0; |
| 6254 | |
| 6255 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6256 | "lbw: %llu inode %lu\n", |
| 6257 | data->task.tk_pid, sync, |
| 6258 | data->args.lastbytewritten, |
| 6259 | data->args.inode->i_ino); |
| 6260 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6261 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6262 | task = rpc_run_task(&task_setup_data); |
| 6263 | if (IS_ERR(task)) |
| 6264 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6265 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6266 | goto out; |
| 6267 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6268 | if (status != 0) |
| 6269 | goto out; |
| 6270 | status = task->tk_status; |
| 6271 | out: |
| 6272 | dprintk("%s: status %d\n", __func__, status); |
| 6273 | rpc_put_task(task); |
| 6274 | return status; |
| 6275 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6276 | |
| 6277 | static int |
| 6278 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6279 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6280 | { |
| 6281 | struct nfs41_secinfo_no_name_args args = { |
| 6282 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6283 | }; |
| 6284 | struct nfs4_secinfo_res res = { |
| 6285 | .flavors = flavors, |
| 6286 | }; |
| 6287 | struct rpc_message msg = { |
| 6288 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6289 | .rpc_argp = &args, |
| 6290 | .rpc_resp = &res, |
| 6291 | }; |
| 6292 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6293 | } |
| 6294 | |
| 6295 | static int |
| 6296 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6297 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6298 | { |
| 6299 | struct nfs4_exception exception = { }; |
| 6300 | int err; |
| 6301 | do { |
| 6302 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6303 | switch (err) { |
| 6304 | case 0: |
| 6305 | case -NFS4ERR_WRONGSEC: |
| 6306 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6307 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6308 | default: |
| 6309 | err = nfs4_handle_exception(server, err, &exception); |
| 6310 | } |
| 6311 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6312 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6313 | return err; |
| 6314 | } |
| 6315 | |
| 6316 | static int |
| 6317 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6318 | struct nfs_fsinfo *info) |
| 6319 | { |
| 6320 | int err; |
| 6321 | struct page *page; |
| 6322 | rpc_authflavor_t flavor; |
| 6323 | struct nfs4_secinfo_flavors *flavors; |
| 6324 | |
| 6325 | page = alloc_page(GFP_KERNEL); |
| 6326 | if (!page) { |
| 6327 | err = -ENOMEM; |
| 6328 | goto out; |
| 6329 | } |
| 6330 | |
| 6331 | flavors = page_address(page); |
| 6332 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6333 | |
| 6334 | /* |
| 6335 | * Fall back on "guess and check" method if |
| 6336 | * the server doesn't support SECINFO_NO_NAME |
| 6337 | */ |
| 6338 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6339 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6340 | goto out_freepage; |
| 6341 | } |
| 6342 | if (err) |
| 6343 | goto out_freepage; |
| 6344 | |
| 6345 | flavor = nfs_find_best_sec(flavors); |
| 6346 | if (err == 0) |
| 6347 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6348 | |
| 6349 | out_freepage: |
| 6350 | put_page(page); |
| 6351 | if (err == -EACCES) |
| 6352 | return -EPERM; |
| 6353 | out: |
| 6354 | return err; |
| 6355 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6356 | |
| 6357 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6358 | { |
| 6359 | int status; |
| 6360 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6361 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6362 | }; |
| 6363 | struct nfs41_test_stateid_res res; |
| 6364 | struct rpc_message msg = { |
| 6365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6366 | .rpc_argp = &args, |
| 6367 | .rpc_resp = &res, |
| 6368 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6369 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6370 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6371 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
| 6372 | |
| 6373 | if (status == NFS_OK) |
| 6374 | return res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6375 | return status; |
| 6376 | } |
| 6377 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6378 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6379 | { |
| 6380 | struct nfs4_exception exception = { }; |
| 6381 | int err; |
| 6382 | do { |
| 6383 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6384 | _nfs41_test_stateid(server, stateid), |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6385 | &exception); |
| 6386 | } while (exception.retry); |
| 6387 | return err; |
| 6388 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6389 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6390 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6391 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6392 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6393 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6394 | }; |
| 6395 | struct nfs41_free_stateid_res res; |
| 6396 | struct rpc_message msg = { |
| 6397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6398 | .rpc_argp = &args, |
| 6399 | .rpc_resp = &res, |
| 6400 | }; |
| 6401 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6402 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6403 | return nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6404 | } |
| 6405 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6406 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6407 | { |
| 6408 | struct nfs4_exception exception = { }; |
| 6409 | int err; |
| 6410 | do { |
| 6411 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6412 | _nfs4_free_stateid(server, stateid), |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6413 | &exception); |
| 6414 | } while (exception.retry); |
| 6415 | return err; |
| 6416 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6417 | |
| 6418 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6419 | const nfs4_stateid *s2) |
| 6420 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6421 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6422 | return false; |
| 6423 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6424 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6425 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6426 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6427 | return true; |
| 6428 | |
| 6429 | return false; |
| 6430 | } |
| 6431 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6432 | #endif /* CONFIG_NFS_V4_1 */ |
| 6433 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6434 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6435 | const nfs4_stateid *s2) |
| 6436 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6437 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6441 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6442 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6443 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | .recover_open = nfs4_open_reclaim, |
| 6445 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6446 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6447 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6448 | }; |
| 6449 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6450 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6451 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6452 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6453 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6454 | .recover_open = nfs4_open_reclaim, |
| 6455 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6456 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6457 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6458 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6459 | }; |
| 6460 | #endif /* CONFIG_NFS_V4_1 */ |
| 6461 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6462 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6463 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6464 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6465 | .recover_open = nfs4_open_expired, |
| 6466 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6467 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6468 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6469 | }; |
| 6470 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6471 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6472 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6473 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6474 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6475 | .recover_open = nfs41_open_expired, |
| 6476 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6477 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6478 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6479 | }; |
| 6480 | #endif /* CONFIG_NFS_V4_1 */ |
| 6481 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6482 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6483 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6484 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6485 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6486 | }; |
| 6487 | |
| 6488 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6489 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6490 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6491 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6492 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6493 | }; |
| 6494 | #endif |
| 6495 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6496 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6497 | .minor_version = 0, |
| 6498 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6499 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6500 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6501 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6502 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6503 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6504 | }; |
| 6505 | |
| 6506 | #if defined(CONFIG_NFS_V4_1) |
| 6507 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6508 | .minor_version = 1, |
| 6509 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6510 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6511 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6512 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6513 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6514 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6515 | }; |
| 6516 | #endif |
| 6517 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6518 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6519 | [0] = &nfs_v4_0_minor_ops, |
| 6520 | #if defined(CONFIG_NFS_V4_1) |
| 6521 | [1] = &nfs_v4_1_minor_ops, |
| 6522 | #endif |
| 6523 | }; |
| 6524 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6525 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6526 | .permission = nfs_permission, |
| 6527 | .getattr = nfs_getattr, |
| 6528 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6529 | .getxattr = generic_getxattr, |
| 6530 | .setxattr = generic_setxattr, |
| 6531 | .listxattr = generic_listxattr, |
| 6532 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6533 | }; |
| 6534 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6535 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | .version = 4, /* protocol version */ |
| 6537 | .dentry_ops = &nfs4_dentry_operations, |
| 6538 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6539 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6540 | .file_ops = &nfs4_file_operations, |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 6541 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6542 | .submount = nfs4_submount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6543 | .getattr = nfs4_proc_getattr, |
| 6544 | .setattr = nfs4_proc_setattr, |
| 6545 | .lookup = nfs4_proc_lookup, |
| 6546 | .access = nfs4_proc_access, |
| 6547 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6548 | .create = nfs4_proc_create, |
| 6549 | .remove = nfs4_proc_remove, |
| 6550 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6551 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6552 | .unlink_done = nfs4_proc_unlink_done, |
| 6553 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6554 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6555 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6556 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6557 | .link = nfs4_proc_link, |
| 6558 | .symlink = nfs4_proc_symlink, |
| 6559 | .mkdir = nfs4_proc_mkdir, |
| 6560 | .rmdir = nfs4_proc_remove, |
| 6561 | .readdir = nfs4_proc_readdir, |
| 6562 | .mknod = nfs4_proc_mknod, |
| 6563 | .statfs = nfs4_proc_statfs, |
| 6564 | .fsinfo = nfs4_proc_fsinfo, |
| 6565 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6566 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6567 | .decode_dirent = nfs4_decode_dirent, |
| 6568 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6569 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6570 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6571 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6572 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6573 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6575 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6576 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6577 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6578 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6579 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6580 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6581 | .init_client = nfs4_init_client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6582 | }; |
| 6583 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6584 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6585 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6586 | .list = nfs4_xattr_list_nfs4_acl, |
| 6587 | .get = nfs4_xattr_get_nfs4_acl, |
| 6588 | .set = nfs4_xattr_set_nfs4_acl, |
| 6589 | }; |
| 6590 | |
| 6591 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6592 | &nfs4_xattr_nfs4_acl_handler, |
| 6593 | NULL |
| 6594 | }; |
| 6595 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6596 | module_param(max_session_slots, ushort, 0644); |
| 6597 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6598 | "requests the client will negotiate"); |
| 6599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6600 | /* |
| 6601 | * Local variables: |
| 6602 | * c-basic-offset: 8 |
| 6603 | * End: |
| 6604 | */ |