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 | 6926afd | 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); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 83 | 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] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 86 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 87 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 88 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 89 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 90 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 92 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 94 | if (err >= -1000) |
| 95 | return err; |
| 96 | switch (err) { |
| 97 | case -NFS4ERR_RESOURCE: |
| 98 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 99 | case -NFS4ERR_WRONGSEC: |
| 100 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 101 | case -NFS4ERR_BADOWNER: |
| 102 | case -NFS4ERR_BADNAME: |
| 103 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 104 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 106 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 107 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * This is our standard bitmap for GETATTR requests. |
| 114 | */ |
| 115 | const u32 nfs4_fattr_bitmap[2] = { |
| 116 | FATTR4_WORD0_TYPE |
| 117 | | FATTR4_WORD0_CHANGE |
| 118 | | FATTR4_WORD0_SIZE |
| 119 | | FATTR4_WORD0_FSID |
| 120 | | FATTR4_WORD0_FILEID, |
| 121 | FATTR4_WORD1_MODE |
| 122 | | FATTR4_WORD1_NUMLINKS |
| 123 | | FATTR4_WORD1_OWNER |
| 124 | | FATTR4_WORD1_OWNER_GROUP |
| 125 | | FATTR4_WORD1_RAWDEV |
| 126 | | FATTR4_WORD1_SPACE_USED |
| 127 | | FATTR4_WORD1_TIME_ACCESS |
| 128 | | FATTR4_WORD1_TIME_METADATA |
| 129 | | FATTR4_WORD1_TIME_MODIFY |
| 130 | }; |
| 131 | |
| 132 | const u32 nfs4_statfs_bitmap[2] = { |
| 133 | FATTR4_WORD0_FILES_AVAIL |
| 134 | | FATTR4_WORD0_FILES_FREE |
| 135 | | FATTR4_WORD0_FILES_TOTAL, |
| 136 | FATTR4_WORD1_SPACE_AVAIL |
| 137 | | FATTR4_WORD1_SPACE_FREE |
| 138 | | FATTR4_WORD1_SPACE_TOTAL |
| 139 | }; |
| 140 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 141 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | FATTR4_WORD0_MAXLINK |
| 143 | | FATTR4_WORD0_MAXNAME, |
| 144 | 0 |
| 145 | }; |
| 146 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 147 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | | FATTR4_WORD0_MAXREAD |
| 149 | | FATTR4_WORD0_MAXWRITE |
| 150 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 151 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 152 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 153 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 156 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 157 | FATTR4_WORD0_TYPE |
| 158 | | FATTR4_WORD0_CHANGE |
| 159 | | FATTR4_WORD0_SIZE |
| 160 | | FATTR4_WORD0_FSID |
| 161 | | FATTR4_WORD0_FILEID |
| 162 | | FATTR4_WORD0_FS_LOCATIONS, |
| 163 | FATTR4_WORD1_MODE |
| 164 | | FATTR4_WORD1_NUMLINKS |
| 165 | | FATTR4_WORD1_OWNER |
| 166 | | FATTR4_WORD1_OWNER_GROUP |
| 167 | | FATTR4_WORD1_RAWDEV |
| 168 | | FATTR4_WORD1_SPACE_USED |
| 169 | | FATTR4_WORD1_TIME_ACCESS |
| 170 | | FATTR4_WORD1_TIME_METADATA |
| 171 | | FATTR4_WORD1_TIME_MODIFY |
| 172 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 173 | }; |
| 174 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 175 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | struct nfs4_readdir_arg *readdir) |
| 177 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 178 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | BUG_ON(readdir->count < 80); |
| 181 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 182 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | readdir->cookie = 0; |
| 188 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 189 | if (cookie == 2) |
| 190 | return; |
| 191 | |
| 192 | /* |
| 193 | * NFSv4 servers do not return entries for '.' and '..' |
| 194 | * Therefore, we fake these entries here. We let '.' |
| 195 | * have cookie 0 and '..' have cookie 1. Note that |
| 196 | * when talking to the server, we always send cookie 0 |
| 197 | * instead of 1 or 2. |
| 198 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 199 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | if (cookie == 0) { |
| 202 | *p++ = xdr_one; /* next */ |
| 203 | *p++ = xdr_zero; /* cookie, first word */ |
| 204 | *p++ = xdr_one; /* cookie, second word */ |
| 205 | *p++ = xdr_one; /* entry len */ |
| 206 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 207 | p++; |
| 208 | *p++ = xdr_one; /* bitmap length */ |
| 209 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 210 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 211 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | *p++ = xdr_one; /* next */ |
| 215 | *p++ = xdr_zero; /* cookie, first word */ |
| 216 | *p++ = xdr_two; /* cookie, second word */ |
| 217 | *p++ = xdr_two; /* entry len */ |
| 218 | memcpy(p, "..\0\0", 4); /* entry */ |
| 219 | p++; |
| 220 | *p++ = xdr_one; /* bitmap length */ |
| 221 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 222 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 223 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | readdir->pgbase = (char *)p - (char *)start; |
| 226 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 227 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 230 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 231 | { |
| 232 | int res; |
| 233 | |
| 234 | might_sleep(); |
| 235 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 236 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 237 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 238 | return res; |
| 239 | } |
| 240 | |
| 241 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 242 | { |
| 243 | int res = 0; |
| 244 | |
| 245 | might_sleep(); |
| 246 | |
| 247 | if (*timeout <= 0) |
| 248 | *timeout = NFS4_POLL_RETRY_MIN; |
| 249 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 250 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 251 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 252 | if (fatal_signal_pending(current)) |
| 253 | res = -ERESTARTSYS; |
| 254 | *timeout <<= 1; |
| 255 | return res; |
| 256 | } |
| 257 | |
| 258 | /* This is the error handling routine for processes that are allowed |
| 259 | * to sleep. |
| 260 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 261 | 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] | 262 | { |
| 263 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 264 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 265 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 266 | int ret = errorcode; |
| 267 | |
| 268 | exception->retry = 0; |
| 269 | switch(errorcode) { |
| 270 | case 0: |
| 271 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 272 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 273 | if (inode && nfs_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 274 | nfs_inode_return_delegation(inode); |
| 275 | exception->retry = 1; |
| 276 | return 0; |
| 277 | } |
| 278 | if (state == NULL) |
| 279 | break; |
| 280 | nfs4_schedule_stateid_recovery(server, state); |
| 281 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 282 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 283 | case -NFS4ERR_ADMIN_REVOKED: |
| 284 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 285 | if (state == NULL) |
| 286 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 287 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 288 | nfs4_schedule_stateid_recovery(server, state); |
| 289 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 290 | case -NFS4ERR_EXPIRED: |
| 291 | if (state != NULL) |
| 292 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 293 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 294 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 295 | nfs4_schedule_lease_recovery(clp); |
| 296 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 297 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 298 | case -NFS4ERR_BADSESSION: |
| 299 | case -NFS4ERR_BADSLOT: |
| 300 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 301 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 302 | case -NFS4ERR_DEADSESSION: |
| 303 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 304 | case -NFS4ERR_SEQ_MISORDERED: |
| 305 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 306 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 307 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 308 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 309 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 310 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 311 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 312 | if (exception->timeout > HZ) { |
| 313 | /* We have retried a decent amount, time to |
| 314 | * fail |
| 315 | */ |
| 316 | ret = -EBUSY; |
| 317 | break; |
| 318 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 319 | case -NFS4ERR_GRACE: |
| 320 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 321 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 322 | ret = nfs4_delay(server->client, &exception->timeout); |
| 323 | if (ret != 0) |
| 324 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 325 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 326 | case -NFS4ERR_OLD_STATEID: |
| 327 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 328 | break; |
| 329 | case -NFS4ERR_BADOWNER: |
| 330 | /* The following works around a Linux server bug! */ |
| 331 | case -NFS4ERR_BADNAME: |
| 332 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 333 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 334 | exception->retry = 1; |
| 335 | printk(KERN_WARNING "NFS: v4 server %s " |
| 336 | "does not accept raw " |
| 337 | "uid/gids. " |
| 338 | "Reenabling the idmapper.\n", |
| 339 | server->nfs_client->cl_hostname); |
| 340 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 341 | } |
| 342 | /* We failed to handle the error */ |
| 343 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 344 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 345 | ret = nfs4_wait_clnt_recover(clp); |
| 346 | if (ret == 0) |
| 347 | exception->retry = 1; |
| 348 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 352 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | spin_lock(&clp->cl_lock); |
| 355 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 356 | clp->cl_last_renewal = timestamp; |
| 357 | spin_unlock(&clp->cl_lock); |
| 358 | } |
| 359 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 360 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 361 | { |
| 362 | do_renew_lease(server->nfs_client, timestamp); |
| 363 | } |
| 364 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 365 | #if defined(CONFIG_NFS_V4_1) |
| 366 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 367 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 368 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 369 | * |
| 370 | * freeing a slot is trivially done by clearing its respective bit |
| 371 | * in the bitmap. |
| 372 | * If the freed slotid equals highest_used_slotid we want to update it |
| 373 | * so that the server would be able to size down the slot table if needed, |
| 374 | * otherwise we know that the highest_used_slotid is still in use. |
| 375 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 376 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 377 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 378 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 379 | * |
| 380 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 381 | */ |
| 382 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 383 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 384 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 385 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 386 | /* clear used bit in bitmap */ |
| 387 | __clear_bit(slotid, tbl->used_slots); |
| 388 | |
| 389 | /* update highest_used_slotid when it is freed */ |
| 390 | if (slotid == tbl->highest_used_slotid) { |
| 391 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 392 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 393 | tbl->highest_used_slotid = slotid; |
| 394 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 395 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 396 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 397 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 398 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 401 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 402 | { |
| 403 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 404 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 407 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 408 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 409 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 410 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 411 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 412 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 413 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 414 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 415 | return; |
| 416 | } |
| 417 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 418 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 419 | return; |
| 420 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 421 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 422 | complete(&ses->fc_slot_table.complete); |
| 423 | } |
| 424 | |
| 425 | /* |
| 426 | * Signal state manager thread if session back channel is drained |
| 427 | */ |
| 428 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 429 | { |
| 430 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 431 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 432 | return; |
| 433 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 434 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 437 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 438 | { |
| 439 | struct nfs4_slot_table *tbl; |
| 440 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 441 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 442 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 443 | /* just wake up the next guy waiting since |
| 444 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 445 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 446 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 447 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 448 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 449 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 450 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 451 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 452 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 453 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 454 | } |
| 455 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | 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] | 457 | { |
| 458 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 460 | |
| 461 | /* |
| 462 | * sr_status remains 1 if an RPC level error occurred. The server |
| 463 | * may or may not have processed the sequence operation.. |
| 464 | * Proceed as if the server received and processed the sequence |
| 465 | * operation. |
| 466 | */ |
| 467 | if (res->sr_status == 1) |
| 468 | res->sr_status = NFS_OK; |
| 469 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 470 | /* don't increment the sequence number if the task wasn't sent */ |
| 471 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 472 | goto out; |
| 473 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 474 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 475 | switch (res->sr_status) { |
| 476 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 477 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 478 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 479 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 480 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 481 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 482 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 483 | if (res->sr_status_flags != 0) |
| 484 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 485 | break; |
| 486 | case -NFS4ERR_DELAY: |
| 487 | /* The server detected a resend of the RPC call and |
| 488 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 489 | * of RFC5661. |
| 490 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 491 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 492 | __func__, |
| 493 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 494 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 495 | goto out_retry; |
| 496 | default: |
| 497 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 498 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 499 | } |
| 500 | out: |
| 501 | /* The session may be reset by one of the error handlers. */ |
| 502 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 503 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 504 | return 1; |
| 505 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 506 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 507 | goto out; |
| 508 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 509 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 510 | } |
| 511 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 512 | static int nfs4_sequence_done(struct rpc_task *task, |
| 513 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 514 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 515 | if (res->sr_session == NULL) |
| 516 | return 1; |
| 517 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 518 | } |
| 519 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 520 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 521 | * nfs4_find_slot - efficiently look for a free slot |
| 522 | * |
| 523 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 524 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 525 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 526 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 527 | * |
| 528 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 529 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 530 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 531 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 532 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 533 | u32 slotid; |
| 534 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 535 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 536 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 537 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 538 | tbl->max_slots); |
| 539 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 540 | if (slotid >= tbl->max_slots) |
| 541 | goto out; |
| 542 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 543 | if (slotid > tbl->highest_used_slotid || |
| 544 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 545 | tbl->highest_used_slotid = slotid; |
| 546 | ret_id = slotid; |
| 547 | out: |
| 548 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 549 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 550 | return ret_id; |
| 551 | } |
| 552 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 553 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 554 | struct nfs4_sequence_res *res, int cache_reply) |
| 555 | { |
| 556 | args->sa_session = NULL; |
| 557 | args->sa_cache_this = 0; |
| 558 | if (cache_reply) |
| 559 | args->sa_cache_this = 1; |
| 560 | res->sr_session = NULL; |
| 561 | res->sr_slot = NULL; |
| 562 | } |
| 563 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 564 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 565 | struct nfs4_sequence_args *args, |
| 566 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 567 | struct rpc_task *task) |
| 568 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 569 | struct nfs4_slot *slot; |
| 570 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 571 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 572 | |
| 573 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 574 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 575 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 576 | return 0; |
| 577 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 578 | tbl = &session->fc_slot_table; |
| 579 | |
| 580 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 581 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 582 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 583 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 584 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 585 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 586 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 587 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 590 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 591 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 592 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 593 | spin_unlock(&tbl->slot_tbl_lock); |
| 594 | dprintk("%s enforce FIFO order\n", __func__); |
| 595 | return -EAGAIN; |
| 596 | } |
| 597 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 598 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 599 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 600 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 601 | spin_unlock(&tbl->slot_tbl_lock); |
| 602 | dprintk("<-- %s: no free slots\n", __func__); |
| 603 | return -EAGAIN; |
| 604 | } |
| 605 | spin_unlock(&tbl->slot_tbl_lock); |
| 606 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 607 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 608 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 609 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 610 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 611 | |
| 612 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 613 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 614 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 615 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 616 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 617 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 618 | /* |
| 619 | * sr_status is only set in decode_sequence, and so will remain |
| 620 | * set to 1 if an rpc level failure occurs. |
| 621 | */ |
| 622 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | return 0; |
| 624 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 625 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 626 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 627 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 628 | struct nfs4_sequence_args *args, |
| 629 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct rpc_task *task) |
| 631 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 632 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 633 | int ret = 0; |
| 634 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 635 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 636 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 637 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 638 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 639 | __func__, session->clp, session, res->sr_slot ? |
| 640 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 641 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 642 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 643 | out: |
| 644 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 645 | return ret; |
| 646 | } |
| 647 | |
| 648 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 649 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 650 | struct nfs4_sequence_args *seq_args; |
| 651 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 652 | }; |
| 653 | |
| 654 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 655 | { |
| 656 | struct nfs41_call_sync_data *data = calldata; |
| 657 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 658 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 659 | |
| 660 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 661 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 662 | return; |
| 663 | rpc_call_start(task); |
| 664 | } |
| 665 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 666 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 667 | { |
| 668 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 669 | nfs41_call_sync_prepare(task, calldata); |
| 670 | } |
| 671 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 672 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 673 | { |
| 674 | struct nfs41_call_sync_data *data = calldata; |
| 675 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 676 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 677 | } |
| 678 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 679 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 681 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | }; |
| 683 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 684 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 685 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 686 | .rpc_call_done = nfs41_call_sync_done, |
| 687 | }; |
| 688 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 689 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 690 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | struct rpc_message *msg, |
| 692 | struct nfs4_sequence_args *args, |
| 693 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 694 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 695 | { |
| 696 | int ret; |
| 697 | struct rpc_task *task; |
| 698 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 699 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 700 | .seq_args = args, |
| 701 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 702 | }; |
| 703 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 704 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 705 | .rpc_message = msg, |
| 706 | .callback_ops = &nfs41_call_sync_ops, |
| 707 | .callback_data = &data |
| 708 | }; |
| 709 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 710 | if (privileged) |
| 711 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 712 | task = rpc_run_task(&task_setup); |
| 713 | if (IS_ERR(task)) |
| 714 | ret = PTR_ERR(task); |
| 715 | else { |
| 716 | ret = task->tk_status; |
| 717 | rpc_put_task(task); |
| 718 | } |
| 719 | return ret; |
| 720 | } |
| 721 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 722 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 723 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 724 | struct rpc_message *msg, |
| 725 | struct nfs4_sequence_args *args, |
| 726 | struct nfs4_sequence_res *res, |
| 727 | int cache_reply) |
| 728 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 729 | nfs41_init_sequence(args, res, cache_reply); |
| 730 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 731 | } |
| 732 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 733 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 734 | static inline |
| 735 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 736 | struct nfs4_sequence_res *res, int cache_reply) |
| 737 | { |
| 738 | } |
| 739 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 740 | static int nfs4_sequence_done(struct rpc_task *task, |
| 741 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 742 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 743 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 744 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 745 | #endif /* CONFIG_NFS_V4_1 */ |
| 746 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 747 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 748 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 749 | struct rpc_message *msg, |
| 750 | struct nfs4_sequence_args *args, |
| 751 | struct nfs4_sequence_res *res, |
| 752 | int cache_reply) |
| 753 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 754 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 755 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 756 | } |
| 757 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 758 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 759 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 760 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 761 | struct rpc_message *msg, |
| 762 | struct nfs4_sequence_args *args, |
| 763 | struct nfs4_sequence_res *res, |
| 764 | int cache_reply) |
| 765 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 766 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 767 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 768 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 769 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 770 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 772 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 774 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 775 | 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] | 776 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 777 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 778 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 779 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 782 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 783 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 784 | struct nfs_openargs o_arg; |
| 785 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 786 | struct nfs_open_confirmargs c_arg; |
| 787 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 788 | struct nfs4_string owner_name; |
| 789 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 790 | struct nfs_fattr f_attr; |
| 791 | struct nfs_fattr dir_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; |
| 807 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 808 | p->o_res.seqid = p->o_arg.seqid; |
| 809 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 810 | p->o_res.server = p->o_arg.server; |
| 811 | nfs_fattr_init(&p->f_attr); |
| 812 | nfs_fattr_init(&p->dir_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 813 | 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] | 814 | } |
| 815 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 816 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 817 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 818 | const struct iattr *attrs, |
| 819 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 821 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | struct inode *dir = parent->d_inode; |
| 823 | struct nfs_server *server = NFS_SERVER(dir); |
| 824 | struct nfs4_opendata *p; |
| 825 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 826 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | if (p == NULL) |
| 828 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 829 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | if (p->o_arg.seqid == NULL) |
| 831 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 832 | nfs_sb_active(dentry->d_sb); |
| 833 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 834 | p->dir = parent; |
| 835 | p->owner = sp; |
| 836 | atomic_inc(&sp->so_count); |
| 837 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 838 | p->o_arg.open_flags = flags; |
| 839 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 840 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 841 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 842 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 843 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 844 | p->o_arg.server = server; |
| 845 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 846 | p->o_arg.dir_bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 848 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 849 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 850 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 851 | p->o_arg.u.attrs = &p->attrs; |
| 852 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 853 | |
| 854 | verf[0] = jiffies; |
| 855 | verf[1] = current->pid; |
| 856 | memcpy(p->o_arg.u.verifier.data, verf, |
| 857 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 858 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 859 | p->c_arg.fh = &p->o_res.fh; |
| 860 | p->c_arg.stateid = &p->o_res.stateid; |
| 861 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 862 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 863 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 864 | return p; |
| 865 | err_free: |
| 866 | kfree(p); |
| 867 | err: |
| 868 | dput(parent); |
| 869 | return NULL; |
| 870 | } |
| 871 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 872 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 873 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 874 | struct nfs4_opendata *p = container_of(kref, |
| 875 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 876 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 877 | |
| 878 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 879 | if (p->state != NULL) |
| 880 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 881 | nfs4_put_state_owner(p->owner); |
| 882 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 883 | dput(p->dentry); |
| 884 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 885 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 886 | kfree(p); |
| 887 | } |
| 888 | |
| 889 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 890 | { |
| 891 | if (p != NULL) |
| 892 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 893 | } |
| 894 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 895 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 896 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 897 | int ret; |
| 898 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 899 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 900 | return ret; |
| 901 | } |
| 902 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | 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] | 904 | { |
| 905 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 906 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 907 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 908 | goto out; |
| 909 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 910 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 911 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 912 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 913 | break; |
| 914 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 915 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 916 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 917 | break; |
| 918 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 919 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 920 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 921 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 922 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 923 | return ret; |
| 924 | } |
| 925 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 926 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 927 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 928 | if (delegation == NULL) |
| 929 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 931 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 932 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 933 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 934 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 935 | return 1; |
| 936 | } |
| 937 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 939 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 941 | case FMODE_WRITE: |
| 942 | state->n_wronly++; |
| 943 | break; |
| 944 | case FMODE_READ: |
| 945 | state->n_rdonly++; |
| 946 | break; |
| 947 | case FMODE_READ|FMODE_WRITE: |
| 948 | state->n_rdwr++; |
| 949 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 950 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | 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] | 954 | { |
| 955 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 956 | nfs4_stateid_copy(&state->stateid, stateid); |
| 957 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 958 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 959 | case FMODE_READ: |
| 960 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 961 | break; |
| 962 | case FMODE_WRITE: |
| 963 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 964 | break; |
| 965 | case FMODE_READ|FMODE_WRITE: |
| 966 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 967 | } |
| 968 | } |
| 969 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | 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] | 971 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 972 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 973 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 974 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 975 | } |
| 976 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | 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] | 978 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 979 | /* |
| 980 | * Protect the call to nfs4_state_set_mode_locked and |
| 981 | * serialise the stateid update |
| 982 | */ |
| 983 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 984 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 985 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 986 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 987 | } |
| 988 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 990 | write_sequnlock(&state->seqlock); |
| 991 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 992 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 993 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | 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] | 997 | { |
| 998 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 999 | struct nfs_delegation *deleg_cur; |
| 1000 | int ret = 0; |
| 1001 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1002 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1003 | |
| 1004 | rcu_read_lock(); |
| 1005 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1006 | if (deleg_cur == NULL) |
| 1007 | goto no_delegation; |
| 1008 | |
| 1009 | spin_lock(&deleg_cur->lock); |
| 1010 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1011 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1012 | goto no_delegation_unlock; |
| 1013 | |
| 1014 | if (delegation == NULL) |
| 1015 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1016 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1017 | goto no_delegation_unlock; |
| 1018 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1019 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1021 | ret = 1; |
| 1022 | no_delegation_unlock: |
| 1023 | spin_unlock(&deleg_cur->lock); |
| 1024 | no_delegation: |
| 1025 | rcu_read_unlock(); |
| 1026 | |
| 1027 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1028 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1029 | ret = 1; |
| 1030 | } |
| 1031 | |
| 1032 | return ret; |
| 1033 | } |
| 1034 | |
| 1035 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | { |
| 1038 | struct nfs_delegation *delegation; |
| 1039 | |
| 1040 | rcu_read_lock(); |
| 1041 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1042 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1043 | rcu_read_unlock(); |
| 1044 | return; |
| 1045 | } |
| 1046 | rcu_read_unlock(); |
| 1047 | nfs_inode_return_delegation(inode); |
| 1048 | } |
| 1049 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1050 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1051 | { |
| 1052 | struct nfs4_state *state = opendata->state; |
| 1053 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1054 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1055 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1057 | nfs4_stateid stateid; |
| 1058 | int ret = -EAGAIN; |
| 1059 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1060 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1062 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1063 | if (can_open_cached(state, fmode, open_mode)) { |
| 1064 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1065 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1066 | goto out_return_state; |
| 1067 | } |
| 1068 | spin_unlock(&state->owner->so_lock); |
| 1069 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1070 | rcu_read_lock(); |
| 1071 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1072 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1073 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1074 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1075 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1077 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1078 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1079 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1080 | if (ret != 0) |
| 1081 | goto out; |
| 1082 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1083 | |
| 1084 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1086 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1087 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1088 | out: |
| 1089 | return ERR_PTR(ret); |
| 1090 | out_return_state: |
| 1091 | atomic_inc(&state->count); |
| 1092 | return state; |
| 1093 | } |
| 1094 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1095 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1096 | { |
| 1097 | struct inode *inode; |
| 1098 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1099 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1100 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1101 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1102 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1103 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | goto out; |
| 1105 | } |
| 1106 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1107 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1108 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1109 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1110 | 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] | 1111 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1112 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1113 | goto err; |
| 1114 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1115 | state = nfs4_get_open_state(inode, data->owner); |
| 1116 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1117 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1118 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1119 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1120 | int delegation_flags = 0; |
| 1121 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1122 | rcu_read_lock(); |
| 1123 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1124 | if (delegation) |
| 1125 | delegation_flags = delegation->flags; |
| 1126 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1127 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1128 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1129 | "returning a delegation for " |
| 1130 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1131 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1132 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1133 | nfs_inode_set_delegation(state->inode, |
| 1134 | data->owner->so_cred, |
| 1135 | &data->o_res); |
| 1136 | else |
| 1137 | nfs_inode_reclaim_delegation(state->inode, |
| 1138 | data->owner->so_cred, |
| 1139 | &data->o_res); |
| 1140 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1141 | |
| 1142 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1143 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1144 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1145 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1146 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1147 | err_put_inode: |
| 1148 | iput(inode); |
| 1149 | err: |
| 1150 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1153 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1154 | { |
| 1155 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1156 | struct nfs_open_context *ctx; |
| 1157 | |
| 1158 | spin_lock(&state->inode->i_lock); |
| 1159 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1160 | if (ctx->state != state) |
| 1161 | continue; |
| 1162 | get_nfs_open_context(ctx); |
| 1163 | spin_unlock(&state->inode->i_lock); |
| 1164 | return ctx; |
| 1165 | } |
| 1166 | spin_unlock(&state->inode->i_lock); |
| 1167 | return ERR_PTR(-ENOENT); |
| 1168 | } |
| 1169 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1170 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1171 | { |
| 1172 | struct nfs4_opendata *opendata; |
| 1173 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1174 | 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] | 1175 | if (opendata == NULL) |
| 1176 | return ERR_PTR(-ENOMEM); |
| 1177 | opendata->state = state; |
| 1178 | atomic_inc(&state->count); |
| 1179 | return opendata; |
| 1180 | } |
| 1181 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1182 | 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] | 1183 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1184 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1185 | int ret; |
| 1186 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1187 | opendata->o_arg.open_flags = 0; |
| 1188 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1189 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1190 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1191 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1192 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | if (ret != 0) |
| 1194 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1195 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1196 | if (IS_ERR(newstate)) |
| 1197 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1198 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1199 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1204 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1205 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1206 | int ret; |
| 1207 | |
| 1208 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1209 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | smp_rmb(); |
| 1211 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1212 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1213 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1214 | if (ret != 0) |
| 1215 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1216 | if (newstate != state) |
| 1217 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | } |
| 1219 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1220 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1221 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | if (ret != 0) |
| 1223 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1224 | if (newstate != state) |
| 1225 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1226 | } |
| 1227 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1228 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1229 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1230 | if (ret != 0) |
| 1231 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1232 | if (newstate != state) |
| 1233 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1235 | /* |
| 1236 | * We may have performed cached opens for all three recoveries. |
| 1237 | * Check if we need to update the current stateid. |
| 1238 | */ |
| 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_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1241 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1242 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1243 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1244 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1245 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1246 | return 0; |
| 1247 | } |
| 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | /* |
| 1250 | * OPEN_RECLAIM: |
| 1251 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1253 | 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] | 1254 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1255 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1256 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1257 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | int status; |
| 1259 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1260 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1261 | if (IS_ERR(opendata)) |
| 1262 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1263 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1264 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1265 | rcu_read_lock(); |
| 1266 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1267 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1268 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1269 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1270 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1271 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1272 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | return status; |
| 1274 | } |
| 1275 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1276 | 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] | 1277 | { |
| 1278 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1279 | struct nfs4_exception exception = { }; |
| 1280 | int err; |
| 1281 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1282 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1283 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1284 | break; |
| 1285 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | } while (exception.retry); |
| 1287 | return err; |
| 1288 | } |
| 1289 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1290 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1291 | { |
| 1292 | struct nfs_open_context *ctx; |
| 1293 | int ret; |
| 1294 | |
| 1295 | ctx = nfs4_state_find_open_context(state); |
| 1296 | if (IS_ERR(ctx)) |
| 1297 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1298 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1299 | put_nfs_open_context(ctx); |
| 1300 | return ret; |
| 1301 | } |
| 1302 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1303 | 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] | 1304 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1305 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1306 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1308 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1309 | if (IS_ERR(opendata)) |
| 1310 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1311 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1312 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1314 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1315 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1318 | 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] | 1319 | { |
| 1320 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1321 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | int err; |
| 1323 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1324 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | switch (err) { |
| 1326 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1327 | case -ENOENT: |
| 1328 | case -ESTALE: |
| 1329 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1330 | case -NFS4ERR_BADSESSION: |
| 1331 | case -NFS4ERR_BADSLOT: |
| 1332 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1333 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1334 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1335 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1336 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | case -NFS4ERR_STALE_CLIENTID: |
| 1338 | case -NFS4ERR_STALE_STATEID: |
| 1339 | case -NFS4ERR_EXPIRED: |
| 1340 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1341 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1342 | goto out; |
| 1343 | case -ERESTARTSYS: |
| 1344 | /* |
| 1345 | * The show must go on: exit, but mark the |
| 1346 | * stateid as needing recovery. |
| 1347 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1348 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1349 | case -NFS4ERR_ADMIN_REVOKED: |
| 1350 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1351 | nfs_inode_find_state_and_recover(state->inode, |
| 1352 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1353 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1354 | case -EKEYEXPIRED: |
| 1355 | /* |
| 1356 | * User RPCSEC_GSS context has expired. |
| 1357 | * We cannot recover this stateid now, so |
| 1358 | * skip it and allow recovery thread to |
| 1359 | * proceed. |
| 1360 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1361 | case -ENOMEM: |
| 1362 | err = 0; |
| 1363 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } |
| 1365 | err = nfs4_handle_exception(server, err, &exception); |
| 1366 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1367 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | return err; |
| 1369 | } |
| 1370 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1371 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1372 | { |
| 1373 | struct nfs4_opendata *data = calldata; |
| 1374 | |
| 1375 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1376 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1377 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1378 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1379 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1380 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1381 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | static void nfs4_open_confirm_release(void *calldata) |
| 1385 | { |
| 1386 | struct nfs4_opendata *data = calldata; |
| 1387 | struct nfs4_state *state = NULL; |
| 1388 | |
| 1389 | /* If this request hasn't been cancelled, do nothing */ |
| 1390 | if (data->cancelled == 0) |
| 1391 | goto out_free; |
| 1392 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1393 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1394 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1395 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1396 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1397 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1399 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1403 | .rpc_call_done = nfs4_open_confirm_done, |
| 1404 | .rpc_release = nfs4_open_confirm_release, |
| 1405 | }; |
| 1406 | |
| 1407 | /* |
| 1408 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1409 | */ |
| 1410 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1411 | { |
| 1412 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1413 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1414 | struct rpc_message msg = { |
| 1415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1416 | .rpc_argp = &data->c_arg, |
| 1417 | .rpc_resp = &data->c_res, |
| 1418 | .rpc_cred = data->owner->so_cred, |
| 1419 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1420 | struct rpc_task_setup task_setup_data = { |
| 1421 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1422 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1423 | .callback_ops = &nfs4_open_confirm_ops, |
| 1424 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1425 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1426 | .flags = RPC_TASK_ASYNC, |
| 1427 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | int status; |
| 1429 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1430 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1431 | data->rpc_done = 0; |
| 1432 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1433 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1434 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1435 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1436 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1437 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1438 | if (status != 0) { |
| 1439 | data->cancelled = 1; |
| 1440 | smp_wmb(); |
| 1441 | } else |
| 1442 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1443 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | return status; |
| 1445 | } |
| 1446 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1447 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1449 | struct nfs4_opendata *data = calldata; |
| 1450 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1451 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1452 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1453 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1454 | /* |
| 1455 | * Check if we still need to send an OPEN call, or if we can use |
| 1456 | * a delegation instead. |
| 1457 | */ |
| 1458 | if (data->state != NULL) { |
| 1459 | struct nfs_delegation *delegation; |
| 1460 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1461 | 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] | 1462 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1463 | rcu_read_lock(); |
| 1464 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1465 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1466 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1467 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1468 | rcu_read_unlock(); |
| 1469 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1470 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1471 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1472 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1473 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1474 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1475 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1476 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1477 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1478 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1479 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1480 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1481 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1482 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1483 | unlock_no_action: |
| 1484 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1485 | out_no_action: |
| 1486 | task->tk_action = NULL; |
| 1487 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1490 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1491 | { |
| 1492 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1493 | nfs4_open_prepare(task, calldata); |
| 1494 | } |
| 1495 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1497 | { |
| 1498 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1500 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1501 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1502 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1503 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1504 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1505 | if (task->tk_status == 0) { |
| 1506 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1507 | case S_IFREG: |
| 1508 | break; |
| 1509 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1510 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1511 | break; |
| 1512 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1513 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1514 | break; |
| 1515 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1516 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1517 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1518 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1519 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1520 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1521 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1522 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1523 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1524 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1525 | static void nfs4_open_release(void *calldata) |
| 1526 | { |
| 1527 | struct nfs4_opendata *data = calldata; |
| 1528 | struct nfs4_state *state = NULL; |
| 1529 | |
| 1530 | /* If this request hasn't been cancelled, do nothing */ |
| 1531 | if (data->cancelled == 0) |
| 1532 | goto out_free; |
| 1533 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1534 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1535 | goto out_free; |
| 1536 | /* In case we need an open_confirm, no cleanup! */ |
| 1537 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1538 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1539 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1540 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1541 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1542 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1543 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1547 | .rpc_call_prepare = nfs4_open_prepare, |
| 1548 | .rpc_call_done = nfs4_open_done, |
| 1549 | .rpc_release = nfs4_open_release, |
| 1550 | }; |
| 1551 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1552 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1553 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1554 | .rpc_call_done = nfs4_open_done, |
| 1555 | .rpc_release = nfs4_open_release, |
| 1556 | }; |
| 1557 | |
| 1558 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1559 | { |
| 1560 | struct inode *dir = data->dir->d_inode; |
| 1561 | struct nfs_server *server = NFS_SERVER(dir); |
| 1562 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1563 | struct nfs_openres *o_res = &data->o_res; |
| 1564 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1565 | struct rpc_message msg = { |
| 1566 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1567 | .rpc_argp = o_arg, |
| 1568 | .rpc_resp = o_res, |
| 1569 | .rpc_cred = data->owner->so_cred, |
| 1570 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1571 | struct rpc_task_setup task_setup_data = { |
| 1572 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1573 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1574 | .callback_ops = &nfs4_open_ops, |
| 1575 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1576 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1577 | .flags = RPC_TASK_ASYNC, |
| 1578 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1579 | int status; |
| 1580 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1581 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1582 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1583 | data->rpc_done = 0; |
| 1584 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1585 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1586 | if (isrecover) |
| 1587 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1588 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1589 | if (IS_ERR(task)) |
| 1590 | return PTR_ERR(task); |
| 1591 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1592 | if (status != 0) { |
| 1593 | data->cancelled = 1; |
| 1594 | smp_wmb(); |
| 1595 | } else |
| 1596 | status = data->rpc_status; |
| 1597 | rpc_put_task(task); |
| 1598 | |
| 1599 | return status; |
| 1600 | } |
| 1601 | |
| 1602 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1603 | { |
| 1604 | struct inode *dir = data->dir->d_inode; |
| 1605 | struct nfs_openres *o_res = &data->o_res; |
| 1606 | int status; |
| 1607 | |
| 1608 | status = nfs4_run_open_task(data, 1); |
| 1609 | if (status != 0 || !data->rpc_done) |
| 1610 | return status; |
| 1611 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1612 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1613 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1614 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1615 | |
| 1616 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1617 | status = _nfs4_proc_open_confirm(data); |
| 1618 | if (status != 0) |
| 1619 | return status; |
| 1620 | } |
| 1621 | |
| 1622 | return status; |
| 1623 | } |
| 1624 | |
| 1625 | /* |
| 1626 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1627 | */ |
| 1628 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1629 | { |
| 1630 | struct inode *dir = data->dir->d_inode; |
| 1631 | struct nfs_server *server = NFS_SERVER(dir); |
| 1632 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1633 | struct nfs_openres *o_res = &data->o_res; |
| 1634 | int status; |
| 1635 | |
| 1636 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1637 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1638 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1639 | if (status != 0) { |
| 1640 | if (status == -NFS4ERR_BADNAME && |
| 1641 | !(o_arg->open_flags & O_CREAT)) |
| 1642 | return -ENOENT; |
| 1643 | return status; |
| 1644 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1645 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1646 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1647 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1648 | if (o_arg->open_flags & O_CREAT) { |
| 1649 | update_changeattr(dir, &o_res->cinfo); |
| 1650 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1651 | } else |
| 1652 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1653 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1654 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1656 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1658 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | } |
| 1660 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1661 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1662 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1665 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1666 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1667 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1668 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1669 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1670 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1671 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1672 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1673 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1674 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1675 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1676 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1677 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1678 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1679 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1680 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1681 | } |
| 1682 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1683 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1684 | { |
| 1685 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1686 | } |
| 1687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | /* |
| 1689 | * OPEN_EXPIRED: |
| 1690 | * reclaim state on the server after a network partition. |
| 1691 | * Assumes caller holds the appropriate lock |
| 1692 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1693 | 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] | 1694 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1695 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1696 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1698 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1699 | if (IS_ERR(opendata)) |
| 1700 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1701 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1702 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1703 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1704 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1705 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1708 | 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] | 1709 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1710 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1711 | struct nfs4_exception exception = { }; |
| 1712 | int err; |
| 1713 | |
| 1714 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1715 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1716 | switch (err) { |
| 1717 | default: |
| 1718 | goto out; |
| 1719 | case -NFS4ERR_GRACE: |
| 1720 | case -NFS4ERR_DELAY: |
| 1721 | nfs4_handle_exception(server, err, &exception); |
| 1722 | err = 0; |
| 1723 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1724 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1725 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1726 | return err; |
| 1727 | } |
| 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1730 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1732 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1734 | ctx = nfs4_state_find_open_context(state); |
| 1735 | if (IS_ERR(ctx)) |
| 1736 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1737 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1738 | put_nfs_open_context(ctx); |
| 1739 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1742 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1743 | 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] | 1744 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1745 | int status = NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1746 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1747 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1748 | if (state->flags & flags) { |
| 1749 | status = nfs41_test_stateid(server, stateid); |
| 1750 | if (status != NFS_OK) { |
| 1751 | nfs41_free_stateid(server, stateid); |
| 1752 | state->flags &= ~flags; |
| 1753 | } |
| 1754 | } |
| 1755 | return status; |
| 1756 | } |
| 1757 | |
| 1758 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1759 | { |
| 1760 | int deleg_status, open_status; |
| 1761 | int deleg_flags = 1 << NFS_DELEGATED_STATE; |
| 1762 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); |
| 1763 | |
| 1764 | deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); |
| 1765 | open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags); |
| 1766 | |
| 1767 | if ((deleg_status == NFS_OK) && (open_status == NFS_OK)) |
| 1768 | return NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1769 | return nfs4_open_expired(sp, state); |
| 1770 | } |
| 1771 | #endif |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1774 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1775 | * fields corresponding to attributes that were used to store the verifier. |
| 1776 | * Make sure we clobber those fields in the later setattr call |
| 1777 | */ |
| 1778 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1779 | { |
| 1780 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1781 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1782 | sattr->ia_valid |= ATTR_ATIME; |
| 1783 | |
| 1784 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1785 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1786 | sattr->ia_valid |= ATTR_MTIME; |
| 1787 | } |
| 1788 | |
| 1789 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1790 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1792 | 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] | 1793 | { |
| 1794 | struct nfs4_state_owner *sp; |
| 1795 | struct nfs4_state *state = NULL; |
| 1796 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1797 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1798 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | |
| 1800 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1802 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1803 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1805 | goto out_err; |
| 1806 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1807 | status = nfs4_recover_expired_lease(server); |
| 1808 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1809 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1810 | if (dentry->d_inode != NULL) |
| 1811 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1812 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1813 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1814 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1815 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1817 | if (dentry->d_inode != NULL) |
| 1818 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1819 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1820 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1822 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1824 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1825 | status = PTR_ERR(state); |
| 1826 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1827 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1828 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1829 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1830 | |
| 1831 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1832 | nfs4_exclusive_attrset(opendata, sattr); |
| 1833 | |
| 1834 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1835 | status = nfs4_do_setattr(state->inode, cred, |
| 1836 | opendata->o_res.f_attr, sattr, |
| 1837 | state); |
| 1838 | if (status == 0) |
| 1839 | nfs_setattr_update_inode(state->inode, sattr); |
| 1840 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1841 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1842 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | *res = state; |
| 1845 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1846 | err_opendata_put: |
| 1847 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1848 | err_put_state_owner: |
| 1849 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | *res = NULL; |
| 1852 | return status; |
| 1853 | } |
| 1854 | |
| 1855 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1856 | 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] | 1857 | { |
| 1858 | struct nfs4_exception exception = { }; |
| 1859 | struct nfs4_state *res; |
| 1860 | int status; |
| 1861 | |
| 1862 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1863 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | if (status == 0) |
| 1865 | break; |
| 1866 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1867 | * book-keeping w.r.t. state-changing operations |
| 1868 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1869 | * It is actually a sign of a bug on the client or on the server. |
| 1870 | * |
| 1871 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1872 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | * have unhashed the old state_owner for us, and that we can |
| 1874 | * therefore safely retry using a new one. We should still warn |
| 1875 | * the user though... |
| 1876 | */ |
| 1877 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1878 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1879 | " returned a bad sequence-id error!\n", |
| 1880 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | exception.retry = 1; |
| 1882 | continue; |
| 1883 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1884 | /* |
| 1885 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1886 | * state before it received the OPEN_CONFIRM. |
| 1887 | * Recover by retrying the request as per the discussion |
| 1888 | * on Page 181 of RFC3530. |
| 1889 | */ |
| 1890 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1891 | exception.retry = 1; |
| 1892 | continue; |
| 1893 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1894 | if (status == -EAGAIN) { |
| 1895 | /* We must have found a delegation */ |
| 1896 | exception.retry = 1; |
| 1897 | continue; |
| 1898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1900 | status, &exception)); |
| 1901 | } while (exception.retry); |
| 1902 | return res; |
| 1903 | } |
| 1904 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1905 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1906 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1907 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1909 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1911 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | .iap = sattr, |
| 1913 | .server = server, |
| 1914 | .bitmask = server->attr_bitmask, |
| 1915 | }; |
| 1916 | struct nfs_setattrres res = { |
| 1917 | .fattr = fattr, |
| 1918 | .server = server, |
| 1919 | }; |
| 1920 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1921 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1922 | .rpc_argp = &arg, |
| 1923 | .rpc_resp = &res, |
| 1924 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1926 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1927 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1929 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 1931 | if (state != NULL) { |
| 1932 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 1933 | current->files, current->tgid); |
| 1934 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 1935 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1936 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1937 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1938 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1940 | 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] | 1941 | if (status == 0 && state != NULL) |
| 1942 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1943 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1946 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1947 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1948 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1950 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1951 | struct nfs4_exception exception = { |
| 1952 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 1953 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1954 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | int err; |
| 1956 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 1957 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 1958 | switch (err) { |
| 1959 | case -NFS4ERR_OPENMODE: |
| 1960 | if (state && !(state->state & FMODE_WRITE)) { |
| 1961 | err = -EBADF; |
| 1962 | if (sattr->ia_valid & ATTR_OPEN) |
| 1963 | err = -EACCES; |
| 1964 | goto out; |
| 1965 | } |
| 1966 | } |
| 1967 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 1969 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | return err; |
| 1971 | } |
| 1972 | |
| 1973 | struct nfs4_closedata { |
| 1974 | struct inode *inode; |
| 1975 | struct nfs4_state *state; |
| 1976 | struct nfs_closeargs arg; |
| 1977 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1978 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1979 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1980 | bool roc; |
| 1981 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | }; |
| 1983 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1984 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1985 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1986 | struct nfs4_closedata *calldata = data; |
| 1987 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1988 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1989 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1990 | if (calldata->roc) |
| 1991 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1992 | nfs4_put_open_state(calldata->state); |
| 1993 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1994 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1995 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1996 | kfree(calldata); |
| 1997 | } |
| 1998 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1999 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2000 | fmode_t fmode) |
| 2001 | { |
| 2002 | spin_lock(&state->owner->so_lock); |
| 2003 | if (!(fmode & FMODE_READ)) |
| 2004 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2005 | if (!(fmode & FMODE_WRITE)) |
| 2006 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2007 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2008 | spin_unlock(&state->owner->so_lock); |
| 2009 | } |
| 2010 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2011 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2013 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2016 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2017 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2018 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2019 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | /* hmm. we are done with the inode, and in the process of freeing |
| 2021 | * the state_owner. we keep this around to process errors |
| 2022 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | switch (task->tk_status) { |
| 2024 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2025 | if (calldata->roc) |
| 2026 | pnfs_roc_set_barrier(state->inode, |
| 2027 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2028 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2029 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2030 | nfs4_close_clear_stateid_flags(state, |
| 2031 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | break; |
| 2033 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2034 | case -NFS4ERR_OLD_STATEID: |
| 2035 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2037 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2038 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2040 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2041 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2043 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2044 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2045 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2048 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2050 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2051 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2052 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2053 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2054 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2055 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2056 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2057 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2058 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2059 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2060 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2061 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2062 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2063 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2064 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2065 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2066 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2067 | } |
| 2068 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2069 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2070 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2071 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2072 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2073 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2074 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2075 | |
| 2076 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2077 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2078 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2079 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2080 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2081 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2082 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2083 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2084 | if (calldata->roc && |
| 2085 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2086 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2087 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2088 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2089 | } |
| 2090 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2091 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2092 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2093 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2094 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2095 | &calldata->arg.seq_args, |
| 2096 | &calldata->res.seq_res, |
| 2097 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2098 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2099 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2100 | out: |
| 2101 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2104 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2105 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2106 | .rpc_call_done = nfs4_close_done, |
| 2107 | .rpc_release = nfs4_free_closedata, |
| 2108 | }; |
| 2109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | /* |
| 2111 | * It is possible for data to be read/written from a mem-mapped file |
| 2112 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2113 | * This means that we can't safely call nfsv4 close on a file until |
| 2114 | * the inode is cleared. This in turn means that we are not good |
| 2115 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2116 | * share state even when we are done with one of the three share |
| 2117 | * stateid's in the inode. |
| 2118 | * |
| 2119 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2120 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2121 | 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] | 2122 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2123 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2125 | struct nfs4_state_owner *sp = state->owner; |
| 2126 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2127 | struct rpc_message msg = { |
| 2128 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2129 | .rpc_cred = state->owner->so_cred, |
| 2130 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2131 | struct rpc_task_setup task_setup_data = { |
| 2132 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2133 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2134 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2135 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2136 | .flags = RPC_TASK_ASYNC, |
| 2137 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2138 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2140 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2142 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2143 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2144 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2146 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2147 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2149 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2150 | if (calldata->arg.seqid == NULL) |
| 2151 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2152 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2153 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2154 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2155 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2156 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2157 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2158 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2159 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2160 | msg.rpc_argp = &calldata->arg; |
| 2161 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2162 | task_setup_data.callback_data = calldata; |
| 2163 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2164 | if (IS_ERR(task)) |
| 2165 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2166 | status = 0; |
| 2167 | if (wait) |
| 2168 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2169 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2170 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2171 | out_free_calldata: |
| 2172 | kfree(calldata); |
| 2173 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2174 | if (roc) |
| 2175 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2176 | nfs4_put_open_state(state); |
| 2177 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2178 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2181 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2182 | 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] | 2183 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | struct nfs4_state *state; |
| 2185 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2186 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2187 | 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] | 2188 | if (IS_ERR(state)) |
| 2189 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2190 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2191 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2194 | 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] | 2195 | { |
| 2196 | if (ctx->state == NULL) |
| 2197 | return; |
| 2198 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2199 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2200 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2201 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
| 2204 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2205 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2206 | struct nfs4_server_caps_arg args = { |
| 2207 | .fhandle = fhandle, |
| 2208 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | struct nfs4_server_caps_res res = {}; |
| 2210 | struct rpc_message msg = { |
| 2211 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2212 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | .rpc_resp = &res, |
| 2214 | }; |
| 2215 | int status; |
| 2216 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2217 | 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] | 2218 | if (status == 0) { |
| 2219 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2220 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2221 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2222 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2223 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2224 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2226 | server->caps |= NFS_CAP_ACLS; |
| 2227 | if (res.has_links != 0) |
| 2228 | server->caps |= NFS_CAP_HARDLINKS; |
| 2229 | if (res.has_symlinks != 0) |
| 2230 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2231 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2232 | server->caps |= NFS_CAP_FILEID; |
| 2233 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2234 | server->caps |= NFS_CAP_MODE; |
| 2235 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2236 | server->caps |= NFS_CAP_NLINK; |
| 2237 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2238 | server->caps |= NFS_CAP_OWNER; |
| 2239 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2240 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2241 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2242 | server->caps |= NFS_CAP_ATIME; |
| 2243 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2244 | server->caps |= NFS_CAP_CTIME; |
| 2245 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2246 | server->caps |= NFS_CAP_MTIME; |
| 2247 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2248 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2249 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2250 | 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] | 2251 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2252 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | return status; |
| 2256 | } |
| 2257 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2258 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | { |
| 2260 | struct nfs4_exception exception = { }; |
| 2261 | int err; |
| 2262 | do { |
| 2263 | err = nfs4_handle_exception(server, |
| 2264 | _nfs4_server_capabilities(server, fhandle), |
| 2265 | &exception); |
| 2266 | } while (exception.retry); |
| 2267 | return err; |
| 2268 | } |
| 2269 | |
| 2270 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2271 | struct nfs_fsinfo *info) |
| 2272 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | struct nfs4_lookup_root_arg args = { |
| 2274 | .bitmask = nfs4_fattr_bitmap, |
| 2275 | }; |
| 2276 | struct nfs4_lookup_res res = { |
| 2277 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2278 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | .fh = fhandle, |
| 2280 | }; |
| 2281 | struct rpc_message msg = { |
| 2282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2283 | .rpc_argp = &args, |
| 2284 | .rpc_resp = &res, |
| 2285 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2286 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2287 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2288 | 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] | 2289 | } |
| 2290 | |
| 2291 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2292 | struct nfs_fsinfo *info) |
| 2293 | { |
| 2294 | struct nfs4_exception exception = { }; |
| 2295 | int err; |
| 2296 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2297 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2298 | switch (err) { |
| 2299 | case 0: |
| 2300 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2301 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2302 | default: |
| 2303 | err = nfs4_handle_exception(server, err, &exception); |
| 2304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2306 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | return err; |
| 2308 | } |
| 2309 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2310 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2311 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2312 | { |
| 2313 | struct rpc_auth *auth; |
| 2314 | int ret; |
| 2315 | |
| 2316 | auth = rpcauth_create(flavor, server->client); |
| 2317 | if (!auth) { |
| 2318 | ret = -EIO; |
| 2319 | goto out; |
| 2320 | } |
| 2321 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2322 | out: |
| 2323 | return ret; |
| 2324 | } |
| 2325 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2326 | 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] | 2327 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2329 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2330 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2332 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2333 | flav_array[len] = RPC_AUTH_NULL; |
| 2334 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2335 | |
| 2336 | for (i = 0; i < len; i++) { |
| 2337 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2338 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2339 | continue; |
| 2340 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2341 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2342 | /* |
| 2343 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2344 | * to access the mount. It could also mean that we tried to mount |
| 2345 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2346 | * existing mount programs don't handle -EACCES very well so it should |
| 2347 | * be mapped to -EPERM instead. |
| 2348 | */ |
| 2349 | if (status == -EACCES) |
| 2350 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2351 | return status; |
| 2352 | } |
| 2353 | |
| 2354 | /* |
| 2355 | * get the file handle for the "/" directory on the server |
| 2356 | */ |
| 2357 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2358 | struct nfs_fsinfo *info) |
| 2359 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2360 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2361 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2362 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2363 | /* |
| 2364 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2365 | * by nfs4_map_errors() as this function exits. |
| 2366 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2367 | 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] | 2368 | if (status == 0) |
| 2369 | status = nfs4_server_capabilities(server, fhandle); |
| 2370 | if (status == 0) |
| 2371 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2372 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2375 | /* |
| 2376 | * Get locations and (maybe) other attributes of a referral. |
| 2377 | * Note that we'll actually follow the referral later when |
| 2378 | * we detect fsid mismatch in inode revalidation |
| 2379 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2380 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2381 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2382 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2383 | { |
| 2384 | int status = -ENOMEM; |
| 2385 | struct page *page = NULL; |
| 2386 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2387 | |
| 2388 | page = alloc_page(GFP_KERNEL); |
| 2389 | if (page == NULL) |
| 2390 | goto out; |
| 2391 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2392 | if (locations == NULL) |
| 2393 | goto out; |
| 2394 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2395 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2396 | if (status != 0) |
| 2397 | goto out; |
| 2398 | /* Make sure server returned a different fsid for the referral */ |
| 2399 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2400 | dprintk("%s: server did not return a different fsid for" |
| 2401 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2402 | status = -EIO; |
| 2403 | goto out; |
| 2404 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2405 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2406 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2407 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2408 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2409 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2410 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2411 | out: |
| 2412 | if (page) |
| 2413 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2414 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2415 | return status; |
| 2416 | } |
| 2417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2419 | { |
| 2420 | struct nfs4_getattr_arg args = { |
| 2421 | .fh = fhandle, |
| 2422 | .bitmask = server->attr_bitmask, |
| 2423 | }; |
| 2424 | struct nfs4_getattr_res res = { |
| 2425 | .fattr = fattr, |
| 2426 | .server = server, |
| 2427 | }; |
| 2428 | struct rpc_message msg = { |
| 2429 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2430 | .rpc_argp = &args, |
| 2431 | .rpc_resp = &res, |
| 2432 | }; |
| 2433 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2434 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2435 | 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] | 2436 | } |
| 2437 | |
| 2438 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2439 | { |
| 2440 | struct nfs4_exception exception = { }; |
| 2441 | int err; |
| 2442 | do { |
| 2443 | err = nfs4_handle_exception(server, |
| 2444 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2445 | &exception); |
| 2446 | } while (exception.retry); |
| 2447 | return err; |
| 2448 | } |
| 2449 | |
| 2450 | /* |
| 2451 | * The file is not closed if it is opened due to the a request to change |
| 2452 | * the size of the file. The open call will not be needed once the |
| 2453 | * VFS layer lookup-intents are implemented. |
| 2454 | * |
| 2455 | * Close is called when the inode is destroyed. |
| 2456 | * If we haven't opened the file for O_WRONLY, we |
| 2457 | * need to in the size_change case to obtain a stateid. |
| 2458 | * |
| 2459 | * Got race? |
| 2460 | * Because OPEN is always done by name in nfsv4, it is |
| 2461 | * possible that we opened a different file by the same |
| 2462 | * name. We can recognize this race condition, but we |
| 2463 | * can't do anything about it besides returning an error. |
| 2464 | * |
| 2465 | * This will be fixed with VFS changes (lookup-intent). |
| 2466 | */ |
| 2467 | static int |
| 2468 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2469 | struct iattr *sattr) |
| 2470 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2471 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2472 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2473 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | int status; |
| 2475 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2476 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2477 | pnfs_return_layout(inode); |
| 2478 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2479 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2481 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2482 | if (sattr->ia_valid & ATTR_FILE) { |
| 2483 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2484 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2485 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2486 | if (ctx) { |
| 2487 | cred = ctx->cred; |
| 2488 | state = ctx->state; |
| 2489 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2490 | } |
| 2491 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 2492 | /* Deal with open(O_TRUNC) */ |
| 2493 | if (sattr->ia_valid & ATTR_OPEN) |
| 2494 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2495 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2496 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2497 | if (status == 0) |
| 2498 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | return status; |
| 2500 | } |
| 2501 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2502 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2503 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2504 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2505 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2506 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2507 | int status; |
| 2508 | struct nfs4_lookup_arg args = { |
| 2509 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2510 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2511 | .name = name, |
| 2512 | }; |
| 2513 | struct nfs4_lookup_res res = { |
| 2514 | .server = server, |
| 2515 | .fattr = fattr, |
| 2516 | .fh = fhandle, |
| 2517 | }; |
| 2518 | struct rpc_message msg = { |
| 2519 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2520 | .rpc_argp = &args, |
| 2521 | .rpc_resp = &res, |
| 2522 | }; |
| 2523 | |
| 2524 | nfs_fattr_init(fattr); |
| 2525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2527 | 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] | 2528 | dprintk("NFS reply lookup: %d\n", status); |
| 2529 | return status; |
| 2530 | } |
| 2531 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2532 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2533 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2534 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2535 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2536 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2537 | fattr->nlink = 2; |
| 2538 | } |
| 2539 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2540 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2541 | struct qstr *name, struct nfs_fh *fhandle, |
| 2542 | struct nfs_fattr *fattr) |
| 2543 | { |
| 2544 | struct nfs4_exception exception = { }; |
| 2545 | struct rpc_clnt *client = *clnt; |
| 2546 | int err; |
| 2547 | do { |
| 2548 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2549 | switch (err) { |
| 2550 | case -NFS4ERR_BADNAME: |
| 2551 | err = -ENOENT; |
| 2552 | goto out; |
| 2553 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2554 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2555 | goto out; |
| 2556 | case -NFS4ERR_WRONGSEC: |
| 2557 | err = -EPERM; |
| 2558 | if (client != *clnt) |
| 2559 | goto out; |
| 2560 | |
| 2561 | client = nfs4_create_sec_client(client, dir, name); |
| 2562 | if (IS_ERR(client)) |
| 2563 | return PTR_ERR(client); |
| 2564 | |
| 2565 | exception.retry = 1; |
| 2566 | break; |
| 2567 | default: |
| 2568 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2569 | } |
| 2570 | } while (exception.retry); |
| 2571 | |
| 2572 | out: |
| 2573 | if (err == 0) |
| 2574 | *clnt = client; |
| 2575 | else if (client != *clnt) |
| 2576 | rpc_shutdown_client(client); |
| 2577 | |
| 2578 | return err; |
| 2579 | } |
| 2580 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2581 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2582 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2584 | int status; |
| 2585 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2586 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2587 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2588 | if (client != NFS_CLIENT(dir)) { |
| 2589 | rpc_shutdown_client(client); |
| 2590 | nfs_fixup_secinfo_attributes(fattr); |
| 2591 | } |
| 2592 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2595 | struct rpc_clnt * |
| 2596 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2597 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2598 | { |
| 2599 | int status; |
| 2600 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2601 | |
| 2602 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2603 | if (status < 0) { |
| 2604 | rpc_shutdown_client(client); |
| 2605 | return ERR_PTR(status); |
| 2606 | } |
| 2607 | return client; |
| 2608 | } |
| 2609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2611 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2612 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | struct nfs4_accessargs args = { |
| 2614 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2615 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2617 | struct nfs4_accessres res = { |
| 2618 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2619 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | struct rpc_message msg = { |
| 2621 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2622 | .rpc_argp = &args, |
| 2623 | .rpc_resp = &res, |
| 2624 | .rpc_cred = entry->cred, |
| 2625 | }; |
| 2626 | int mode = entry->mask; |
| 2627 | int status; |
| 2628 | |
| 2629 | /* |
| 2630 | * Determine which access bits we want to ask for... |
| 2631 | */ |
| 2632 | if (mode & MAY_READ) |
| 2633 | args.access |= NFS4_ACCESS_READ; |
| 2634 | if (S_ISDIR(inode->i_mode)) { |
| 2635 | if (mode & MAY_WRITE) |
| 2636 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2637 | if (mode & MAY_EXEC) |
| 2638 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2639 | } else { |
| 2640 | if (mode & MAY_WRITE) |
| 2641 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2642 | if (mode & MAY_EXEC) |
| 2643 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2644 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2645 | |
| 2646 | res.fattr = nfs_alloc_fattr(); |
| 2647 | if (res.fattr == NULL) |
| 2648 | return -ENOMEM; |
| 2649 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2650 | 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] | 2651 | if (!status) { |
| 2652 | entry->mask = 0; |
| 2653 | if (res.access & NFS4_ACCESS_READ) |
| 2654 | entry->mask |= MAY_READ; |
| 2655 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2656 | entry->mask |= MAY_WRITE; |
| 2657 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2658 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2659 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2661 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | return status; |
| 2663 | } |
| 2664 | |
| 2665 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2666 | { |
| 2667 | struct nfs4_exception exception = { }; |
| 2668 | int err; |
| 2669 | do { |
| 2670 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2671 | _nfs4_proc_access(inode, entry), |
| 2672 | &exception); |
| 2673 | } while (exception.retry); |
| 2674 | return err; |
| 2675 | } |
| 2676 | |
| 2677 | /* |
| 2678 | * TODO: For the time being, we don't try to get any attributes |
| 2679 | * along with any of the zero-copy operations READ, READDIR, |
| 2680 | * READLINK, WRITE. |
| 2681 | * |
| 2682 | * In the case of the first three, we want to put the GETATTR |
| 2683 | * after the read-type operation -- this is because it is hard |
| 2684 | * to predict the length of a GETATTR response in v4, and thus |
| 2685 | * align the READ data correctly. This means that the GETATTR |
| 2686 | * may end up partially falling into the page cache, and we should |
| 2687 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2688 | * To do this efficiently, we need to know the total length |
| 2689 | * of data received, which doesn't seem to be available outside |
| 2690 | * of the RPC layer. |
| 2691 | * |
| 2692 | * In the case of WRITE, we also want to put the GETATTR after |
| 2693 | * the operation -- in this case because we want to make sure |
| 2694 | * we get the post-operation mtime and size. This means that |
| 2695 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2696 | * of it which would leave room in the 'tail' iovec. |
| 2697 | * |
| 2698 | * Both of these changes to the XDR layer would in fact be quite |
| 2699 | * minor, but I decided to leave them for a subsequent patch. |
| 2700 | */ |
| 2701 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2702 | unsigned int pgbase, unsigned int pglen) |
| 2703 | { |
| 2704 | struct nfs4_readlink args = { |
| 2705 | .fh = NFS_FH(inode), |
| 2706 | .pgbase = pgbase, |
| 2707 | .pglen = pglen, |
| 2708 | .pages = &page, |
| 2709 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2710 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | struct rpc_message msg = { |
| 2712 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2713 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2714 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | }; |
| 2716 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2717 | 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] | 2718 | } |
| 2719 | |
| 2720 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2721 | unsigned int pgbase, unsigned int pglen) |
| 2722 | { |
| 2723 | struct nfs4_exception exception = { }; |
| 2724 | int err; |
| 2725 | do { |
| 2726 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2727 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2728 | &exception); |
| 2729 | } while (exception.retry); |
| 2730 | return err; |
| 2731 | } |
| 2732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | /* |
| 2734 | * Got race? |
| 2735 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2736 | * Until then, this create/open method is prone to inefficiency and race |
| 2737 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2738 | * placed on the wire. |
| 2739 | * |
| 2740 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2741 | * The file will be opened again in the subsequent VFS open call |
| 2742 | * (nfs4_proc_file_open). |
| 2743 | * |
| 2744 | * The open for read will just hang around to be used by any process that |
| 2745 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2746 | */ |
| 2747 | |
| 2748 | static int |
| 2749 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2750 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2752 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2754 | struct rpc_cred *cred = NULL; |
| 2755 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | int status = 0; |
| 2757 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2758 | if (ctx != NULL) { |
| 2759 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2760 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2761 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2763 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2764 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2765 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | if (IS_ERR(state)) { |
| 2767 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2768 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2770 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2771 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2772 | if (ctx != NULL) |
| 2773 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2774 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2775 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | out: |
| 2777 | return status; |
| 2778 | } |
| 2779 | |
| 2780 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2781 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2782 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2783 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2785 | .name.len = name->len, |
| 2786 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2787 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2789 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2790 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2791 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2793 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2794 | .rpc_argp = &args, |
| 2795 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2797 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2799 | res.dir_attr = nfs_alloc_fattr(); |
| 2800 | if (res.dir_attr == NULL) |
| 2801 | goto out; |
| 2802 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2803 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2804 | if (status == 0) { |
| 2805 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2806 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2807 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2808 | nfs_free_fattr(res.dir_attr); |
| 2809 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | return status; |
| 2811 | } |
| 2812 | |
| 2813 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2814 | { |
| 2815 | struct nfs4_exception exception = { }; |
| 2816 | int err; |
| 2817 | do { |
| 2818 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2819 | _nfs4_proc_remove(dir, name), |
| 2820 | &exception); |
| 2821 | } while (exception.retry); |
| 2822 | return err; |
| 2823 | } |
| 2824 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2825 | 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] | 2826 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2827 | struct nfs_server *server = NFS_SERVER(dir); |
| 2828 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2829 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2831 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2832 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2834 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2837 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2838 | { |
| 2839 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2840 | &data->args.seq_args, |
| 2841 | &data->res.seq_res, |
| 2842 | task)) |
| 2843 | return; |
| 2844 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2847 | 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] | 2848 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2849 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2850 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2851 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2852 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2853 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2854 | return 0; |
| 2855 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2856 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2857 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2860 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2861 | { |
| 2862 | struct nfs_server *server = NFS_SERVER(dir); |
| 2863 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2864 | struct nfs_renameres *res = msg->rpc_resp; |
| 2865 | |
| 2866 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2867 | arg->bitmask = server->attr_bitmask; |
| 2868 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2869 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2870 | } |
| 2871 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2872 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2873 | { |
| 2874 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2875 | &data->args.seq_args, |
| 2876 | &data->res.seq_res, |
| 2877 | task)) |
| 2878 | return; |
| 2879 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2880 | } |
| 2881 | |
| 2882 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2883 | struct inode *new_dir) |
| 2884 | { |
| 2885 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2886 | |
| 2887 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2888 | return 0; |
| 2889 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2890 | return 0; |
| 2891 | |
| 2892 | update_changeattr(old_dir, &res->old_cinfo); |
| 2893 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2894 | update_changeattr(new_dir, &res->new_cinfo); |
| 2895 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2896 | return 1; |
| 2897 | } |
| 2898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2900 | struct inode *new_dir, struct qstr *new_name) |
| 2901 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2902 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2903 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | .old_dir = NFS_FH(old_dir), |
| 2905 | .new_dir = NFS_FH(new_dir), |
| 2906 | .old_name = old_name, |
| 2907 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2908 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2910 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2911 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2912 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | struct rpc_message msg = { |
| 2914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2915 | .rpc_argp = &arg, |
| 2916 | .rpc_resp = &res, |
| 2917 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2918 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2920 | res.old_fattr = nfs_alloc_fattr(); |
| 2921 | res.new_fattr = nfs_alloc_fattr(); |
| 2922 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2923 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2925 | 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] | 2926 | if (!status) { |
| 2927 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2928 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2930 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2932 | out: |
| 2933 | nfs_free_fattr(res.new_fattr); |
| 2934 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | return status; |
| 2936 | } |
| 2937 | |
| 2938 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2939 | struct inode *new_dir, struct qstr *new_name) |
| 2940 | { |
| 2941 | struct nfs4_exception exception = { }; |
| 2942 | int err; |
| 2943 | do { |
| 2944 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2945 | _nfs4_proc_rename(old_dir, old_name, |
| 2946 | new_dir, new_name), |
| 2947 | &exception); |
| 2948 | } while (exception.retry); |
| 2949 | return err; |
| 2950 | } |
| 2951 | |
| 2952 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2953 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2954 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | struct nfs4_link_arg arg = { |
| 2956 | .fh = NFS_FH(inode), |
| 2957 | .dir_fh = NFS_FH(dir), |
| 2958 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2959 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2961 | struct nfs4_link_res res = { |
| 2962 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2963 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | struct rpc_message msg = { |
| 2965 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2966 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2967 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2969 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2971 | res.fattr = nfs_alloc_fattr(); |
| 2972 | res.dir_attr = nfs_alloc_fattr(); |
| 2973 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2974 | goto out; |
| 2975 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2976 | 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] | 2977 | if (!status) { |
| 2978 | update_changeattr(dir, &res.cinfo); |
| 2979 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2980 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2981 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2982 | out: |
| 2983 | nfs_free_fattr(res.dir_attr); |
| 2984 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | return status; |
| 2986 | } |
| 2987 | |
| 2988 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2989 | { |
| 2990 | struct nfs4_exception exception = { }; |
| 2991 | int err; |
| 2992 | do { |
| 2993 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2994 | _nfs4_proc_link(inode, dir, name), |
| 2995 | &exception); |
| 2996 | } while (exception.retry); |
| 2997 | return err; |
| 2998 | } |
| 2999 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3000 | struct nfs4_createdata { |
| 3001 | struct rpc_message msg; |
| 3002 | struct nfs4_create_arg arg; |
| 3003 | struct nfs4_create_res res; |
| 3004 | struct nfs_fh fh; |
| 3005 | struct nfs_fattr fattr; |
| 3006 | struct nfs_fattr dir_fattr; |
| 3007 | }; |
| 3008 | |
| 3009 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3010 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3011 | { |
| 3012 | struct nfs4_createdata *data; |
| 3013 | |
| 3014 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3015 | if (data != NULL) { |
| 3016 | struct nfs_server *server = NFS_SERVER(dir); |
| 3017 | |
| 3018 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3019 | data->msg.rpc_argp = &data->arg; |
| 3020 | data->msg.rpc_resp = &data->res; |
| 3021 | data->arg.dir_fh = NFS_FH(dir); |
| 3022 | data->arg.server = server; |
| 3023 | data->arg.name = name; |
| 3024 | data->arg.attrs = sattr; |
| 3025 | data->arg.ftype = ftype; |
| 3026 | data->arg.bitmask = server->attr_bitmask; |
| 3027 | data->res.server = server; |
| 3028 | data->res.fh = &data->fh; |
| 3029 | data->res.fattr = &data->fattr; |
| 3030 | data->res.dir_fattr = &data->dir_fattr; |
| 3031 | nfs_fattr_init(data->res.fattr); |
| 3032 | nfs_fattr_init(data->res.dir_fattr); |
| 3033 | } |
| 3034 | return data; |
| 3035 | } |
| 3036 | |
| 3037 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3038 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3039 | 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] | 3040 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3041 | if (status == 0) { |
| 3042 | update_changeattr(dir, &data->res.dir_cinfo); |
| 3043 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 3044 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3045 | } |
| 3046 | return status; |
| 3047 | } |
| 3048 | |
| 3049 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3050 | { |
| 3051 | kfree(data); |
| 3052 | } |
| 3053 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3054 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3055 | struct page *page, unsigned int len, struct iattr *sattr) |
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 | struct nfs4_createdata *data; |
| 3058 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3060 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3061 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3062 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3063 | status = -ENOMEM; |
| 3064 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3065 | if (data == NULL) |
| 3066 | goto out; |
| 3067 | |
| 3068 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3069 | data->arg.u.symlink.pages = &page; |
| 3070 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3072 | status = nfs4_do_create(dir, dentry, data); |
| 3073 | |
| 3074 | nfs4_free_createdata(data); |
| 3075 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | return status; |
| 3077 | } |
| 3078 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3079 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3080 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | { |
| 3082 | struct nfs4_exception exception = { }; |
| 3083 | int err; |
| 3084 | do { |
| 3085 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3086 | _nfs4_proc_symlink(dir, dentry, page, |
| 3087 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | &exception); |
| 3089 | } while (exception.retry); |
| 3090 | return err; |
| 3091 | } |
| 3092 | |
| 3093 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3094 | struct iattr *sattr) |
| 3095 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3096 | struct nfs4_createdata *data; |
| 3097 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3099 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3100 | if (data == NULL) |
| 3101 | goto out; |
| 3102 | |
| 3103 | status = nfs4_do_create(dir, dentry, data); |
| 3104 | |
| 3105 | nfs4_free_createdata(data); |
| 3106 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | return status; |
| 3108 | } |
| 3109 | |
| 3110 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3111 | struct iattr *sattr) |
| 3112 | { |
| 3113 | struct nfs4_exception exception = { }; |
| 3114 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3115 | |
| 3116 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | do { |
| 3118 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3119 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3120 | &exception); |
| 3121 | } while (exception.retry); |
| 3122 | return err; |
| 3123 | } |
| 3124 | |
| 3125 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3126 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | { |
| 3128 | struct inode *dir = dentry->d_inode; |
| 3129 | struct nfs4_readdir_arg args = { |
| 3130 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3131 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | .pgbase = 0, |
| 3133 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3134 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3135 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | }; |
| 3137 | struct nfs4_readdir_res res; |
| 3138 | struct rpc_message msg = { |
| 3139 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3140 | .rpc_argp = &args, |
| 3141 | .rpc_resp = &res, |
| 3142 | .rpc_cred = cred, |
| 3143 | }; |
| 3144 | int status; |
| 3145 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3146 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3147 | dentry->d_parent->d_name.name, |
| 3148 | dentry->d_name.name, |
| 3149 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3151 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3152 | 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] | 3153 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3155 | status += args.pgbase; |
| 3156 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3157 | |
| 3158 | nfs_invalidate_atime(dir); |
| 3159 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3160 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | return status; |
| 3162 | } |
| 3163 | |
| 3164 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3165 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | { |
| 3167 | struct nfs4_exception exception = { }; |
| 3168 | int err; |
| 3169 | do { |
| 3170 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3171 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3172 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | &exception); |
| 3174 | } while (exception.retry); |
| 3175 | return err; |
| 3176 | } |
| 3177 | |
| 3178 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3179 | struct iattr *sattr, dev_t rdev) |
| 3180 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3181 | struct nfs4_createdata *data; |
| 3182 | int mode = sattr->ia_mode; |
| 3183 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | |
| 3185 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3186 | 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] | 3187 | |
| 3188 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3189 | if (data == NULL) |
| 3190 | goto out; |
| 3191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3193 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3195 | data->arg.ftype = NF4BLK; |
| 3196 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3197 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } |
| 3199 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3200 | data->arg.ftype = NF4CHR; |
| 3201 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3202 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3205 | status = nfs4_do_create(dir, dentry, data); |
| 3206 | |
| 3207 | nfs4_free_createdata(data); |
| 3208 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | return status; |
| 3210 | } |
| 3211 | |
| 3212 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3213 | struct iattr *sattr, dev_t rdev) |
| 3214 | { |
| 3215 | struct nfs4_exception exception = { }; |
| 3216 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3217 | |
| 3218 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | do { |
| 3220 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3221 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3222 | &exception); |
| 3223 | } while (exception.retry); |
| 3224 | return err; |
| 3225 | } |
| 3226 | |
| 3227 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3228 | struct nfs_fsstat *fsstat) |
| 3229 | { |
| 3230 | struct nfs4_statfs_arg args = { |
| 3231 | .fh = fhandle, |
| 3232 | .bitmask = server->attr_bitmask, |
| 3233 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3234 | struct nfs4_statfs_res res = { |
| 3235 | .fsstat = fsstat, |
| 3236 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | struct rpc_message msg = { |
| 3238 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3239 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3240 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | }; |
| 3242 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3243 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3244 | 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] | 3245 | } |
| 3246 | |
| 3247 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3248 | { |
| 3249 | struct nfs4_exception exception = { }; |
| 3250 | int err; |
| 3251 | do { |
| 3252 | err = nfs4_handle_exception(server, |
| 3253 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3254 | &exception); |
| 3255 | } while (exception.retry); |
| 3256 | return err; |
| 3257 | } |
| 3258 | |
| 3259 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3260 | struct nfs_fsinfo *fsinfo) |
| 3261 | { |
| 3262 | struct nfs4_fsinfo_arg args = { |
| 3263 | .fh = fhandle, |
| 3264 | .bitmask = server->attr_bitmask, |
| 3265 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3266 | struct nfs4_fsinfo_res res = { |
| 3267 | .fsinfo = fsinfo, |
| 3268 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | struct rpc_message msg = { |
| 3270 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3271 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3272 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | }; |
| 3274 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3275 | 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] | 3276 | } |
| 3277 | |
| 3278 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3279 | { |
| 3280 | struct nfs4_exception exception = { }; |
| 3281 | int err; |
| 3282 | |
| 3283 | do { |
| 3284 | err = nfs4_handle_exception(server, |
| 3285 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3286 | &exception); |
| 3287 | } while (exception.retry); |
| 3288 | return err; |
| 3289 | } |
| 3290 | |
| 3291 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3292 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3293 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3295 | } |
| 3296 | |
| 3297 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3298 | struct nfs_pathconf *pathconf) |
| 3299 | { |
| 3300 | struct nfs4_pathconf_arg args = { |
| 3301 | .fh = fhandle, |
| 3302 | .bitmask = server->attr_bitmask, |
| 3303 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3304 | struct nfs4_pathconf_res res = { |
| 3305 | .pathconf = pathconf, |
| 3306 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | struct rpc_message msg = { |
| 3308 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3309 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3310 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | }; |
| 3312 | |
| 3313 | /* None of the pathconf attributes are mandatory to implement */ |
| 3314 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3315 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3316 | return 0; |
| 3317 | } |
| 3318 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3319 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3320 | 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] | 3321 | } |
| 3322 | |
| 3323 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3324 | struct nfs_pathconf *pathconf) |
| 3325 | { |
| 3326 | struct nfs4_exception exception = { }; |
| 3327 | int err; |
| 3328 | |
| 3329 | do { |
| 3330 | err = nfs4_handle_exception(server, |
| 3331 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3332 | &exception); |
| 3333 | } while (exception.retry); |
| 3334 | return err; |
| 3335 | } |
| 3336 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3337 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3338 | { |
| 3339 | nfs_invalidate_atime(data->inode); |
| 3340 | } |
| 3341 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3342 | 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] | 3343 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3344 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3346 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3347 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3348 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3350 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3351 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3353 | renew_lease(server, data->timestamp); |
| 3354 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3357 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3358 | { |
| 3359 | |
| 3360 | dprintk("--> %s\n", __func__); |
| 3361 | |
| 3362 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3363 | return -EAGAIN; |
| 3364 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3365 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3366 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3369 | 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] | 3370 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3372 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3373 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3374 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3377 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3378 | { |
| 3379 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3380 | &data->args.seq_args, |
| 3381 | &data->res.seq_res, |
| 3382 | task)) |
| 3383 | return; |
| 3384 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3387 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3388 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3389 | { |
| 3390 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3391 | put_lseg(data->lseg); |
| 3392 | data->lseg = NULL; |
| 3393 | /* offsets will differ in the dense stripe case */ |
| 3394 | data->args.offset = data->mds_offset; |
| 3395 | data->ds_clp = NULL; |
| 3396 | data->args.fh = NFS_FH(data->inode); |
| 3397 | data->read_done_cb = nfs4_read_done_cb; |
| 3398 | task->tk_ops = data->mds_ops; |
| 3399 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3400 | } |
| 3401 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3402 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3403 | 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] | 3404 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | struct inode *inode = data->inode; |
| 3406 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3407 | 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] | 3408 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3409 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3411 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3413 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3414 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3415 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3418 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3419 | { |
| 3420 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3421 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3422 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3423 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3426 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3427 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3428 | { |
| 3429 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3430 | put_lseg(data->lseg); |
| 3431 | data->lseg = NULL; |
| 3432 | data->ds_clp = NULL; |
| 3433 | data->write_done_cb = nfs4_write_done_cb; |
| 3434 | data->args.fh = NFS_FH(data->inode); |
| 3435 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3436 | data->args.offset = data->mds_offset; |
| 3437 | data->res.fattr = &data->fattr; |
| 3438 | task->tk_ops = data->mds_ops; |
| 3439 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3440 | } |
| 3441 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3442 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3443 | 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] | 3444 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3445 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3446 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3447 | if (data->lseg) { |
| 3448 | data->args.bitmask = NULL; |
| 3449 | data->res.fattr = NULL; |
| 3450 | } else |
| 3451 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3452 | if (!data->write_done_cb) |
| 3453 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3454 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | data->timestamp = jiffies; |
| 3456 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3457 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3458 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3461 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3462 | { |
| 3463 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3464 | &data->args.seq_args, |
| 3465 | &data->res.seq_res, |
| 3466 | task)) |
| 3467 | return; |
| 3468 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3471 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3474 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3475 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3476 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3477 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3479 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3480 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | } |
| 3482 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3483 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3484 | { |
| 3485 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3486 | return -EAGAIN; |
| 3487 | return data->write_done_cb(task, data); |
| 3488 | } |
| 3489 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3490 | static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3492 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3493 | |
| 3494 | if (data->lseg) { |
| 3495 | data->args.bitmask = NULL; |
| 3496 | data->res.fattr = NULL; |
| 3497 | } else |
| 3498 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3499 | if (!data->write_done_cb) |
| 3500 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3501 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3502 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3503 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3506 | struct nfs4_renewdata { |
| 3507 | struct nfs_client *client; |
| 3508 | unsigned long timestamp; |
| 3509 | }; |
| 3510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | /* |
| 3512 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3513 | * standalone procedure for queueing an asynchronous RENEW. |
| 3514 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3515 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3516 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3517 | struct nfs4_renewdata *data = calldata; |
| 3518 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3519 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3520 | if (atomic_read(&clp->cl_count) > 1) |
| 3521 | nfs4_schedule_state_renewal(clp); |
| 3522 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3523 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3526 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
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 = calldata; |
| 3529 | struct nfs_client *clp = data->client; |
| 3530 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
| 3532 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3533 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3534 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3535 | return; |
| 3536 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3537 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3538 | return; |
| 3539 | } |
| 3540 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3542 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3545 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3546 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3547 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3548 | }; |
| 3549 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3550 | 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] | 3551 | { |
| 3552 | struct rpc_message msg = { |
| 3553 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3554 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3555 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3557 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3559 | if (renew_flags == 0) |
| 3560 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3561 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3562 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3563 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3564 | if (data == NULL) |
| 3565 | return -ENOMEM; |
| 3566 | data->client = clp; |
| 3567 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3569 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3572 | 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] | 3573 | { |
| 3574 | struct rpc_message msg = { |
| 3575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3576 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3577 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | }; |
| 3579 | unsigned long now = jiffies; |
| 3580 | int status; |
| 3581 | |
| 3582 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3583 | if (status < 0) |
| 3584 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3585 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | return 0; |
| 3587 | } |
| 3588 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3589 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3590 | { |
| 3591 | return (server->caps & NFS_CAP_ACLS) |
| 3592 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3593 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3594 | } |
| 3595 | |
| 3596 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3597 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3598 | * the stack. |
| 3599 | */ |
| 3600 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3601 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3602 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3603 | struct page **pages, unsigned int *pgbase) |
| 3604 | { |
| 3605 | struct page *newpage, **spages; |
| 3606 | int rc = 0; |
| 3607 | size_t len; |
| 3608 | spages = pages; |
| 3609 | |
| 3610 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3611 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3612 | newpage = alloc_page(GFP_KERNEL); |
| 3613 | |
| 3614 | if (newpage == NULL) |
| 3615 | goto unwind; |
| 3616 | memcpy(page_address(newpage), buf, len); |
| 3617 | buf += len; |
| 3618 | buflen -= len; |
| 3619 | *pages++ = newpage; |
| 3620 | rc++; |
| 3621 | } while (buflen != 0); |
| 3622 | |
| 3623 | return rc; |
| 3624 | |
| 3625 | unwind: |
| 3626 | for(; rc > 0; rc--) |
| 3627 | __free_page(spages[rc-1]); |
| 3628 | return -ENOMEM; |
| 3629 | } |
| 3630 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3631 | struct nfs4_cached_acl { |
| 3632 | int cached; |
| 3633 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3634 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3635 | }; |
| 3636 | |
| 3637 | 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] | 3638 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3639 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3640 | |
| 3641 | spin_lock(&inode->i_lock); |
| 3642 | kfree(nfsi->nfs4_acl); |
| 3643 | nfsi->nfs4_acl = acl; |
| 3644 | spin_unlock(&inode->i_lock); |
| 3645 | } |
| 3646 | |
| 3647 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3648 | { |
| 3649 | nfs4_set_cached_acl(inode, NULL); |
| 3650 | } |
| 3651 | |
| 3652 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3653 | { |
| 3654 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3655 | struct nfs4_cached_acl *acl; |
| 3656 | int ret = -ENOENT; |
| 3657 | |
| 3658 | spin_lock(&inode->i_lock); |
| 3659 | acl = nfsi->nfs4_acl; |
| 3660 | if (acl == NULL) |
| 3661 | goto out; |
| 3662 | if (buf == NULL) /* user is just asking for length */ |
| 3663 | goto out_len; |
| 3664 | if (acl->cached == 0) |
| 3665 | goto out; |
| 3666 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3667 | if (acl->len > buflen) |
| 3668 | goto out; |
| 3669 | memcpy(buf, acl->data, acl->len); |
| 3670 | out_len: |
| 3671 | ret = acl->len; |
| 3672 | out: |
| 3673 | spin_unlock(&inode->i_lock); |
| 3674 | return ret; |
| 3675 | } |
| 3676 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3677 | 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] | 3678 | { |
| 3679 | struct nfs4_cached_acl *acl; |
| 3680 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3681 | if (pages && acl_len <= PAGE_SIZE) { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3682 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3683 | if (acl == NULL) |
| 3684 | goto out; |
| 3685 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3686 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3687 | } else { |
| 3688 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3689 | if (acl == NULL) |
| 3690 | goto out; |
| 3691 | acl->cached = 0; |
| 3692 | } |
| 3693 | acl->len = acl_len; |
| 3694 | out: |
| 3695 | nfs4_set_cached_acl(inode, acl); |
| 3696 | } |
| 3697 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3698 | /* |
| 3699 | * The getxattr API returns the required buffer length when called with a |
| 3700 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3701 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3702 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3703 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3704 | * the cache. If not so, we throw away the page, and cache the required |
| 3705 | * length. The next getxattr call will then produce another round trip to |
| 3706 | * the server, this time with the input buf of the required size. |
| 3707 | */ |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3708 | 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] | 3709 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3710 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3711 | struct nfs_getaclargs args = { |
| 3712 | .fh = NFS_FH(inode), |
| 3713 | .acl_pages = pages, |
| 3714 | .acl_len = buflen, |
| 3715 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3716 | struct nfs_getaclres res = { |
| 3717 | .acl_len = buflen, |
| 3718 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3719 | struct rpc_message msg = { |
| 3720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3721 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3722 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3723 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3724 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3725 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3726 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3727 | /* As long as we're doing a round trip to the server anyway, |
| 3728 | * let's be prepared for a page of acl data. */ |
| 3729 | if (npages == 0) |
| 3730 | npages = 1; |
| 3731 | |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3732 | /* Add an extra page to handle the bitmap returned */ |
| 3733 | npages++; |
| 3734 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3735 | for (i = 0; i < npages; i++) { |
| 3736 | pages[i] = alloc_page(GFP_KERNEL); |
| 3737 | if (!pages[i]) |
| 3738 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3739 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3740 | |
| 3741 | /* for decoding across pages */ |
| 3742 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3743 | if (!res.acl_scratch) |
| 3744 | goto out_free; |
| 3745 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3746 | args.acl_len = npages * PAGE_SIZE; |
| 3747 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3748 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3749 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3750 | * the page we send as a guess */ |
| 3751 | if (buf == NULL) |
| 3752 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3753 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3754 | 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] | 3755 | __func__, buf, buflen, npages, args.acl_len); |
| 3756 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3757 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3758 | if (ret) |
| 3759 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3760 | |
| 3761 | acl_len = res.acl_len - res.acl_data_offset; |
| 3762 | if (acl_len > args.acl_len) |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3763 | nfs4_write_cached_acl(inode, NULL, 0, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3764 | else |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3765 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3766 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3767 | if (buf) { |
| 3768 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3769 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3770 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3771 | _copy_from_pages(buf, pages, res.acl_data_offset, |
Sachin Prabhu | 20e0fa9 | 2012-03-22 16:46:28 +0000 | [diff] [blame] | 3772 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3773 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3774 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3775 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3776 | for (i = 0; i < npages; i++) |
| 3777 | if (pages[i]) |
| 3778 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3779 | if (res.acl_scratch) |
| 3780 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3781 | return ret; |
| 3782 | } |
| 3783 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3784 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3785 | { |
| 3786 | struct nfs4_exception exception = { }; |
| 3787 | ssize_t ret; |
| 3788 | do { |
| 3789 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3790 | if (ret >= 0) |
| 3791 | break; |
| 3792 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3793 | } while (exception.retry); |
| 3794 | return ret; |
| 3795 | } |
| 3796 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3797 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3798 | { |
| 3799 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3800 | int ret; |
| 3801 | |
| 3802 | if (!nfs4_server_supports_acls(server)) |
| 3803 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3804 | ret = nfs_revalidate_inode(server, inode); |
| 3805 | if (ret < 0) |
| 3806 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3807 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3808 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3809 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3810 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3811 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3812 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3813 | return ret; |
| 3814 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3817 | 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] | 3818 | { |
| 3819 | struct nfs_server *server = NFS_SERVER(inode); |
| 3820 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3821 | struct nfs_setaclargs arg = { |
| 3822 | .fh = NFS_FH(inode), |
| 3823 | .acl_pages = pages, |
| 3824 | .acl_len = buflen, |
| 3825 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3826 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3827 | struct rpc_message msg = { |
| 3828 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3829 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3830 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3831 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3832 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3833 | |
| 3834 | if (!nfs4_server_supports_acls(server)) |
| 3835 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3836 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3837 | if (i < 0) |
| 3838 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3839 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3840 | 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] | 3841 | |
| 3842 | /* |
| 3843 | * Free each page after tx, so the only ref left is |
| 3844 | * held by the network stack |
| 3845 | */ |
| 3846 | for (; i > 0; i--) |
| 3847 | put_page(pages[i-1]); |
| 3848 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3849 | /* |
| 3850 | * Acl update can result in inode attribute update. |
| 3851 | * so mark the attribute cache invalid. |
| 3852 | */ |
| 3853 | spin_lock(&inode->i_lock); |
| 3854 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3855 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3856 | nfs_access_zap_cache(inode); |
| 3857 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3858 | return ret; |
| 3859 | } |
| 3860 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3861 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3862 | { |
| 3863 | struct nfs4_exception exception = { }; |
| 3864 | int err; |
| 3865 | do { |
| 3866 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3867 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3868 | &exception); |
| 3869 | } while (exception.retry); |
| 3870 | return err; |
| 3871 | } |
| 3872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3874 | 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] | 3875 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3876 | struct nfs_client *clp = server->nfs_client; |
| 3877 | |
| 3878 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | return 0; |
| 3880 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3881 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3882 | case -NFS4ERR_ADMIN_REVOKED: |
| 3883 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3884 | if (state == NULL) |
| 3885 | break; |
| 3886 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3887 | case -NFS4ERR_OPENMODE: |
| 3888 | if (state == NULL) |
| 3889 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3890 | nfs4_schedule_stateid_recovery(server, state); |
| 3891 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3892 | case -NFS4ERR_EXPIRED: |
| 3893 | if (state != NULL) |
| 3894 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3896 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3897 | nfs4_schedule_lease_recovery(clp); |
| 3898 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3899 | #if defined(CONFIG_NFS_V4_1) |
| 3900 | case -NFS4ERR_BADSESSION: |
| 3901 | case -NFS4ERR_BADSLOT: |
| 3902 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3903 | case -NFS4ERR_DEADSESSION: |
| 3904 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3905 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3906 | case -NFS4ERR_SEQ_MISORDERED: |
| 3907 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3908 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3909 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3910 | task->tk_status = 0; |
| 3911 | return -EAGAIN; |
| 3912 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3914 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3915 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3916 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3918 | task->tk_status = 0; |
| 3919 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3920 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | case -NFS4ERR_OLD_STATEID: |
| 3922 | task->tk_status = 0; |
| 3923 | return -EAGAIN; |
| 3924 | } |
| 3925 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3926 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3927 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3928 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3929 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3930 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3931 | task->tk_status = 0; |
| 3932 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | } |
| 3934 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3935 | static void nfs4_construct_boot_verifier(struct nfs_client *clp, |
| 3936 | nfs4_verifier *bootverf) |
| 3937 | { |
| 3938 | __be32 verf[2]; |
| 3939 | |
| 3940 | verf[0] = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3941 | verf[1] = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3942 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 3943 | } |
| 3944 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3945 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3946 | unsigned short port, struct rpc_cred *cred, |
| 3947 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | { |
| 3949 | nfs4_verifier sc_verifier; |
| 3950 | struct nfs4_setclientid setclientid = { |
| 3951 | .sc_verifier = &sc_verifier, |
| 3952 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3953 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | }; |
| 3955 | struct rpc_message msg = { |
| 3956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3957 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3958 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3959 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | int loop = 0; |
| 3962 | int status; |
| 3963 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3964 | nfs4_construct_boot_verifier(clp, &sc_verifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | |
| 3966 | for(;;) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3967 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3969 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3970 | clp->cl_ipaddr, |
| 3971 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3972 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3973 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3974 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3975 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | clp->cl_id_uniquifier); |
| 3977 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3978 | sizeof(setclientid.sc_netid), |
| 3979 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3980 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3982 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | clp->cl_ipaddr, port >> 8, port & 255); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3984 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3986 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | if (status != -NFS4ERR_CLID_INUSE) |
| 3988 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3989 | if (loop != 0) { |
| 3990 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3992 | } |
| 3993 | ++loop; |
| 3994 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | } |
| 3996 | return status; |
| 3997 | } |
| 3998 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3999 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4000 | struct nfs4_setclientid_res *arg, |
| 4001 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | { |
| 4003 | struct nfs_fsinfo fsinfo; |
| 4004 | struct rpc_message msg = { |
| 4005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4006 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4008 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | }; |
| 4010 | unsigned long now; |
| 4011 | int status; |
| 4012 | |
| 4013 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4014 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | if (status == 0) { |
| 4016 | spin_lock(&clp->cl_lock); |
| 4017 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4018 | clp->cl_last_renewal = now; |
| 4019 | spin_unlock(&clp->cl_lock); |
| 4020 | } |
| 4021 | return status; |
| 4022 | } |
| 4023 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4024 | struct nfs4_delegreturndata { |
| 4025 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4026 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4027 | struct nfs_fh fh; |
| 4028 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4029 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4030 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4031 | int rpc_status; |
| 4032 | }; |
| 4033 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4034 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4035 | { |
| 4036 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4037 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4038 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4039 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4040 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4041 | switch (task->tk_status) { |
| 4042 | case -NFS4ERR_STALE_STATEID: |
| 4043 | case -NFS4ERR_EXPIRED: |
| 4044 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4045 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4046 | break; |
| 4047 | default: |
| 4048 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4049 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4050 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4051 | return; |
| 4052 | } |
| 4053 | } |
| 4054 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | static void nfs4_delegreturn_release(void *calldata) |
| 4058 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4059 | kfree(calldata); |
| 4060 | } |
| 4061 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4062 | #if defined(CONFIG_NFS_V4_1) |
| 4063 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4064 | { |
| 4065 | struct nfs4_delegreturndata *d_data; |
| 4066 | |
| 4067 | d_data = (struct nfs4_delegreturndata *)data; |
| 4068 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4069 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4070 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4071 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4072 | return; |
| 4073 | rpc_call_start(task); |
| 4074 | } |
| 4075 | #endif /* CONFIG_NFS_V4_1 */ |
| 4076 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4077 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4078 | #if defined(CONFIG_NFS_V4_1) |
| 4079 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4080 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4081 | .rpc_call_done = nfs4_delegreturn_done, |
| 4082 | .rpc_release = nfs4_delegreturn_release, |
| 4083 | }; |
| 4084 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4085 | 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] | 4086 | { |
| 4087 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4088 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4089 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4090 | struct rpc_message msg = { |
| 4091 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4092 | .rpc_cred = cred, |
| 4093 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4094 | struct rpc_task_setup task_setup_data = { |
| 4095 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4096 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4097 | .callback_ops = &nfs4_delegreturn_ops, |
| 4098 | .flags = RPC_TASK_ASYNC, |
| 4099 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4100 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4101 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4102 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4103 | if (data == NULL) |
| 4104 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4105 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4106 | data->args.fhandle = &data->fh; |
| 4107 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4108 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4109 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4110 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4111 | data->res.fattr = &data->fattr; |
| 4112 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4113 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4114 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4115 | data->rpc_status = 0; |
| 4116 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4117 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4118 | msg.rpc_argp = &data->args; |
| 4119 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4120 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4121 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4122 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4123 | if (!issync) |
| 4124 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4125 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4126 | if (status != 0) |
| 4127 | goto out; |
| 4128 | status = data->rpc_status; |
| 4129 | if (status != 0) |
| 4130 | goto out; |
| 4131 | nfs_refresh_inode(inode, &data->fattr); |
| 4132 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4133 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4134 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4137 | 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] | 4138 | { |
| 4139 | struct nfs_server *server = NFS_SERVER(inode); |
| 4140 | struct nfs4_exception exception = { }; |
| 4141 | int err; |
| 4142 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4143 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | switch (err) { |
| 4145 | case -NFS4ERR_STALE_STATEID: |
| 4146 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | case 0: |
| 4148 | return 0; |
| 4149 | } |
| 4150 | err = nfs4_handle_exception(server, err, &exception); |
| 4151 | } while (exception.retry); |
| 4152 | return err; |
| 4153 | } |
| 4154 | |
| 4155 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4156 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4157 | |
| 4158 | /* |
| 4159 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4160 | */ |
| 4161 | static unsigned long |
| 4162 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4163 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4164 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | timeout <<= 1; |
| 4166 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4167 | return NFS4_LOCK_MAXTIMEOUT; |
| 4168 | return timeout; |
| 4169 | } |
| 4170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4172 | { |
| 4173 | struct inode *inode = state->inode; |
| 4174 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4175 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4176 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4178 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4180 | struct nfs_lockt_res res = { |
| 4181 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | }; |
| 4183 | struct rpc_message msg = { |
| 4184 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4185 | .rpc_argp = &arg, |
| 4186 | .rpc_resp = &res, |
| 4187 | .rpc_cred = state->owner->so_cred, |
| 4188 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | struct nfs4_lock_state *lsp; |
| 4190 | int status; |
| 4191 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4192 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4193 | status = nfs4_set_lock_state(state, request); |
| 4194 | if (status != 0) |
| 4195 | goto out; |
| 4196 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4197 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4198 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4199 | 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] | 4200 | switch (status) { |
| 4201 | case 0: |
| 4202 | request->fl_type = F_UNLCK; |
| 4203 | break; |
| 4204 | case -NFS4ERR_DENIED: |
| 4205 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4207 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4208 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | return status; |
| 4210 | } |
| 4211 | |
| 4212 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4213 | { |
| 4214 | struct nfs4_exception exception = { }; |
| 4215 | int err; |
| 4216 | |
| 4217 | do { |
| 4218 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4219 | _nfs4_proc_getlk(state, cmd, request), |
| 4220 | &exception); |
| 4221 | } while (exception.retry); |
| 4222 | return err; |
| 4223 | } |
| 4224 | |
| 4225 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4226 | { |
| 4227 | int res = 0; |
| 4228 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4229 | case FL_POSIX: |
| 4230 | res = posix_lock_file_wait(file, fl); |
| 4231 | break; |
| 4232 | case FL_FLOCK: |
| 4233 | res = flock_lock_file_wait(file, fl); |
| 4234 | break; |
| 4235 | default: |
| 4236 | BUG(); |
| 4237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | return res; |
| 4239 | } |
| 4240 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4241 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4242 | struct nfs_locku_args arg; |
| 4243 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4244 | struct nfs4_lock_state *lsp; |
| 4245 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4246 | struct file_lock fl; |
| 4247 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4248 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4249 | }; |
| 4250 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4251 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4252 | struct nfs_open_context *ctx, |
| 4253 | struct nfs4_lock_state *lsp, |
| 4254 | struct nfs_seqid *seqid) |
| 4255 | { |
| 4256 | struct nfs4_unlockdata *p; |
| 4257 | struct inode *inode = lsp->ls_state->inode; |
| 4258 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4259 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4260 | if (p == NULL) |
| 4261 | return NULL; |
| 4262 | p->arg.fh = NFS_FH(inode); |
| 4263 | p->arg.fl = &p->fl; |
| 4264 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4265 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4266 | p->arg.stateid = &lsp->ls_stateid; |
| 4267 | p->lsp = lsp; |
| 4268 | atomic_inc(&lsp->ls_count); |
| 4269 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4270 | p->ctx = get_nfs_open_context(ctx); |
| 4271 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4272 | p->server = NFS_SERVER(inode); |
| 4273 | return p; |
| 4274 | } |
| 4275 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4276 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4277 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4278 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4279 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4280 | nfs4_put_lock_state(calldata->lsp); |
| 4281 | put_nfs_open_context(calldata->ctx); |
| 4282 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4285 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4286 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4287 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4288 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4289 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4290 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4291 | switch (task->tk_status) { |
| 4292 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4293 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4294 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4295 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4296 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4297 | case -NFS4ERR_BAD_STATEID: |
| 4298 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4299 | case -NFS4ERR_STALE_STATEID: |
| 4300 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4301 | break; |
| 4302 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4303 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4304 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4305 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4308 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4309 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4310 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4312 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4313 | return; |
| 4314 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4315 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4316 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4317 | return; |
| 4318 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4319 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4320 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4321 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4322 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4323 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4324 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4327 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4328 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4329 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4330 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4331 | }; |
| 4332 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4333 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4334 | struct nfs_open_context *ctx, |
| 4335 | struct nfs4_lock_state *lsp, |
| 4336 | struct nfs_seqid *seqid) |
| 4337 | { |
| 4338 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4339 | struct rpc_message msg = { |
| 4340 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4341 | .rpc_cred = ctx->cred, |
| 4342 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4343 | struct rpc_task_setup task_setup_data = { |
| 4344 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4345 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4346 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4347 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4348 | .flags = RPC_TASK_ASYNC, |
| 4349 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4350 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4351 | /* Ensure this is an unlock - when canceling a lock, the |
| 4352 | * canceled lock is passed in, and it won't be an unlock. |
| 4353 | */ |
| 4354 | fl->fl_type = F_UNLCK; |
| 4355 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4356 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4357 | if (data == NULL) { |
| 4358 | nfs_free_seqid(seqid); |
| 4359 | return ERR_PTR(-ENOMEM); |
| 4360 | } |
| 4361 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4362 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4363 | msg.rpc_argp = &data->arg; |
| 4364 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4365 | task_setup_data.callback_data = data; |
| 4366 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4367 | } |
| 4368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4370 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4371 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4372 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4373 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4374 | struct rpc_task *task; |
| 4375 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4376 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4378 | status = nfs4_set_lock_state(state, request); |
| 4379 | /* Unlock _before_ we do the RPC call */ |
| 4380 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4381 | down_read(&nfsi->rwsem); |
| 4382 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4383 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4384 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4385 | } |
| 4386 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4387 | if (status != 0) |
| 4388 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4389 | /* Is this a delegated lock? */ |
| 4390 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4391 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4392 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4393 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4394 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4395 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4396 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4397 | 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] | 4398 | status = PTR_ERR(task); |
| 4399 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4400 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4401 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4402 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4403 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4404 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4405 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4408 | struct nfs4_lockdata { |
| 4409 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4410 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4411 | struct nfs4_lock_state *lsp; |
| 4412 | struct nfs_open_context *ctx; |
| 4413 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4414 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4415 | int rpc_status; |
| 4416 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4417 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4418 | }; |
| 4419 | |
| 4420 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4421 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4422 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4423 | { |
| 4424 | struct nfs4_lockdata *p; |
| 4425 | struct inode *inode = lsp->ls_state->inode; |
| 4426 | struct nfs_server *server = NFS_SERVER(inode); |
| 4427 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4428 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4429 | if (p == NULL) |
| 4430 | return NULL; |
| 4431 | |
| 4432 | p->arg.fh = NFS_FH(inode); |
| 4433 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4434 | 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] | 4435 | if (p->arg.open_seqid == NULL) |
| 4436 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4437 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4438 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4439 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4440 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4441 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4442 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4443 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4444 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4445 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4446 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4447 | atomic_inc(&lsp->ls_count); |
| 4448 | p->ctx = get_nfs_open_context(ctx); |
| 4449 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4450 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4451 | out_free_seqid: |
| 4452 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4453 | out_free: |
| 4454 | kfree(p); |
| 4455 | return NULL; |
| 4456 | } |
| 4457 | |
| 4458 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4459 | { |
| 4460 | struct nfs4_lockdata *data = calldata; |
| 4461 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4463 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4464 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4465 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4466 | /* Do we need to do an open_to_lock_owner? */ |
| 4467 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4468 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4469 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4470 | data->arg.open_stateid = &state->stateid; |
| 4471 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4472 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4473 | } else |
| 4474 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4475 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4476 | if (nfs4_setup_sequence(data->server, |
| 4477 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4478 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4479 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4480 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4481 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4482 | } |
| 4483 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4484 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4485 | { |
| 4486 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4487 | nfs4_lock_prepare(task, calldata); |
| 4488 | } |
| 4489 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4490 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4491 | { |
| 4492 | struct nfs4_lockdata *data = calldata; |
| 4493 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4494 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4495 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4496 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4497 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4498 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4499 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4500 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4501 | if (data->rpc_status == 0) |
| 4502 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4503 | else |
| 4504 | goto out; |
| 4505 | } |
| 4506 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4507 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4508 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4509 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4510 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4511 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4512 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | static void nfs4_lock_release(void *calldata) |
| 4516 | { |
| 4517 | struct nfs4_lockdata *data = calldata; |
| 4518 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4519 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4520 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4521 | if (data->cancelled != 0) { |
| 4522 | struct rpc_task *task; |
| 4523 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4524 | data->arg.lock_seqid); |
| 4525 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4526 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4527 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4528 | } else |
| 4529 | nfs_free_seqid(data->arg.lock_seqid); |
| 4530 | nfs4_put_lock_state(data->lsp); |
| 4531 | put_nfs_open_context(data->ctx); |
| 4532 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4533 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4537 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4538 | .rpc_call_done = nfs4_lock_done, |
| 4539 | .rpc_release = nfs4_lock_release, |
| 4540 | }; |
| 4541 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4542 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4543 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4544 | .rpc_call_done = nfs4_lock_done, |
| 4545 | .rpc_release = nfs4_lock_release, |
| 4546 | }; |
| 4547 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4548 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4549 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4550 | switch (error) { |
| 4551 | case -NFS4ERR_ADMIN_REVOKED: |
| 4552 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4553 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4554 | if (new_lock_owner != 0 || |
| 4555 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4556 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4557 | break; |
| 4558 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4559 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4560 | case -NFS4ERR_EXPIRED: |
| 4561 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4562 | }; |
| 4563 | } |
| 4564 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4565 | 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] | 4566 | { |
| 4567 | struct nfs4_lockdata *data; |
| 4568 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4569 | struct rpc_message msg = { |
| 4570 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4571 | .rpc_cred = state->owner->so_cred, |
| 4572 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4573 | struct rpc_task_setup task_setup_data = { |
| 4574 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4575 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4576 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4577 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4578 | .flags = RPC_TASK_ASYNC, |
| 4579 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4580 | int ret; |
| 4581 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4582 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4583 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4584 | fl->fl_u.nfs4_fl.owner, |
| 4585 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4586 | if (data == NULL) |
| 4587 | return -ENOMEM; |
| 4588 | if (IS_SETLKW(cmd)) |
| 4589 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4590 | if (recovery_type > NFS_LOCK_NEW) { |
| 4591 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4592 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4593 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4594 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4595 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4596 | msg.rpc_argp = &data->arg; |
| 4597 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4598 | task_setup_data.callback_data = data; |
| 4599 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4600 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4601 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4602 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4603 | if (ret == 0) { |
| 4604 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4605 | if (ret) |
| 4606 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4607 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4608 | } else |
| 4609 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4610 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4611 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4612 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4616 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4617 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4618 | struct nfs4_exception exception = { |
| 4619 | .inode = state->inode, |
| 4620 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4621 | int err; |
| 4622 | |
| 4623 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4624 | /* Cache the lock if possible... */ |
| 4625 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4626 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4627 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4628 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4629 | break; |
| 4630 | nfs4_handle_exception(server, err, &exception); |
| 4631 | } while (exception.retry); |
| 4632 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4636 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4637 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4638 | struct nfs4_exception exception = { |
| 4639 | .inode = state->inode, |
| 4640 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4641 | int err; |
| 4642 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4643 | err = nfs4_set_lock_state(state, request); |
| 4644 | if (err != 0) |
| 4645 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4646 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4647 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4648 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4649 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4650 | switch (err) { |
| 4651 | default: |
| 4652 | goto out; |
| 4653 | case -NFS4ERR_GRACE: |
| 4654 | case -NFS4ERR_DELAY: |
| 4655 | nfs4_handle_exception(server, err, &exception); |
| 4656 | err = 0; |
| 4657 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4658 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4659 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4660 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4663 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4664 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4665 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4666 | int status, ret = NFS_OK; |
| 4667 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4668 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4669 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4670 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4671 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4672 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4673 | if (status != NFS_OK) { |
| 4674 | nfs41_free_stateid(server, &lsp->ls_stateid); |
| 4675 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4676 | ret = status; |
| 4677 | } |
| 4678 | } |
| 4679 | }; |
| 4680 | |
| 4681 | return ret; |
| 4682 | } |
| 4683 | |
| 4684 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4685 | { |
| 4686 | int status = NFS_OK; |
| 4687 | |
| 4688 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4689 | status = nfs41_check_expired_locks(state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4690 | if (status == NFS_OK) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4691 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4692 | return nfs4_lock_expired(state, request); |
| 4693 | } |
| 4694 | #endif |
| 4695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4697 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4698 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4699 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4700 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4702 | if ((fl_flags & FL_POSIX) && |
| 4703 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4704 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4705 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4706 | status = nfs4_set_lock_state(state, request); |
| 4707 | if (status != 0) |
| 4708 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4709 | request->fl_flags |= FL_ACCESS; |
| 4710 | status = do_vfs_lock(request->fl_file, request); |
| 4711 | if (status < 0) |
| 4712 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4713 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4714 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4715 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4716 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4717 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4718 | status = do_vfs_lock(request->fl_file, request); |
| 4719 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4720 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4721 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4722 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4723 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4724 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4725 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4726 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4727 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4728 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4729 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4730 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4731 | out: |
| 4732 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | return status; |
| 4734 | } |
| 4735 | |
| 4736 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4737 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4738 | struct nfs4_exception exception = { |
| 4739 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4740 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4741 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | int err; |
| 4743 | |
| 4744 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4745 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4746 | if (err == -NFS4ERR_DENIED) |
| 4747 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4749 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | } while (exception.retry); |
| 4751 | return err; |
| 4752 | } |
| 4753 | |
| 4754 | static int |
| 4755 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4756 | { |
| 4757 | struct nfs_open_context *ctx; |
| 4758 | struct nfs4_state *state; |
| 4759 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4760 | int status; |
| 4761 | |
| 4762 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4763 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | state = ctx->state; |
| 4765 | |
| 4766 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4767 | return -EINVAL; |
| 4768 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4769 | if (IS_GETLK(cmd)) { |
| 4770 | if (state != NULL) |
| 4771 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4772 | return 0; |
| 4773 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | |
| 4775 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4776 | return -EINVAL; |
| 4777 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4778 | if (request->fl_type == F_UNLCK) { |
| 4779 | if (state != NULL) |
| 4780 | return nfs4_proc_unlck(state, cmd, request); |
| 4781 | return 0; |
| 4782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4784 | if (state == NULL) |
| 4785 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4786 | /* |
| 4787 | * Don't rely on the VFS having checked the file open mode, |
| 4788 | * since it won't do this for flock() locks. |
| 4789 | */ |
| 4790 | switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) { |
| 4791 | case F_RDLCK: |
| 4792 | if (!(filp->f_mode & FMODE_READ)) |
| 4793 | return -EBADF; |
| 4794 | break; |
| 4795 | case F_WRLCK: |
| 4796 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4797 | return -EBADF; |
| 4798 | } |
| 4799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | do { |
| 4801 | status = nfs4_proc_setlk(state, cmd, request); |
| 4802 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4803 | break; |
| 4804 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4805 | status = -ERESTARTSYS; |
| 4806 | if (signalled()) |
| 4807 | break; |
| 4808 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | return status; |
| 4810 | } |
| 4811 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4812 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4813 | { |
| 4814 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4815 | struct nfs4_exception exception = { }; |
| 4816 | int err; |
| 4817 | |
| 4818 | err = nfs4_set_lock_state(state, fl); |
| 4819 | if (err != 0) |
| 4820 | goto out; |
| 4821 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4822 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4823 | switch (err) { |
| 4824 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4825 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4826 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4827 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4828 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4829 | goto out; |
| 4830 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4831 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4832 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4833 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4834 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4835 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4836 | case -NFS4ERR_BADSESSION: |
| 4837 | case -NFS4ERR_BADSLOT: |
| 4838 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4839 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4840 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4841 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4842 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4843 | case -ERESTARTSYS: |
| 4844 | /* |
| 4845 | * The show must go on: exit, but mark the |
| 4846 | * stateid as needing recovery. |
| 4847 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4848 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4849 | case -NFS4ERR_ADMIN_REVOKED: |
| 4850 | case -NFS4ERR_BAD_STATEID: |
| 4851 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4852 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4853 | err = 0; |
| 4854 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4855 | case -EKEYEXPIRED: |
| 4856 | /* |
| 4857 | * User RPCSEC_GSS context has expired. |
| 4858 | * We cannot recover this stateid now, so |
| 4859 | * skip it and allow recovery thread to |
| 4860 | * proceed. |
| 4861 | */ |
| 4862 | err = 0; |
| 4863 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4864 | case -ENOMEM: |
| 4865 | case -NFS4ERR_DENIED: |
| 4866 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4867 | err = 0; |
| 4868 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4869 | case -NFS4ERR_DELAY: |
| 4870 | break; |
| 4871 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4872 | err = nfs4_handle_exception(server, err, &exception); |
| 4873 | } while (exception.retry); |
| 4874 | out: |
| 4875 | return err; |
| 4876 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4877 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4878 | struct nfs_release_lockowner_data { |
| 4879 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4880 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4881 | struct nfs_release_lockowner_args args; |
| 4882 | }; |
| 4883 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4884 | static void nfs4_release_lockowner_release(void *calldata) |
| 4885 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4886 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4887 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4888 | kfree(calldata); |
| 4889 | } |
| 4890 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4891 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4892 | .rpc_release = nfs4_release_lockowner_release, |
| 4893 | }; |
| 4894 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4895 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4896 | { |
| 4897 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4898 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4899 | struct rpc_message msg = { |
| 4900 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4901 | }; |
| 4902 | |
| 4903 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4904 | return -EINVAL; |
| 4905 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 4906 | if (!data) |
| 4907 | return -ENOMEM; |
| 4908 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4909 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4910 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4911 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 4912 | data->args.lock_owner.s_dev = server->s_dev; |
| 4913 | msg.rpc_argp = &data->args; |
| 4914 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 4915 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4916 | } |
| 4917 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4918 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4919 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4920 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4921 | const void *buf, size_t buflen, |
| 4922 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4923 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4924 | if (strcmp(key, "") != 0) |
| 4925 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4926 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4927 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4928 | } |
| 4929 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4930 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4931 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4932 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4933 | if (strcmp(key, "") != 0) |
| 4934 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4935 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4936 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4939 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4940 | size_t list_len, const char *name, |
| 4941 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4942 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4943 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4944 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4945 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4946 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4947 | |
| 4948 | if (list && len <= list_len) |
| 4949 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4950 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4953 | /* |
| 4954 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4955 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4956 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4957 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4958 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4959 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4960 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4961 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4962 | return; |
| 4963 | |
| 4964 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4965 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4966 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4967 | fattr->nlink = 2; |
| 4968 | } |
| 4969 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4970 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 4971 | const struct qstr *name, |
| 4972 | struct nfs4_fs_locations *fs_locations, |
| 4973 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4974 | { |
| 4975 | struct nfs_server *server = NFS_SERVER(dir); |
| 4976 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4977 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4978 | }; |
| 4979 | struct nfs4_fs_locations_arg args = { |
| 4980 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4981 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4982 | .page = page, |
| 4983 | .bitmask = bitmask, |
| 4984 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4985 | struct nfs4_fs_locations_res res = { |
| 4986 | .fs_locations = fs_locations, |
| 4987 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4988 | struct rpc_message msg = { |
| 4989 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4990 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4991 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4992 | }; |
| 4993 | int status; |
| 4994 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4995 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4996 | |
| 4997 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4998 | * is not supported */ |
| 4999 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5000 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5001 | else |
| 5002 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5003 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5004 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5005 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5006 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5007 | 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] | 5008 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5009 | return status; |
| 5010 | } |
| 5011 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5012 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5013 | const struct qstr *name, |
| 5014 | struct nfs4_fs_locations *fs_locations, |
| 5015 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5016 | { |
| 5017 | struct nfs4_exception exception = { }; |
| 5018 | int err; |
| 5019 | do { |
| 5020 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5021 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5022 | &exception); |
| 5023 | } while (exception.retry); |
| 5024 | return err; |
| 5025 | } |
| 5026 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5027 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5028 | { |
| 5029 | int status; |
| 5030 | struct nfs4_secinfo_arg args = { |
| 5031 | .dir_fh = NFS_FH(dir), |
| 5032 | .name = name, |
| 5033 | }; |
| 5034 | struct nfs4_secinfo_res res = { |
| 5035 | .flavors = flavors, |
| 5036 | }; |
| 5037 | struct rpc_message msg = { |
| 5038 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5039 | .rpc_argp = &args, |
| 5040 | .rpc_resp = &res, |
| 5041 | }; |
| 5042 | |
| 5043 | dprintk("NFS call secinfo %s\n", name->name); |
| 5044 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5045 | dprintk("NFS reply secinfo: %d\n", status); |
| 5046 | return status; |
| 5047 | } |
| 5048 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5049 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5050 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5051 | { |
| 5052 | struct nfs4_exception exception = { }; |
| 5053 | int err; |
| 5054 | do { |
| 5055 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5056 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5057 | &exception); |
| 5058 | } while (exception.retry); |
| 5059 | return err; |
| 5060 | } |
| 5061 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5062 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5063 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5064 | * Check the exchange flags returned by the server for invalid flags, having |
| 5065 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5066 | * DS flags set. |
| 5067 | */ |
| 5068 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5069 | { |
| 5070 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5071 | goto out_inval; |
| 5072 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5073 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5074 | goto out_inval; |
| 5075 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5076 | goto out_inval; |
| 5077 | return NFS_OK; |
| 5078 | out_inval: |
| 5079 | return -NFS4ERR_INVAL; |
| 5080 | } |
| 5081 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5082 | static bool |
| 5083 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 5084 | { |
| 5085 | if (a->server_scope_sz == b->server_scope_sz && |
| 5086 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5087 | return true; |
| 5088 | |
| 5089 | return false; |
| 5090 | } |
| 5091 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5092 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5093 | * nfs4_proc_exchange_id() |
| 5094 | * |
| 5095 | * Since the clientid has expired, all compounds using sessions |
| 5096 | * associated with the stale clientid will be returning |
| 5097 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5098 | * be in some phase of session reset. |
| 5099 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5100 | 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] | 5101 | { |
| 5102 | nfs4_verifier verifier; |
| 5103 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5104 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5105 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5106 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5107 | }; |
| 5108 | struct nfs41_exchange_id_res res = { |
| 5109 | .client = clp, |
| 5110 | }; |
| 5111 | int status; |
| 5112 | struct rpc_message msg = { |
| 5113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5114 | .rpc_argp = &args, |
| 5115 | .rpc_resp = &res, |
| 5116 | .rpc_cred = cred, |
| 5117 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5118 | |
| 5119 | dprintk("--> %s\n", __func__); |
| 5120 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5121 | |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5122 | nfs4_construct_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5123 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5124 | args.id_len = scnprintf(args.id, sizeof(args.id), |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5125 | "%s/%s/%u", |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5126 | clp->cl_ipaddr, |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5127 | clp->cl_rpcclient->cl_nodename, |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5128 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5129 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5130 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5131 | if (unlikely(!res.server_scope)) { |
| 5132 | status = -ENOMEM; |
| 5133 | goto out; |
| 5134 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5135 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5136 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_KERNEL); |
| 5137 | if (unlikely(!res.impl_id)) { |
| 5138 | status = -ENOMEM; |
| 5139 | goto out_server_scope; |
| 5140 | } |
| 5141 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5142 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5143 | if (!status) |
| 5144 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5145 | |
| 5146 | if (!status) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5147 | /* use the most recent implementation id */ |
| 5148 | kfree(clp->impl_id); |
| 5149 | clp->impl_id = res.impl_id; |
| 5150 | } else |
| 5151 | kfree(res.impl_id); |
| 5152 | |
| 5153 | if (!status) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5154 | if (clp->server_scope && |
| 5155 | !nfs41_same_server_scope(clp->server_scope, |
| 5156 | res.server_scope)) { |
| 5157 | dprintk("%s: server_scope mismatch detected\n", |
| 5158 | __func__); |
| 5159 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 5160 | kfree(clp->server_scope); |
| 5161 | clp->server_scope = NULL; |
| 5162 | } |
| 5163 | |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5164 | if (!clp->server_scope) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5165 | clp->server_scope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5166 | goto out; |
| 5167 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5168 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5169 | |
| 5170 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5171 | kfree(res.server_scope); |
| 5172 | out: |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5173 | if (clp->impl_id) |
| 5174 | dprintk("%s: Server Implementation ID: " |
| 5175 | "domain: %s, name: %s, date: %llu,%u\n", |
| 5176 | __func__, clp->impl_id->domain, clp->impl_id->name, |
| 5177 | clp->impl_id->date.seconds, |
| 5178 | clp->impl_id->date.nseconds); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5179 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5180 | return status; |
| 5181 | } |
| 5182 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5183 | struct nfs4_get_lease_time_data { |
| 5184 | struct nfs4_get_lease_time_args *args; |
| 5185 | struct nfs4_get_lease_time_res *res; |
| 5186 | struct nfs_client *clp; |
| 5187 | }; |
| 5188 | |
| 5189 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5190 | void *calldata) |
| 5191 | { |
| 5192 | int ret; |
| 5193 | struct nfs4_get_lease_time_data *data = |
| 5194 | (struct nfs4_get_lease_time_data *)calldata; |
| 5195 | |
| 5196 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5197 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5198 | /* just setup sequence, do not trigger session recovery |
| 5199 | since we're invoked within one */ |
| 5200 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5201 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5202 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5203 | |
| 5204 | BUG_ON(ret == -EAGAIN); |
| 5205 | rpc_call_start(task); |
| 5206 | dprintk("<-- %s\n", __func__); |
| 5207 | } |
| 5208 | |
| 5209 | /* |
| 5210 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5211 | * from sequence operation or clientid errors. |
| 5212 | */ |
| 5213 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5214 | { |
| 5215 | struct nfs4_get_lease_time_data *data = |
| 5216 | (struct nfs4_get_lease_time_data *)calldata; |
| 5217 | |
| 5218 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5219 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5220 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5221 | switch (task->tk_status) { |
| 5222 | case -NFS4ERR_DELAY: |
| 5223 | case -NFS4ERR_GRACE: |
| 5224 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5225 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5226 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5227 | /* fall through */ |
| 5228 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5229 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5230 | return; |
| 5231 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5232 | dprintk("<-- %s\n", __func__); |
| 5233 | } |
| 5234 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5235 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5236 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5237 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5238 | }; |
| 5239 | |
| 5240 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5241 | { |
| 5242 | struct rpc_task *task; |
| 5243 | struct nfs4_get_lease_time_args args; |
| 5244 | struct nfs4_get_lease_time_res res = { |
| 5245 | .lr_fsinfo = fsinfo, |
| 5246 | }; |
| 5247 | struct nfs4_get_lease_time_data data = { |
| 5248 | .args = &args, |
| 5249 | .res = &res, |
| 5250 | .clp = clp, |
| 5251 | }; |
| 5252 | struct rpc_message msg = { |
| 5253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5254 | .rpc_argp = &args, |
| 5255 | .rpc_resp = &res, |
| 5256 | }; |
| 5257 | struct rpc_task_setup task_setup = { |
| 5258 | .rpc_client = clp->cl_rpcclient, |
| 5259 | .rpc_message = &msg, |
| 5260 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5261 | .callback_data = &data, |
| 5262 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5263 | }; |
| 5264 | int status; |
| 5265 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5266 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5267 | dprintk("--> %s\n", __func__); |
| 5268 | task = rpc_run_task(&task_setup); |
| 5269 | |
| 5270 | if (IS_ERR(task)) |
| 5271 | status = PTR_ERR(task); |
| 5272 | else { |
| 5273 | status = task->tk_status; |
| 5274 | rpc_put_task(task); |
| 5275 | } |
| 5276 | dprintk("<-- %s return %d\n", __func__, status); |
| 5277 | |
| 5278 | return status; |
| 5279 | } |
| 5280 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5281 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5282 | { |
| 5283 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5284 | } |
| 5285 | |
| 5286 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5287 | struct nfs4_slot *new, |
| 5288 | u32 max_slots, |
| 5289 | u32 ivalue) |
| 5290 | { |
| 5291 | struct nfs4_slot *old = NULL; |
| 5292 | u32 i; |
| 5293 | |
| 5294 | spin_lock(&tbl->slot_tbl_lock); |
| 5295 | if (new) { |
| 5296 | old = tbl->slots; |
| 5297 | tbl->slots = new; |
| 5298 | tbl->max_slots = max_slots; |
| 5299 | } |
| 5300 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5301 | for (i = 0; i < tbl->max_slots; i++) |
| 5302 | tbl->slots[i].seq_nr = ivalue; |
| 5303 | spin_unlock(&tbl->slot_tbl_lock); |
| 5304 | kfree(old); |
| 5305 | } |
| 5306 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5307 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5308 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5309 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5310 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5311 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5312 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5313 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5314 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5315 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5316 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5317 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5318 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5319 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5320 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5321 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5322 | if (!new) |
| 5323 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5324 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5325 | ret = 0; |
| 5326 | |
| 5327 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5328 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5329 | tbl, tbl->slots, tbl->max_slots); |
| 5330 | out: |
| 5331 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5332 | return ret; |
| 5333 | } |
| 5334 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5335 | /* Destroy the slot table */ |
| 5336 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5337 | { |
| 5338 | if (session->fc_slot_table.slots != NULL) { |
| 5339 | kfree(session->fc_slot_table.slots); |
| 5340 | session->fc_slot_table.slots = NULL; |
| 5341 | } |
| 5342 | if (session->bc_slot_table.slots != NULL) { |
| 5343 | kfree(session->bc_slot_table.slots); |
| 5344 | session->bc_slot_table.slots = NULL; |
| 5345 | } |
| 5346 | return; |
| 5347 | } |
| 5348 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5349 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5350 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5351 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5352 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5353 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5354 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5355 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5356 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5357 | dprintk("--> %s\n", __func__); |
| 5358 | /* Fore channel */ |
| 5359 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5360 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5361 | if (status) /* -ENOMEM */ |
| 5362 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5363 | /* Back channel */ |
| 5364 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5365 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5366 | if (status && tbl->slots == NULL) |
| 5367 | /* Fore and back channel share a connection so get |
| 5368 | * both slot tables or neither */ |
| 5369 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5370 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5374 | { |
| 5375 | struct nfs4_session *session; |
| 5376 | struct nfs4_slot_table *tbl; |
| 5377 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5378 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5379 | if (!session) |
| 5380 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5381 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5382 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5383 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5384 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5385 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5386 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5387 | |
| 5388 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5389 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5390 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5391 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5392 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5393 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5394 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5395 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5396 | session->clp = clp; |
| 5397 | return session; |
| 5398 | } |
| 5399 | |
| 5400 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5401 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5402 | struct rpc_xprt *xprt; |
| 5403 | |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5404 | nfs4_proc_destroy_session(session); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5405 | |
| 5406 | rcu_read_lock(); |
| 5407 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5408 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5409 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5410 | __func__, xprt); |
| 5411 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5412 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5413 | kfree(session); |
| 5414 | } |
| 5415 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5416 | /* |
| 5417 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5418 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5419 | * use them. |
| 5420 | * |
| 5421 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5422 | * always set csa_cachethis to FALSE because the current implementation |
| 5423 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5424 | */ |
| 5425 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5426 | { |
| 5427 | struct nfs4_session *session = args->client->cl_session; |
| 5428 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5429 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5430 | |
| 5431 | if (mxrqst_sz == 0) |
| 5432 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5433 | if (mxresp_sz == 0) |
| 5434 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5435 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5436 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5437 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5438 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5439 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5440 | |
| 5441 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5442 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5443 | __func__, |
| 5444 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5445 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5446 | |
| 5447 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5448 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5449 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5450 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5451 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5452 | args->bc_attrs.max_reqs = 1; |
| 5453 | |
| 5454 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5455 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5456 | __func__, |
| 5457 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5458 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5459 | args->bc_attrs.max_reqs); |
| 5460 | } |
| 5461 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5462 | 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] | 5463 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5464 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5465 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5466 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5467 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5468 | return -EINVAL; |
| 5469 | /* |
| 5470 | * Our requested max_ops is the minimum we need; we're not |
| 5471 | * prepared to break up compounds into smaller pieces than that. |
| 5472 | * So, no point even trying to continue if the server won't |
| 5473 | * cooperate: |
| 5474 | */ |
| 5475 | if (rcvd->max_ops < sent->max_ops) |
| 5476 | return -EINVAL; |
| 5477 | if (rcvd->max_reqs == 0) |
| 5478 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5479 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5480 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5481 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5482 | } |
| 5483 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5484 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5485 | { |
| 5486 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5487 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
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 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5490 | return -EINVAL; |
| 5491 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5492 | return -EINVAL; |
| 5493 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5494 | return -EINVAL; |
| 5495 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5496 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5497 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5498 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5499 | return -EINVAL; |
| 5500 | return 0; |
| 5501 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5502 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5503 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5504 | struct nfs4_session *session) |
| 5505 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5506 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5507 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5508 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5509 | if (ret) |
| 5510 | return ret; |
| 5511 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5512 | } |
| 5513 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5514 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5515 | { |
| 5516 | struct nfs4_session *session = clp->cl_session; |
| 5517 | struct nfs41_create_session_args args = { |
| 5518 | .client = clp, |
| 5519 | .cb_program = NFS4_CALLBACK, |
| 5520 | }; |
| 5521 | struct nfs41_create_session_res res = { |
| 5522 | .client = clp, |
| 5523 | }; |
| 5524 | struct rpc_message msg = { |
| 5525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5526 | .rpc_argp = &args, |
| 5527 | .rpc_resp = &res, |
| 5528 | }; |
| 5529 | int status; |
| 5530 | |
| 5531 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5532 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5533 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5534 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5535 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5536 | if (!status) |
| 5537 | /* Verify the session's negotiated channel_attrs values */ |
| 5538 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5539 | if (!status) { |
| 5540 | /* Increment the clientid slot sequence id */ |
| 5541 | clp->cl_seqid++; |
| 5542 | } |
| 5543 | |
| 5544 | return status; |
| 5545 | } |
| 5546 | |
| 5547 | /* |
| 5548 | * Issues a CREATE_SESSION operation to the server. |
| 5549 | * It is the responsibility of the caller to verify the session is |
| 5550 | * expired before calling this routine. |
| 5551 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5552 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5553 | { |
| 5554 | int status; |
| 5555 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5556 | struct nfs4_session *session = clp->cl_session; |
| 5557 | |
| 5558 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5559 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5560 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5561 | if (status) |
| 5562 | goto out; |
| 5563 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5564 | /* Init or reset the session slot tables */ |
| 5565 | status = nfs4_setup_session_slot_tables(session); |
| 5566 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5567 | if (status) |
| 5568 | goto out; |
| 5569 | |
| 5570 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5571 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5572 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5573 | out: |
| 5574 | dprintk("<-- %s\n", __func__); |
| 5575 | return status; |
| 5576 | } |
| 5577 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5578 | /* |
| 5579 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5580 | * The caller must serialize access to this routine. |
| 5581 | */ |
| 5582 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5583 | { |
| 5584 | int status = 0; |
| 5585 | struct rpc_message msg; |
| 5586 | |
| 5587 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5588 | |
| 5589 | /* session is still being setup */ |
| 5590 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5591 | return status; |
| 5592 | |
| 5593 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5594 | msg.rpc_argp = session; |
| 5595 | msg.rpc_resp = NULL; |
| 5596 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5597 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5598 | |
| 5599 | if (status) |
| 5600 | printk(KERN_WARNING |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 5601 | "NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5602 | "Session has been destroyed regardless...\n", status); |
| 5603 | |
| 5604 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5605 | return status; |
| 5606 | } |
| 5607 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5608 | int nfs4_init_session(struct nfs_server *server) |
| 5609 | { |
| 5610 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5611 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5612 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5613 | int ret; |
| 5614 | |
| 5615 | if (!nfs4_has_session(clp)) |
| 5616 | return 0; |
| 5617 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5618 | session = clp->cl_session; |
| 5619 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5620 | return 0; |
| 5621 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5622 | rsize = server->rsize; |
| 5623 | if (rsize == 0) |
| 5624 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5625 | wsize = server->wsize; |
| 5626 | if (wsize == 0) |
| 5627 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5628 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5629 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5630 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5631 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5632 | ret = nfs4_recover_expired_lease(server); |
| 5633 | if (!ret) |
| 5634 | ret = nfs4_check_client_ready(clp); |
| 5635 | return ret; |
| 5636 | } |
| 5637 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5638 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5639 | { |
| 5640 | struct nfs4_session *session = clp->cl_session; |
| 5641 | int ret; |
| 5642 | |
| 5643 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5644 | return 0; |
| 5645 | |
| 5646 | ret = nfs4_client_recover_expired_lease(clp); |
| 5647 | if (!ret) |
| 5648 | /* Test for the DS role */ |
| 5649 | if (!is_ds_client(clp)) |
| 5650 | ret = -ENODEV; |
| 5651 | if (!ret) |
| 5652 | ret = nfs4_check_client_ready(clp); |
| 5653 | return ret; |
| 5654 | |
| 5655 | } |
| 5656 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5657 | |
| 5658 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5659 | /* |
| 5660 | * Renew the cl_session lease. |
| 5661 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5662 | struct nfs4_sequence_data { |
| 5663 | struct nfs_client *clp; |
| 5664 | struct nfs4_sequence_args args; |
| 5665 | struct nfs4_sequence_res res; |
| 5666 | }; |
| 5667 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5668 | static void nfs41_sequence_release(void *data) |
| 5669 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5670 | struct nfs4_sequence_data *calldata = data; |
| 5671 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5672 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5673 | if (atomic_read(&clp->cl_count) > 1) |
| 5674 | nfs4_schedule_state_renewal(clp); |
| 5675 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5676 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5677 | } |
| 5678 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5679 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5680 | { |
| 5681 | switch(task->tk_status) { |
| 5682 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5683 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5684 | return -EAGAIN; |
| 5685 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5686 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5687 | } |
| 5688 | return 0; |
| 5689 | } |
| 5690 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5691 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5692 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5693 | struct nfs4_sequence_data *calldata = data; |
| 5694 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5695 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5696 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5697 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5698 | |
| 5699 | if (task->tk_status < 0) { |
| 5700 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5701 | if (atomic_read(&clp->cl_count) == 1) |
| 5702 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5703 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5704 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5705 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5706 | return; |
| 5707 | } |
| 5708 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5709 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5710 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5711 | dprintk("<-- %s\n", __func__); |
| 5712 | } |
| 5713 | |
| 5714 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5715 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5716 | struct nfs4_sequence_data *calldata = data; |
| 5717 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5718 | struct nfs4_sequence_args *args; |
| 5719 | struct nfs4_sequence_res *res; |
| 5720 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5721 | args = task->tk_msg.rpc_argp; |
| 5722 | res = task->tk_msg.rpc_resp; |
| 5723 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5724 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5725 | return; |
| 5726 | rpc_call_start(task); |
| 5727 | } |
| 5728 | |
| 5729 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5730 | .rpc_call_done = nfs41_sequence_call_done, |
| 5731 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5732 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5733 | }; |
| 5734 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5735 | 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] | 5736 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5737 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5738 | struct rpc_message msg = { |
| 5739 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5740 | .rpc_cred = cred, |
| 5741 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5742 | struct rpc_task_setup task_setup_data = { |
| 5743 | .rpc_client = clp->cl_rpcclient, |
| 5744 | .rpc_message = &msg, |
| 5745 | .callback_ops = &nfs41_sequence_ops, |
| 5746 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5747 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5748 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5749 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5750 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5751 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5752 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5753 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5754 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5755 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5756 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5757 | msg.rpc_argp = &calldata->args; |
| 5758 | msg.rpc_resp = &calldata->res; |
| 5759 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5760 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5761 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5762 | return rpc_run_task(&task_setup_data); |
| 5763 | } |
| 5764 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5765 | 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] | 5766 | { |
| 5767 | struct rpc_task *task; |
| 5768 | int ret = 0; |
| 5769 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5770 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5771 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5772 | task = _nfs41_proc_sequence(clp, cred); |
| 5773 | if (IS_ERR(task)) |
| 5774 | ret = PTR_ERR(task); |
| 5775 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5776 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5777 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5778 | return ret; |
| 5779 | } |
| 5780 | |
| 5781 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5782 | { |
| 5783 | struct rpc_task *task; |
| 5784 | int ret; |
| 5785 | |
| 5786 | task = _nfs41_proc_sequence(clp, cred); |
| 5787 | if (IS_ERR(task)) { |
| 5788 | ret = PTR_ERR(task); |
| 5789 | goto out; |
| 5790 | } |
| 5791 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5792 | if (!ret) { |
| 5793 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5794 | |
| 5795 | if (task->tk_status == 0) |
| 5796 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5797 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5798 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5799 | rpc_put_task(task); |
| 5800 | out: |
| 5801 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5802 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5803 | } |
| 5804 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5805 | struct nfs4_reclaim_complete_data { |
| 5806 | struct nfs_client *clp; |
| 5807 | struct nfs41_reclaim_complete_args arg; |
| 5808 | struct nfs41_reclaim_complete_res res; |
| 5809 | }; |
| 5810 | |
| 5811 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5812 | { |
| 5813 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5814 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5815 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5816 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5817 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5818 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5819 | return; |
| 5820 | |
| 5821 | rpc_call_start(task); |
| 5822 | } |
| 5823 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5824 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5825 | { |
| 5826 | switch(task->tk_status) { |
| 5827 | case 0: |
| 5828 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5829 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5830 | break; |
| 5831 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5832 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5833 | /* fall through */ |
| 5834 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5835 | return -EAGAIN; |
| 5836 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5837 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5838 | } |
| 5839 | return 0; |
| 5840 | } |
| 5841 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5842 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5843 | { |
| 5844 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5845 | struct nfs_client *clp = calldata->clp; |
| 5846 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5847 | |
| 5848 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5849 | if (!nfs41_sequence_done(task, res)) |
| 5850 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5851 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5852 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5853 | rpc_restart_call_prepare(task); |
| 5854 | return; |
| 5855 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5856 | dprintk("<-- %s\n", __func__); |
| 5857 | } |
| 5858 | |
| 5859 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5860 | { |
| 5861 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5862 | |
| 5863 | kfree(calldata); |
| 5864 | } |
| 5865 | |
| 5866 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5867 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5868 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5869 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5870 | }; |
| 5871 | |
| 5872 | /* |
| 5873 | * Issue a global reclaim complete. |
| 5874 | */ |
| 5875 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5876 | { |
| 5877 | struct nfs4_reclaim_complete_data *calldata; |
| 5878 | struct rpc_task *task; |
| 5879 | struct rpc_message msg = { |
| 5880 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5881 | }; |
| 5882 | struct rpc_task_setup task_setup_data = { |
| 5883 | .rpc_client = clp->cl_rpcclient, |
| 5884 | .rpc_message = &msg, |
| 5885 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5886 | .flags = RPC_TASK_ASYNC, |
| 5887 | }; |
| 5888 | int status = -ENOMEM; |
| 5889 | |
| 5890 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5891 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5892 | if (calldata == NULL) |
| 5893 | goto out; |
| 5894 | calldata->clp = clp; |
| 5895 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5896 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5897 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5898 | msg.rpc_argp = &calldata->arg; |
| 5899 | msg.rpc_resp = &calldata->res; |
| 5900 | task_setup_data.callback_data = calldata; |
| 5901 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5902 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5903 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5904 | goto out; |
| 5905 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5906 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5907 | if (status == 0) |
| 5908 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5909 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5910 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5911 | out: |
| 5912 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5913 | return status; |
| 5914 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5915 | |
| 5916 | static void |
| 5917 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5918 | { |
| 5919 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5920 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5921 | |
| 5922 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5923 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5924 | * right now covering the LAYOUTGET we are about to send. |
| 5925 | * However, that is not so catastrophic, and there seems |
| 5926 | * to be no way to prevent it completely. |
| 5927 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5928 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5929 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5930 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5931 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5932 | NFS_I(lgp->args.inode)->layout, |
| 5933 | lgp->args.ctx->state)) { |
| 5934 | rpc_exit(task, NFS4_OK); |
| 5935 | return; |
| 5936 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5937 | rpc_call_start(task); |
| 5938 | } |
| 5939 | |
| 5940 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5941 | { |
| 5942 | struct nfs4_layoutget *lgp = calldata; |
| 5943 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5944 | |
| 5945 | dprintk("--> %s\n", __func__); |
| 5946 | |
| 5947 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5948 | return; |
| 5949 | |
| 5950 | switch (task->tk_status) { |
| 5951 | case 0: |
| 5952 | break; |
| 5953 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5954 | case -NFS4ERR_RECALLCONFLICT: |
| 5955 | task->tk_status = -NFS4ERR_DELAY; |
| 5956 | /* Fall through */ |
| 5957 | default: |
| 5958 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5959 | rpc_restart_call_prepare(task); |
| 5960 | return; |
| 5961 | } |
| 5962 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5963 | dprintk("<-- %s\n", __func__); |
| 5964 | } |
| 5965 | |
| 5966 | static void nfs4_layoutget_release(void *calldata) |
| 5967 | { |
| 5968 | struct nfs4_layoutget *lgp = calldata; |
| 5969 | |
| 5970 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5971 | put_nfs_open_context(lgp->args.ctx); |
| 5972 | kfree(calldata); |
| 5973 | dprintk("<-- %s\n", __func__); |
| 5974 | } |
| 5975 | |
| 5976 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5977 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5978 | .rpc_call_done = nfs4_layoutget_done, |
| 5979 | .rpc_release = nfs4_layoutget_release, |
| 5980 | }; |
| 5981 | |
| 5982 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5983 | { |
| 5984 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5985 | struct rpc_task *task; |
| 5986 | struct rpc_message msg = { |
| 5987 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5988 | .rpc_argp = &lgp->args, |
| 5989 | .rpc_resp = &lgp->res, |
| 5990 | }; |
| 5991 | struct rpc_task_setup task_setup_data = { |
| 5992 | .rpc_client = server->client, |
| 5993 | .rpc_message = &msg, |
| 5994 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5995 | .callback_data = lgp, |
| 5996 | .flags = RPC_TASK_ASYNC, |
| 5997 | }; |
| 5998 | int status = 0; |
| 5999 | |
| 6000 | dprintk("--> %s\n", __func__); |
| 6001 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6002 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6003 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6004 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6005 | task = rpc_run_task(&task_setup_data); |
| 6006 | if (IS_ERR(task)) |
| 6007 | return PTR_ERR(task); |
| 6008 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6009 | if (status == 0) |
| 6010 | status = task->tk_status; |
| 6011 | if (status == 0) |
| 6012 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6013 | rpc_put_task(task); |
| 6014 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6015 | return status; |
| 6016 | } |
| 6017 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6018 | static void |
| 6019 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6020 | { |
| 6021 | struct nfs4_layoutreturn *lrp = calldata; |
| 6022 | |
| 6023 | dprintk("--> %s\n", __func__); |
| 6024 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6025 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6026 | return; |
| 6027 | rpc_call_start(task); |
| 6028 | } |
| 6029 | |
| 6030 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6031 | { |
| 6032 | struct nfs4_layoutreturn *lrp = calldata; |
| 6033 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6034 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6035 | |
| 6036 | dprintk("--> %s\n", __func__); |
| 6037 | |
| 6038 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6039 | return; |
| 6040 | |
| 6041 | server = NFS_SERVER(lrp->args.inode); |
| 6042 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6043 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6044 | return; |
| 6045 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6046 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6047 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6048 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6049 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6050 | } else |
| 6051 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 6052 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6053 | lo->plh_block_lgets--; |
| 6054 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6055 | dprintk("<-- %s\n", __func__); |
| 6056 | } |
| 6057 | |
| 6058 | static void nfs4_layoutreturn_release(void *calldata) |
| 6059 | { |
| 6060 | struct nfs4_layoutreturn *lrp = calldata; |
| 6061 | |
| 6062 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6063 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6064 | kfree(calldata); |
| 6065 | dprintk("<-- %s\n", __func__); |
| 6066 | } |
| 6067 | |
| 6068 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6069 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6070 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6071 | .rpc_release = nfs4_layoutreturn_release, |
| 6072 | }; |
| 6073 | |
| 6074 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6075 | { |
| 6076 | struct rpc_task *task; |
| 6077 | struct rpc_message msg = { |
| 6078 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6079 | .rpc_argp = &lrp->args, |
| 6080 | .rpc_resp = &lrp->res, |
| 6081 | }; |
| 6082 | struct rpc_task_setup task_setup_data = { |
| 6083 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6084 | .rpc_message = &msg, |
| 6085 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6086 | .callback_data = lrp, |
| 6087 | }; |
| 6088 | int status; |
| 6089 | |
| 6090 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6091 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6092 | task = rpc_run_task(&task_setup_data); |
| 6093 | if (IS_ERR(task)) |
| 6094 | return PTR_ERR(task); |
| 6095 | status = task->tk_status; |
| 6096 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6097 | rpc_put_task(task); |
| 6098 | return status; |
| 6099 | } |
| 6100 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6101 | /* |
| 6102 | * Retrieve the list of Data Server devices from the MDS. |
| 6103 | */ |
| 6104 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6105 | const struct nfs_fh *fh, |
| 6106 | struct pnfs_devicelist *devlist) |
| 6107 | { |
| 6108 | struct nfs4_getdevicelist_args args = { |
| 6109 | .fh = fh, |
| 6110 | .layoutclass = server->pnfs_curr_ld->id, |
| 6111 | }; |
| 6112 | struct nfs4_getdevicelist_res res = { |
| 6113 | .devlist = devlist, |
| 6114 | }; |
| 6115 | struct rpc_message msg = { |
| 6116 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6117 | .rpc_argp = &args, |
| 6118 | .rpc_resp = &res, |
| 6119 | }; |
| 6120 | int status; |
| 6121 | |
| 6122 | dprintk("--> %s\n", __func__); |
| 6123 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6124 | &res.seq_res, 0); |
| 6125 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6126 | return status; |
| 6127 | } |
| 6128 | |
| 6129 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6130 | const struct nfs_fh *fh, |
| 6131 | struct pnfs_devicelist *devlist) |
| 6132 | { |
| 6133 | struct nfs4_exception exception = { }; |
| 6134 | int err; |
| 6135 | |
| 6136 | do { |
| 6137 | err = nfs4_handle_exception(server, |
| 6138 | _nfs4_getdevicelist(server, fh, devlist), |
| 6139 | &exception); |
| 6140 | } while (exception.retry); |
| 6141 | |
| 6142 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6143 | err, devlist->num_devs); |
| 6144 | |
| 6145 | return err; |
| 6146 | } |
| 6147 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6148 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6149 | static int |
| 6150 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6151 | { |
| 6152 | struct nfs4_getdeviceinfo_args args = { |
| 6153 | .pdev = pdev, |
| 6154 | }; |
| 6155 | struct nfs4_getdeviceinfo_res res = { |
| 6156 | .pdev = pdev, |
| 6157 | }; |
| 6158 | struct rpc_message msg = { |
| 6159 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6160 | .rpc_argp = &args, |
| 6161 | .rpc_resp = &res, |
| 6162 | }; |
| 6163 | int status; |
| 6164 | |
| 6165 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6166 | 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] | 6167 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6168 | |
| 6169 | return status; |
| 6170 | } |
| 6171 | |
| 6172 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6173 | { |
| 6174 | struct nfs4_exception exception = { }; |
| 6175 | int err; |
| 6176 | |
| 6177 | do { |
| 6178 | err = nfs4_handle_exception(server, |
| 6179 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6180 | &exception); |
| 6181 | } while (exception.retry); |
| 6182 | return err; |
| 6183 | } |
| 6184 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6185 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6186 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6187 | { |
| 6188 | struct nfs4_layoutcommit_data *data = calldata; |
| 6189 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6190 | |
| 6191 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6192 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6193 | return; |
| 6194 | rpc_call_start(task); |
| 6195 | } |
| 6196 | |
| 6197 | static void |
| 6198 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6199 | { |
| 6200 | struct nfs4_layoutcommit_data *data = calldata; |
| 6201 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6202 | |
| 6203 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6204 | return; |
| 6205 | |
| 6206 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6207 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6208 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6209 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6210 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6211 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6212 | break; |
| 6213 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6214 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6215 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6216 | break; |
| 6217 | default: |
| 6218 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6219 | rpc_restart_call_prepare(task); |
| 6220 | return; |
| 6221 | } |
| 6222 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | static void nfs4_layoutcommit_release(void *calldata) |
| 6226 | { |
| 6227 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6228 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6229 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6230 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6231 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6232 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6233 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6234 | list_del_init(&lseg->pls_lc_list); |
| 6235 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6236 | &lseg->pls_flags)) |
| 6237 | put_lseg(lseg); |
| 6238 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6239 | |
| 6240 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6241 | smp_mb__after_clear_bit(); |
| 6242 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6243 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6244 | put_rpccred(data->cred); |
| 6245 | kfree(data); |
| 6246 | } |
| 6247 | |
| 6248 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6249 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6250 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6251 | .rpc_release = nfs4_layoutcommit_release, |
| 6252 | }; |
| 6253 | |
| 6254 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6255 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6256 | { |
| 6257 | struct rpc_message msg = { |
| 6258 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6259 | .rpc_argp = &data->args, |
| 6260 | .rpc_resp = &data->res, |
| 6261 | .rpc_cred = data->cred, |
| 6262 | }; |
| 6263 | struct rpc_task_setup task_setup_data = { |
| 6264 | .task = &data->task, |
| 6265 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6266 | .rpc_message = &msg, |
| 6267 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6268 | .callback_data = data, |
| 6269 | .flags = RPC_TASK_ASYNC, |
| 6270 | }; |
| 6271 | struct rpc_task *task; |
| 6272 | int status = 0; |
| 6273 | |
| 6274 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6275 | "lbw: %llu inode %lu\n", |
| 6276 | data->task.tk_pid, sync, |
| 6277 | data->args.lastbytewritten, |
| 6278 | data->args.inode->i_ino); |
| 6279 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6280 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6281 | task = rpc_run_task(&task_setup_data); |
| 6282 | if (IS_ERR(task)) |
| 6283 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6284 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6285 | goto out; |
| 6286 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6287 | if (status != 0) |
| 6288 | goto out; |
| 6289 | status = task->tk_status; |
| 6290 | out: |
| 6291 | dprintk("%s: status %d\n", __func__, status); |
| 6292 | rpc_put_task(task); |
| 6293 | return status; |
| 6294 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6295 | |
| 6296 | static int |
| 6297 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6298 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6299 | { |
| 6300 | struct nfs41_secinfo_no_name_args args = { |
| 6301 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6302 | }; |
| 6303 | struct nfs4_secinfo_res res = { |
| 6304 | .flavors = flavors, |
| 6305 | }; |
| 6306 | struct rpc_message msg = { |
| 6307 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6308 | .rpc_argp = &args, |
| 6309 | .rpc_resp = &res, |
| 6310 | }; |
| 6311 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6312 | } |
| 6313 | |
| 6314 | static int |
| 6315 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6316 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6317 | { |
| 6318 | struct nfs4_exception exception = { }; |
| 6319 | int err; |
| 6320 | do { |
| 6321 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6322 | switch (err) { |
| 6323 | case 0: |
| 6324 | case -NFS4ERR_WRONGSEC: |
| 6325 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6326 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6327 | default: |
| 6328 | err = nfs4_handle_exception(server, err, &exception); |
| 6329 | } |
| 6330 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6331 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6332 | return err; |
| 6333 | } |
| 6334 | |
| 6335 | static int |
| 6336 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6337 | struct nfs_fsinfo *info) |
| 6338 | { |
| 6339 | int err; |
| 6340 | struct page *page; |
| 6341 | rpc_authflavor_t flavor; |
| 6342 | struct nfs4_secinfo_flavors *flavors; |
| 6343 | |
| 6344 | page = alloc_page(GFP_KERNEL); |
| 6345 | if (!page) { |
| 6346 | err = -ENOMEM; |
| 6347 | goto out; |
| 6348 | } |
| 6349 | |
| 6350 | flavors = page_address(page); |
| 6351 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6352 | |
| 6353 | /* |
| 6354 | * Fall back on "guess and check" method if |
| 6355 | * the server doesn't support SECINFO_NO_NAME |
| 6356 | */ |
| 6357 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6358 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6359 | goto out_freepage; |
| 6360 | } |
| 6361 | if (err) |
| 6362 | goto out_freepage; |
| 6363 | |
| 6364 | flavor = nfs_find_best_sec(flavors); |
| 6365 | if (err == 0) |
| 6366 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6367 | |
| 6368 | out_freepage: |
| 6369 | put_page(page); |
| 6370 | if (err == -EACCES) |
| 6371 | return -EPERM; |
| 6372 | out: |
| 6373 | return err; |
| 6374 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6375 | |
| 6376 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6377 | { |
| 6378 | int status; |
| 6379 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6380 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6381 | }; |
| 6382 | struct nfs41_test_stateid_res res; |
| 6383 | struct rpc_message msg = { |
| 6384 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6385 | .rpc_argp = &args, |
| 6386 | .rpc_resp = &res, |
| 6387 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6388 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6389 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6390 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
| 6391 | |
| 6392 | if (status == NFS_OK) |
| 6393 | return res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6394 | return status; |
| 6395 | } |
| 6396 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6397 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6398 | { |
| 6399 | struct nfs4_exception exception = { }; |
| 6400 | int err; |
| 6401 | do { |
| 6402 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6403 | _nfs41_test_stateid(server, stateid), |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6404 | &exception); |
| 6405 | } while (exception.retry); |
| 6406 | return err; |
| 6407 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6408 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6409 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6410 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6411 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6412 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6413 | }; |
| 6414 | struct nfs41_free_stateid_res res; |
| 6415 | struct rpc_message msg = { |
| 6416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6417 | .rpc_argp = &args, |
| 6418 | .rpc_resp = &res, |
| 6419 | }; |
| 6420 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6421 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6422 | 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] | 6423 | } |
| 6424 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6425 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6426 | { |
| 6427 | struct nfs4_exception exception = { }; |
| 6428 | int err; |
| 6429 | do { |
| 6430 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6431 | _nfs4_free_stateid(server, stateid), |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6432 | &exception); |
| 6433 | } while (exception.retry); |
| 6434 | return err; |
| 6435 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6436 | |
| 6437 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6438 | const nfs4_stateid *s2) |
| 6439 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6440 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6441 | return false; |
| 6442 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6443 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6444 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6445 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6446 | return true; |
| 6447 | |
| 6448 | return false; |
| 6449 | } |
| 6450 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6451 | #endif /* CONFIG_NFS_V4_1 */ |
| 6452 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6453 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6454 | const nfs4_stateid *s2) |
| 6455 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6456 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6457 | } |
| 6458 | |
| 6459 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6460 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6461 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6462 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | .recover_open = nfs4_open_reclaim, |
| 6464 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6465 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6466 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6467 | }; |
| 6468 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6469 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6470 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6471 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6472 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6473 | .recover_open = nfs4_open_reclaim, |
| 6474 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6475 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6476 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6477 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6478 | }; |
| 6479 | #endif /* CONFIG_NFS_V4_1 */ |
| 6480 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6481 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6482 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6483 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6484 | .recover_open = nfs4_open_expired, |
| 6485 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6486 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6487 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6488 | }; |
| 6489 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6490 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6491 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6492 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6493 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6494 | .recover_open = nfs41_open_expired, |
| 6495 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6496 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6497 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6498 | }; |
| 6499 | #endif /* CONFIG_NFS_V4_1 */ |
| 6500 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6501 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6502 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6503 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6504 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6505 | }; |
| 6506 | |
| 6507 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6508 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6509 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6510 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6511 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6512 | }; |
| 6513 | #endif |
| 6514 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6515 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6516 | .minor_version = 0, |
| 6517 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6518 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6519 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6520 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6521 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6522 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6523 | }; |
| 6524 | |
| 6525 | #if defined(CONFIG_NFS_V4_1) |
| 6526 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6527 | .minor_version = 1, |
| 6528 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6529 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6530 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6531 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6532 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6533 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6534 | }; |
| 6535 | #endif |
| 6536 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6537 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6538 | [0] = &nfs_v4_0_minor_ops, |
| 6539 | #if defined(CONFIG_NFS_V4_1) |
| 6540 | [1] = &nfs_v4_1_minor_ops, |
| 6541 | #endif |
| 6542 | }; |
| 6543 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6544 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6545 | .permission = nfs_permission, |
| 6546 | .getattr = nfs_getattr, |
| 6547 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6548 | .getxattr = generic_getxattr, |
| 6549 | .setxattr = generic_setxattr, |
| 6550 | .listxattr = generic_listxattr, |
| 6551 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6552 | }; |
| 6553 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6554 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6555 | .version = 4, /* protocol version */ |
| 6556 | .dentry_ops = &nfs4_dentry_operations, |
| 6557 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6558 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6559 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | .getroot = nfs4_proc_get_root, |
| 6561 | .getattr = nfs4_proc_getattr, |
| 6562 | .setattr = nfs4_proc_setattr, |
| 6563 | .lookup = nfs4_proc_lookup, |
| 6564 | .access = nfs4_proc_access, |
| 6565 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | .create = nfs4_proc_create, |
| 6567 | .remove = nfs4_proc_remove, |
| 6568 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6569 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6570 | .unlink_done = nfs4_proc_unlink_done, |
| 6571 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6572 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6573 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6574 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6575 | .link = nfs4_proc_link, |
| 6576 | .symlink = nfs4_proc_symlink, |
| 6577 | .mkdir = nfs4_proc_mkdir, |
| 6578 | .rmdir = nfs4_proc_remove, |
| 6579 | .readdir = nfs4_proc_readdir, |
| 6580 | .mknod = nfs4_proc_mknod, |
| 6581 | .statfs = nfs4_proc_statfs, |
| 6582 | .fsinfo = nfs4_proc_fsinfo, |
| 6583 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6584 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6585 | .decode_dirent = nfs4_decode_dirent, |
| 6586 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6587 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6588 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6589 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6590 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6591 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6592 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6593 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6594 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6595 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6596 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6597 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6598 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6599 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6600 | }; |
| 6601 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6602 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6603 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6604 | .list = nfs4_xattr_list_nfs4_acl, |
| 6605 | .get = nfs4_xattr_get_nfs4_acl, |
| 6606 | .set = nfs4_xattr_set_nfs4_acl, |
| 6607 | }; |
| 6608 | |
| 6609 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6610 | &nfs4_xattr_nfs4_acl_handler, |
| 6611 | NULL |
| 6612 | }; |
| 6613 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6614 | module_param(max_session_slots, ushort, 0644); |
| 6615 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6616 | "requests the client will negotiate"); |
| 6617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6618 | /* |
| 6619 | * Local variables: |
| 6620 | * c-basic-offset: 8 |
| 6621 | * End: |
| 6622 | */ |