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" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 67 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 70 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 73 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 74 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 75 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 76 | static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE; |
| 77 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 78 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 79 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 80 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 82 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 83 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 84 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 85 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 86 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 87 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 88 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 90 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 91 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 92 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 94 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 96 | if (err >= -1000) |
| 97 | return err; |
| 98 | switch (err) { |
| 99 | case -NFS4ERR_RESOURCE: |
| 100 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 101 | case -NFS4ERR_WRONGSEC: |
| 102 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 103 | case -NFS4ERR_BADOWNER: |
| 104 | case -NFS4ERR_BADNAME: |
| 105 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 106 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 108 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 111 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* |
| 115 | * This is our standard bitmap for GETATTR requests. |
| 116 | */ |
| 117 | const u32 nfs4_fattr_bitmap[2] = { |
| 118 | FATTR4_WORD0_TYPE |
| 119 | | FATTR4_WORD0_CHANGE |
| 120 | | FATTR4_WORD0_SIZE |
| 121 | | FATTR4_WORD0_FSID |
| 122 | | FATTR4_WORD0_FILEID, |
| 123 | FATTR4_WORD1_MODE |
| 124 | | FATTR4_WORD1_NUMLINKS |
| 125 | | FATTR4_WORD1_OWNER |
| 126 | | FATTR4_WORD1_OWNER_GROUP |
| 127 | | FATTR4_WORD1_RAWDEV |
| 128 | | FATTR4_WORD1_SPACE_USED |
| 129 | | FATTR4_WORD1_TIME_ACCESS |
| 130 | | FATTR4_WORD1_TIME_METADATA |
| 131 | | FATTR4_WORD1_TIME_MODIFY |
| 132 | }; |
| 133 | |
| 134 | const u32 nfs4_statfs_bitmap[2] = { |
| 135 | FATTR4_WORD0_FILES_AVAIL |
| 136 | | FATTR4_WORD0_FILES_FREE |
| 137 | | FATTR4_WORD0_FILES_TOTAL, |
| 138 | FATTR4_WORD1_SPACE_AVAIL |
| 139 | | FATTR4_WORD1_SPACE_FREE |
| 140 | | FATTR4_WORD1_SPACE_TOTAL |
| 141 | }; |
| 142 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 143 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | FATTR4_WORD0_MAXLINK |
| 145 | | FATTR4_WORD0_MAXNAME, |
| 146 | 0 |
| 147 | }; |
| 148 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 149 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | | FATTR4_WORD0_MAXREAD |
| 151 | | FATTR4_WORD0_MAXWRITE |
| 152 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 153 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 154 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 155 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 158 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 159 | FATTR4_WORD0_TYPE |
| 160 | | FATTR4_WORD0_CHANGE |
| 161 | | FATTR4_WORD0_SIZE |
| 162 | | FATTR4_WORD0_FSID |
| 163 | | FATTR4_WORD0_FILEID |
| 164 | | FATTR4_WORD0_FS_LOCATIONS, |
| 165 | FATTR4_WORD1_MODE |
| 166 | | FATTR4_WORD1_NUMLINKS |
| 167 | | FATTR4_WORD1_OWNER |
| 168 | | FATTR4_WORD1_OWNER_GROUP |
| 169 | | FATTR4_WORD1_RAWDEV |
| 170 | | FATTR4_WORD1_SPACE_USED |
| 171 | | FATTR4_WORD1_TIME_ACCESS |
| 172 | | FATTR4_WORD1_TIME_METADATA |
| 173 | | FATTR4_WORD1_TIME_MODIFY |
| 174 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 175 | }; |
| 176 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 177 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | struct nfs4_readdir_arg *readdir) |
| 179 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 180 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | BUG_ON(readdir->count < 80); |
| 183 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 184 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | readdir->cookie = 0; |
| 190 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 191 | if (cookie == 2) |
| 192 | return; |
| 193 | |
| 194 | /* |
| 195 | * NFSv4 servers do not return entries for '.' and '..' |
| 196 | * Therefore, we fake these entries here. We let '.' |
| 197 | * have cookie 0 and '..' have cookie 1. Note that |
| 198 | * when talking to the server, we always send cookie 0 |
| 199 | * instead of 1 or 2. |
| 200 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 201 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | if (cookie == 0) { |
| 204 | *p++ = xdr_one; /* next */ |
| 205 | *p++ = xdr_zero; /* cookie, first word */ |
| 206 | *p++ = xdr_one; /* cookie, second word */ |
| 207 | *p++ = xdr_one; /* entry len */ |
| 208 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 209 | p++; |
| 210 | *p++ = xdr_one; /* bitmap length */ |
| 211 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 212 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 213 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | *p++ = xdr_one; /* next */ |
| 217 | *p++ = xdr_zero; /* cookie, first word */ |
| 218 | *p++ = xdr_two; /* cookie, second word */ |
| 219 | *p++ = xdr_two; /* entry len */ |
| 220 | memcpy(p, "..\0\0", 4); /* entry */ |
| 221 | p++; |
| 222 | *p++ = xdr_one; /* bitmap length */ |
| 223 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 224 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 225 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | readdir->pgbase = (char *)p - (char *)start; |
| 228 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 229 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 232 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 233 | { |
| 234 | int res; |
| 235 | |
| 236 | might_sleep(); |
| 237 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 238 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 239 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 240 | return res; |
| 241 | } |
| 242 | |
| 243 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 244 | { |
| 245 | int res = 0; |
| 246 | |
| 247 | might_sleep(); |
| 248 | |
| 249 | if (*timeout <= 0) |
| 250 | *timeout = NFS4_POLL_RETRY_MIN; |
| 251 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 252 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 253 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 254 | if (fatal_signal_pending(current)) |
| 255 | res = -ERESTARTSYS; |
| 256 | *timeout <<= 1; |
| 257 | return res; |
| 258 | } |
| 259 | |
| 260 | /* This is the error handling routine for processes that are allowed |
| 261 | * to sleep. |
| 262 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 263 | 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] | 264 | { |
| 265 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 266 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 267 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 268 | int ret = errorcode; |
| 269 | |
| 270 | exception->retry = 0; |
| 271 | switch(errorcode) { |
| 272 | case 0: |
| 273 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 274 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 275 | if (inode && nfs_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 276 | nfs_inode_return_delegation(inode); |
| 277 | exception->retry = 1; |
| 278 | return 0; |
| 279 | } |
| 280 | if (state == NULL) |
| 281 | break; |
| 282 | nfs4_schedule_stateid_recovery(server, state); |
| 283 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 284 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 285 | case -NFS4ERR_ADMIN_REVOKED: |
| 286 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 287 | if (state == NULL) |
| 288 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 289 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 290 | nfs4_schedule_stateid_recovery(server, state); |
| 291 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 292 | case -NFS4ERR_EXPIRED: |
| 293 | if (state != NULL) |
| 294 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 295 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 296 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 297 | nfs4_schedule_lease_recovery(clp); |
| 298 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 299 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 300 | case -NFS4ERR_BADSESSION: |
| 301 | case -NFS4ERR_BADSLOT: |
| 302 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 303 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 304 | case -NFS4ERR_DEADSESSION: |
| 305 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 306 | case -NFS4ERR_SEQ_MISORDERED: |
| 307 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 308 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame^] | 309 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 310 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 311 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 312 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 313 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 314 | if (exception->timeout > HZ) { |
| 315 | /* We have retried a decent amount, time to |
| 316 | * fail |
| 317 | */ |
| 318 | ret = -EBUSY; |
| 319 | break; |
| 320 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 321 | case -NFS4ERR_GRACE: |
| 322 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 323 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 324 | ret = nfs4_delay(server->client, &exception->timeout); |
| 325 | if (ret != 0) |
| 326 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 327 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 328 | case -NFS4ERR_OLD_STATEID: |
| 329 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 330 | break; |
| 331 | case -NFS4ERR_BADOWNER: |
| 332 | /* The following works around a Linux server bug! */ |
| 333 | case -NFS4ERR_BADNAME: |
| 334 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 335 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 336 | exception->retry = 1; |
| 337 | printk(KERN_WARNING "NFS: v4 server %s " |
| 338 | "does not accept raw " |
| 339 | "uid/gids. " |
| 340 | "Reenabling the idmapper.\n", |
| 341 | server->nfs_client->cl_hostname); |
| 342 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 343 | } |
| 344 | /* We failed to handle the error */ |
| 345 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 346 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 347 | ret = nfs4_wait_clnt_recover(clp); |
| 348 | if (ret == 0) |
| 349 | exception->retry = 1; |
| 350 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 354 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | spin_lock(&clp->cl_lock); |
| 357 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 358 | clp->cl_last_renewal = timestamp; |
| 359 | spin_unlock(&clp->cl_lock); |
| 360 | } |
| 361 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 362 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 363 | { |
| 364 | do_renew_lease(server->nfs_client, timestamp); |
| 365 | } |
| 366 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 367 | #if defined(CONFIG_NFS_V4_1) |
| 368 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 369 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 370 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 371 | * |
| 372 | * freeing a slot is trivially done by clearing its respective bit |
| 373 | * in the bitmap. |
| 374 | * If the freed slotid equals highest_used_slotid we want to update it |
| 375 | * so that the server would be able to size down the slot table if needed, |
| 376 | * otherwise we know that the highest_used_slotid is still in use. |
| 377 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 378 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 379 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 380 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 381 | * |
| 382 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 383 | */ |
| 384 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 385 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 386 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 387 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 388 | /* clear used bit in bitmap */ |
| 389 | __clear_bit(slotid, tbl->used_slots); |
| 390 | |
| 391 | /* update highest_used_slotid when it is freed */ |
| 392 | if (slotid == tbl->highest_used_slotid) { |
| 393 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 394 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 395 | tbl->highest_used_slotid = slotid; |
| 396 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 397 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 398 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 399 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 400 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 403 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 404 | { |
| 405 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 406 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 407 | } |
| 408 | |
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 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 411 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 412 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 413 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 414 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 415 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 416 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 417 | return; |
| 418 | } |
| 419 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 420 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 421 | return; |
| 422 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 423 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 424 | complete(&ses->fc_slot_table.complete); |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * Signal state manager thread if session back channel is drained |
| 429 | */ |
| 430 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 431 | { |
| 432 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 433 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 434 | return; |
| 435 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 436 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 439 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 440 | { |
| 441 | struct nfs4_slot_table *tbl; |
| 442 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 443 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 444 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 445 | /* just wake up the next guy waiting since |
| 446 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 447 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 448 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 449 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 450 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 451 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 452 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 453 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 454 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 455 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | 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] | 459 | { |
| 460 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 461 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 462 | |
| 463 | /* |
| 464 | * sr_status remains 1 if an RPC level error occurred. The server |
| 465 | * may or may not have processed the sequence operation.. |
| 466 | * Proceed as if the server received and processed the sequence |
| 467 | * operation. |
| 468 | */ |
| 469 | if (res->sr_status == 1) |
| 470 | res->sr_status = NFS_OK; |
| 471 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 472 | /* don't increment the sequence number if the task wasn't sent */ |
| 473 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 474 | goto out; |
| 475 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 476 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 477 | switch (res->sr_status) { |
| 478 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 479 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 480 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 481 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 483 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 484 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 485 | if (res->sr_status_flags != 0) |
| 486 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | break; |
| 488 | case -NFS4ERR_DELAY: |
| 489 | /* The server detected a resend of the RPC call and |
| 490 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 491 | * of RFC5661. |
| 492 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 493 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 494 | __func__, |
| 495 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 496 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 497 | goto out_retry; |
| 498 | default: |
| 499 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 500 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 501 | } |
| 502 | out: |
| 503 | /* The session may be reset by one of the error handlers. */ |
| 504 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 505 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 506 | return 1; |
| 507 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 508 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 509 | goto out; |
| 510 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 511 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 514 | static int nfs4_sequence_done(struct rpc_task *task, |
| 515 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 516 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 517 | if (res->sr_session == NULL) |
| 518 | return 1; |
| 519 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 520 | } |
| 521 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 522 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 523 | * nfs4_find_slot - efficiently look for a free slot |
| 524 | * |
| 525 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 526 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 527 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 528 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 529 | * |
| 530 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 531 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 532 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 533 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 534 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 535 | u32 slotid; |
| 536 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 537 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 538 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 539 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 540 | tbl->max_slots); |
| 541 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 542 | if (slotid >= tbl->max_slots) |
| 543 | goto out; |
| 544 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 545 | if (slotid > tbl->highest_used_slotid || |
| 546 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 547 | tbl->highest_used_slotid = slotid; |
| 548 | ret_id = slotid; |
| 549 | out: |
| 550 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 551 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 552 | return ret_id; |
| 553 | } |
| 554 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 555 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 556 | struct nfs4_sequence_res *res, int cache_reply) |
| 557 | { |
| 558 | args->sa_session = NULL; |
| 559 | args->sa_cache_this = 0; |
| 560 | if (cache_reply) |
| 561 | args->sa_cache_this = 1; |
| 562 | res->sr_session = NULL; |
| 563 | res->sr_slot = NULL; |
| 564 | } |
| 565 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 566 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 567 | struct nfs4_sequence_args *args, |
| 568 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 569 | struct rpc_task *task) |
| 570 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 571 | struct nfs4_slot *slot; |
| 572 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 573 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | |
| 575 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 576 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 577 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 578 | return 0; |
| 579 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 580 | tbl = &session->fc_slot_table; |
| 581 | |
| 582 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 583 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 584 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 585 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 586 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 587 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 588 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 589 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 592 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 593 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 594 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 595 | spin_unlock(&tbl->slot_tbl_lock); |
| 596 | dprintk("%s enforce FIFO order\n", __func__); |
| 597 | return -EAGAIN; |
| 598 | } |
| 599 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 600 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 601 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 602 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 603 | spin_unlock(&tbl->slot_tbl_lock); |
| 604 | dprintk("<-- %s: no free slots\n", __func__); |
| 605 | return -EAGAIN; |
| 606 | } |
| 607 | spin_unlock(&tbl->slot_tbl_lock); |
| 608 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 609 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 610 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 611 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 612 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 613 | |
| 614 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 615 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 616 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 617 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 618 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 619 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 620 | /* |
| 621 | * sr_status is only set in decode_sequence, and so will remain |
| 622 | * set to 1 if an rpc level failure occurs. |
| 623 | */ |
| 624 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | return 0; |
| 626 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 627 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 628 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct nfs4_sequence_args *args, |
| 631 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | struct rpc_task *task) |
| 633 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 634 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 635 | int ret = 0; |
| 636 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 637 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 638 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 639 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 640 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 641 | __func__, session->clp, session, res->sr_slot ? |
| 642 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 643 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 644 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | out: |
| 646 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 651 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 652 | struct nfs4_sequence_args *seq_args; |
| 653 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 657 | { |
| 658 | struct nfs41_call_sync_data *data = calldata; |
| 659 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 660 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 661 | |
| 662 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 663 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 664 | return; |
| 665 | rpc_call_start(task); |
| 666 | } |
| 667 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 668 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 669 | { |
| 670 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 671 | nfs41_call_sync_prepare(task, calldata); |
| 672 | } |
| 673 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 674 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 675 | { |
| 676 | struct nfs41_call_sync_data *data = calldata; |
| 677 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 678 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 679 | } |
| 680 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 681 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 683 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 684 | }; |
| 685 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 686 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 687 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 688 | .rpc_call_done = nfs41_call_sync_done, |
| 689 | }; |
| 690 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 691 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 692 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 693 | struct rpc_message *msg, |
| 694 | struct nfs4_sequence_args *args, |
| 695 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 696 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 697 | { |
| 698 | int ret; |
| 699 | struct rpc_task *task; |
| 700 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 701 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 702 | .seq_args = args, |
| 703 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 704 | }; |
| 705 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 706 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 707 | .rpc_message = msg, |
| 708 | .callback_ops = &nfs41_call_sync_ops, |
| 709 | .callback_data = &data |
| 710 | }; |
| 711 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 712 | if (privileged) |
| 713 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 714 | task = rpc_run_task(&task_setup); |
| 715 | if (IS_ERR(task)) |
| 716 | ret = PTR_ERR(task); |
| 717 | else { |
| 718 | ret = task->tk_status; |
| 719 | rpc_put_task(task); |
| 720 | } |
| 721 | return ret; |
| 722 | } |
| 723 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 725 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 726 | struct rpc_message *msg, |
| 727 | struct nfs4_sequence_args *args, |
| 728 | struct nfs4_sequence_res *res, |
| 729 | int cache_reply) |
| 730 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 731 | nfs41_init_sequence(args, res, cache_reply); |
| 732 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 733 | } |
| 734 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 735 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 736 | static inline |
| 737 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 738 | struct nfs4_sequence_res *res, int cache_reply) |
| 739 | { |
| 740 | } |
| 741 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 742 | static int nfs4_sequence_done(struct rpc_task *task, |
| 743 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 744 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 745 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 746 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 747 | #endif /* CONFIG_NFS_V4_1 */ |
| 748 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 749 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 750 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 751 | struct rpc_message *msg, |
| 752 | struct nfs4_sequence_args *args, |
| 753 | struct nfs4_sequence_res *res, |
| 754 | int cache_reply) |
| 755 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 756 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 757 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 758 | } |
| 759 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 760 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 761 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 762 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 763 | struct rpc_message *msg, |
| 764 | struct nfs4_sequence_args *args, |
| 765 | struct nfs4_sequence_res *res, |
| 766 | int cache_reply) |
| 767 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 768 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 769 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 770 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 771 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 772 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
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 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 776 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 777 | 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] | 778 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 779 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 780 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 781 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 784 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 785 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 786 | struct nfs_openargs o_arg; |
| 787 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 788 | struct nfs_open_confirmargs c_arg; |
| 789 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 790 | struct nfs4_string owner_name; |
| 791 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 792 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 794 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 795 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 796 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 798 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 799 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 800 | int rpc_status; |
| 801 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 802 | }; |
| 803 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 804 | |
| 805 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 806 | { |
| 807 | p->o_res.f_attr = &p->f_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); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 812 | 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] | 813 | } |
| 814 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 815 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 816 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 817 | const struct iattr *attrs, |
| 818 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 820 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | struct inode *dir = parent->d_inode; |
| 822 | struct nfs_server *server = NFS_SERVER(dir); |
| 823 | struct nfs4_opendata *p; |
| 824 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 825 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | if (p == NULL) |
| 827 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 828 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | if (p->o_arg.seqid == NULL) |
| 830 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 831 | nfs_sb_active(dentry->d_sb); |
| 832 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 833 | p->dir = parent; |
| 834 | p->owner = sp; |
| 835 | atomic_inc(&sp->so_count); |
| 836 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 837 | p->o_arg.open_flags = flags; |
| 838 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 839 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 840 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 841 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 842 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 843 | p->o_arg.server = server; |
| 844 | p->o_arg.bitmask = server->attr_bitmask; |
| 845 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 846 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 847 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 848 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 849 | p->o_arg.u.attrs = &p->attrs; |
| 850 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 851 | |
| 852 | verf[0] = jiffies; |
| 853 | verf[1] = current->pid; |
| 854 | memcpy(p->o_arg.u.verifier.data, verf, |
| 855 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 856 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 857 | p->c_arg.fh = &p->o_res.fh; |
| 858 | p->c_arg.stateid = &p->o_res.stateid; |
| 859 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 860 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 861 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 862 | return p; |
| 863 | err_free: |
| 864 | kfree(p); |
| 865 | err: |
| 866 | dput(parent); |
| 867 | return NULL; |
| 868 | } |
| 869 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 870 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 871 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 872 | struct nfs4_opendata *p = container_of(kref, |
| 873 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 874 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 875 | |
| 876 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 877 | if (p->state != NULL) |
| 878 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 879 | nfs4_put_state_owner(p->owner); |
| 880 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 881 | dput(p->dentry); |
| 882 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 883 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 884 | kfree(p); |
| 885 | } |
| 886 | |
| 887 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 888 | { |
| 889 | if (p != NULL) |
| 890 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 893 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 894 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 895 | int ret; |
| 896 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 897 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 898 | return ret; |
| 899 | } |
| 900 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 901 | 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] | 902 | { |
| 903 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 904 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 905 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 906 | goto out; |
| 907 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 908 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 909 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 910 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 911 | break; |
| 912 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 913 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 914 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 915 | break; |
| 916 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 917 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 918 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 919 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 925 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 926 | if (delegation == NULL) |
| 927 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 929 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 930 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 931 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 932 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 933 | return 1; |
| 934 | } |
| 935 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 936 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 937 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 939 | case FMODE_WRITE: |
| 940 | state->n_wronly++; |
| 941 | break; |
| 942 | case FMODE_READ: |
| 943 | state->n_rdonly++; |
| 944 | break; |
| 945 | case FMODE_READ|FMODE_WRITE: |
| 946 | state->n_rdwr++; |
| 947 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 948 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 949 | } |
| 950 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | 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] | 952 | { |
| 953 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 954 | nfs4_stateid_copy(&state->stateid, stateid); |
| 955 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 957 | case FMODE_READ: |
| 958 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 959 | break; |
| 960 | case FMODE_WRITE: |
| 961 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 962 | break; |
| 963 | case FMODE_READ|FMODE_WRITE: |
| 964 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 965 | } |
| 966 | } |
| 967 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | 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] | 969 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 970 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 971 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 972 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 973 | } |
| 974 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 975 | 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] | 976 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 977 | /* |
| 978 | * Protect the call to nfs4_state_set_mode_locked and |
| 979 | * serialise the stateid update |
| 980 | */ |
| 981 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 982 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 983 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 984 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 985 | } |
| 986 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 987 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 988 | write_sequnlock(&state->seqlock); |
| 989 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 991 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 994 | 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] | 995 | { |
| 996 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 997 | struct nfs_delegation *deleg_cur; |
| 998 | int ret = 0; |
| 999 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1001 | |
| 1002 | rcu_read_lock(); |
| 1003 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1004 | if (deleg_cur == NULL) |
| 1005 | goto no_delegation; |
| 1006 | |
| 1007 | spin_lock(&deleg_cur->lock); |
| 1008 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1009 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1010 | goto no_delegation_unlock; |
| 1011 | |
| 1012 | if (delegation == NULL) |
| 1013 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1014 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1015 | goto no_delegation_unlock; |
| 1016 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1017 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1018 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1019 | ret = 1; |
| 1020 | no_delegation_unlock: |
| 1021 | spin_unlock(&deleg_cur->lock); |
| 1022 | no_delegation: |
| 1023 | rcu_read_unlock(); |
| 1024 | |
| 1025 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1026 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1027 | ret = 1; |
| 1028 | } |
| 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1034 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1035 | { |
| 1036 | struct nfs_delegation *delegation; |
| 1037 | |
| 1038 | rcu_read_lock(); |
| 1039 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1041 | rcu_read_unlock(); |
| 1042 | return; |
| 1043 | } |
| 1044 | rcu_read_unlock(); |
| 1045 | nfs_inode_return_delegation(inode); |
| 1046 | } |
| 1047 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1048 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1049 | { |
| 1050 | struct nfs4_state *state = opendata->state; |
| 1051 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1052 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1053 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1054 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | nfs4_stateid stateid; |
| 1056 | int ret = -EAGAIN; |
| 1057 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1058 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1059 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1060 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | if (can_open_cached(state, fmode, open_mode)) { |
| 1062 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1063 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1064 | goto out_return_state; |
| 1065 | } |
| 1066 | spin_unlock(&state->owner->so_lock); |
| 1067 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1068 | rcu_read_lock(); |
| 1069 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1070 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1071 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1072 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1073 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1074 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1075 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1077 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1078 | if (ret != 0) |
| 1079 | goto out; |
| 1080 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1081 | |
| 1082 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1083 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1084 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1086 | out: |
| 1087 | return ERR_PTR(ret); |
| 1088 | out_return_state: |
| 1089 | atomic_inc(&state->count); |
| 1090 | return state; |
| 1091 | } |
| 1092 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1093 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1094 | { |
| 1095 | struct inode *inode; |
| 1096 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1097 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1098 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1099 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1100 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1101 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1102 | goto out; |
| 1103 | } |
| 1104 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1105 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1106 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1107 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1108 | 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] | 1109 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1110 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1111 | goto err; |
| 1112 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1113 | state = nfs4_get_open_state(inode, data->owner); |
| 1114 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1115 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1116 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1117 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1118 | int delegation_flags = 0; |
| 1119 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1120 | rcu_read_lock(); |
| 1121 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1122 | if (delegation) |
| 1123 | delegation_flags = delegation->flags; |
| 1124 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1125 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1126 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1127 | "returning a delegation for " |
| 1128 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1129 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1130 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1131 | nfs_inode_set_delegation(state->inode, |
| 1132 | data->owner->so_cred, |
| 1133 | &data->o_res); |
| 1134 | else |
| 1135 | nfs_inode_reclaim_delegation(state->inode, |
| 1136 | data->owner->so_cred, |
| 1137 | &data->o_res); |
| 1138 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1139 | |
| 1140 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1142 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1143 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1144 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1145 | err_put_inode: |
| 1146 | iput(inode); |
| 1147 | err: |
| 1148 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1151 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1152 | { |
| 1153 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1154 | struct nfs_open_context *ctx; |
| 1155 | |
| 1156 | spin_lock(&state->inode->i_lock); |
| 1157 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1158 | if (ctx->state != state) |
| 1159 | continue; |
| 1160 | get_nfs_open_context(ctx); |
| 1161 | spin_unlock(&state->inode->i_lock); |
| 1162 | return ctx; |
| 1163 | } |
| 1164 | spin_unlock(&state->inode->i_lock); |
| 1165 | return ERR_PTR(-ENOENT); |
| 1166 | } |
| 1167 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1168 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1169 | { |
| 1170 | struct nfs4_opendata *opendata; |
| 1171 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1172 | 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] | 1173 | if (opendata == NULL) |
| 1174 | return ERR_PTR(-ENOMEM); |
| 1175 | opendata->state = state; |
| 1176 | atomic_inc(&state->count); |
| 1177 | return opendata; |
| 1178 | } |
| 1179 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1180 | 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] | 1181 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1182 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1183 | int ret; |
| 1184 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1185 | opendata->o_arg.open_flags = 0; |
| 1186 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1187 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1188 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1189 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1190 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1191 | if (ret != 0) |
| 1192 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1193 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1194 | if (IS_ERR(newstate)) |
| 1195 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1196 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1197 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1202 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1203 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1204 | int ret; |
| 1205 | |
| 1206 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1207 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1208 | smp_rmb(); |
| 1209 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1210 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1211 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1212 | if (ret != 0) |
| 1213 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1214 | if (newstate != state) |
| 1215 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1216 | } |
| 1217 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1218 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1219 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1220 | if (ret != 0) |
| 1221 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1222 | if (newstate != state) |
| 1223 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1224 | } |
| 1225 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1226 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1227 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1228 | if (ret != 0) |
| 1229 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1230 | if (newstate != state) |
| 1231 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1232 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1233 | /* |
| 1234 | * We may have performed cached opens for all three recoveries. |
| 1235 | * Check if we need to update the current stateid. |
| 1236 | */ |
| 1237 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1238 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1239 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1240 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1241 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1242 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1243 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1244 | return 0; |
| 1245 | } |
| 1246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | /* |
| 1248 | * OPEN_RECLAIM: |
| 1249 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1251 | 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] | 1252 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1253 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1254 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1255 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | int status; |
| 1257 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1258 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1259 | if (IS_ERR(opendata)) |
| 1260 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1261 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1262 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1263 | rcu_read_lock(); |
| 1264 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1265 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1266 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1267 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1269 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1270 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | return status; |
| 1272 | } |
| 1273 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1274 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | { |
| 1276 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1277 | struct nfs4_exception exception = { }; |
| 1278 | int err; |
| 1279 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1280 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1281 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1282 | break; |
| 1283 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | } while (exception.retry); |
| 1285 | return err; |
| 1286 | } |
| 1287 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1288 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1289 | { |
| 1290 | struct nfs_open_context *ctx; |
| 1291 | int ret; |
| 1292 | |
| 1293 | ctx = nfs4_state_find_open_context(state); |
| 1294 | if (IS_ERR(ctx)) |
| 1295 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1296 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1297 | put_nfs_open_context(ctx); |
| 1298 | return ret; |
| 1299 | } |
| 1300 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1301 | 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] | 1302 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1303 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1306 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1307 | if (IS_ERR(opendata)) |
| 1308 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1309 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1310 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1311 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1312 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1316 | 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] | 1317 | { |
| 1318 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1319 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | int err; |
| 1321 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1322 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | switch (err) { |
| 1324 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1325 | case -ENOENT: |
| 1326 | case -ESTALE: |
| 1327 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1328 | case -NFS4ERR_BADSESSION: |
| 1329 | case -NFS4ERR_BADSLOT: |
| 1330 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1331 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1332 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame^] | 1333 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1334 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | case -NFS4ERR_STALE_CLIENTID: |
| 1336 | case -NFS4ERR_STALE_STATEID: |
| 1337 | case -NFS4ERR_EXPIRED: |
| 1338 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1339 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1340 | goto out; |
| 1341 | case -ERESTARTSYS: |
| 1342 | /* |
| 1343 | * The show must go on: exit, but mark the |
| 1344 | * stateid as needing recovery. |
| 1345 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1346 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1347 | case -NFS4ERR_ADMIN_REVOKED: |
| 1348 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1349 | nfs_inode_find_state_and_recover(state->inode, |
| 1350 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1351 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1352 | case -EKEYEXPIRED: |
| 1353 | /* |
| 1354 | * User RPCSEC_GSS context has expired. |
| 1355 | * We cannot recover this stateid now, so |
| 1356 | * skip it and allow recovery thread to |
| 1357 | * proceed. |
| 1358 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1359 | case -ENOMEM: |
| 1360 | err = 0; |
| 1361 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } |
| 1363 | err = nfs4_handle_exception(server, err, &exception); |
| 1364 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1365 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | return err; |
| 1367 | } |
| 1368 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1369 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1370 | { |
| 1371 | struct nfs4_opendata *data = calldata; |
| 1372 | |
| 1373 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1374 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1375 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1376 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1377 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1378 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1379 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | static void nfs4_open_confirm_release(void *calldata) |
| 1383 | { |
| 1384 | struct nfs4_opendata *data = calldata; |
| 1385 | struct nfs4_state *state = NULL; |
| 1386 | |
| 1387 | /* If this request hasn't been cancelled, do nothing */ |
| 1388 | if (data->cancelled == 0) |
| 1389 | goto out_free; |
| 1390 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1391 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1392 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1393 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1394 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1395 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1396 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1397 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1401 | .rpc_call_done = nfs4_open_confirm_done, |
| 1402 | .rpc_release = nfs4_open_confirm_release, |
| 1403 | }; |
| 1404 | |
| 1405 | /* |
| 1406 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1407 | */ |
| 1408 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1409 | { |
| 1410 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1411 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1412 | struct rpc_message msg = { |
| 1413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1414 | .rpc_argp = &data->c_arg, |
| 1415 | .rpc_resp = &data->c_res, |
| 1416 | .rpc_cred = data->owner->so_cred, |
| 1417 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1418 | struct rpc_task_setup task_setup_data = { |
| 1419 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1420 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1421 | .callback_ops = &nfs4_open_confirm_ops, |
| 1422 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1423 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1424 | .flags = RPC_TASK_ASYNC, |
| 1425 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | int status; |
| 1427 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1428 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1429 | data->rpc_done = 0; |
| 1430 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1431 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1432 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1433 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1434 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1435 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1436 | if (status != 0) { |
| 1437 | data->cancelled = 1; |
| 1438 | smp_wmb(); |
| 1439 | } else |
| 1440 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1441 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | return status; |
| 1443 | } |
| 1444 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1445 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1447 | struct nfs4_opendata *data = calldata; |
| 1448 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1449 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1450 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1451 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1452 | /* |
| 1453 | * Check if we still need to send an OPEN call, or if we can use |
| 1454 | * a delegation instead. |
| 1455 | */ |
| 1456 | if (data->state != NULL) { |
| 1457 | struct nfs_delegation *delegation; |
| 1458 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1459 | 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] | 1460 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1461 | rcu_read_lock(); |
| 1462 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1463 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1464 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1465 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1466 | rcu_read_unlock(); |
| 1467 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1468 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1469 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1470 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1471 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1472 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1473 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1474 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1475 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1476 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1477 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1478 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1479 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1480 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1481 | unlock_no_action: |
| 1482 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1483 | out_no_action: |
| 1484 | task->tk_action = NULL; |
| 1485 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1488 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1489 | { |
| 1490 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1491 | nfs4_open_prepare(task, calldata); |
| 1492 | } |
| 1493 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1494 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1495 | { |
| 1496 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1498 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1499 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1500 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1501 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1502 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1503 | if (task->tk_status == 0) { |
| 1504 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1505 | case S_IFREG: |
| 1506 | break; |
| 1507 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1508 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1509 | break; |
| 1510 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1511 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1512 | break; |
| 1513 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1514 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1515 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1516 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1517 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1518 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1519 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1520 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1522 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1523 | static void nfs4_open_release(void *calldata) |
| 1524 | { |
| 1525 | struct nfs4_opendata *data = calldata; |
| 1526 | struct nfs4_state *state = NULL; |
| 1527 | |
| 1528 | /* If this request hasn't been cancelled, do nothing */ |
| 1529 | if (data->cancelled == 0) |
| 1530 | goto out_free; |
| 1531 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1532 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | goto out_free; |
| 1534 | /* In case we need an open_confirm, no cleanup! */ |
| 1535 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1536 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1537 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1538 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1539 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1540 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1541 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1545 | .rpc_call_prepare = nfs4_open_prepare, |
| 1546 | .rpc_call_done = nfs4_open_done, |
| 1547 | .rpc_release = nfs4_open_release, |
| 1548 | }; |
| 1549 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1550 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1551 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1552 | .rpc_call_done = nfs4_open_done, |
| 1553 | .rpc_release = nfs4_open_release, |
| 1554 | }; |
| 1555 | |
| 1556 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1557 | { |
| 1558 | struct inode *dir = data->dir->d_inode; |
| 1559 | struct nfs_server *server = NFS_SERVER(dir); |
| 1560 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1561 | struct nfs_openres *o_res = &data->o_res; |
| 1562 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1563 | struct rpc_message msg = { |
| 1564 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1565 | .rpc_argp = o_arg, |
| 1566 | .rpc_resp = o_res, |
| 1567 | .rpc_cred = data->owner->so_cred, |
| 1568 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1569 | struct rpc_task_setup task_setup_data = { |
| 1570 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1571 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1572 | .callback_ops = &nfs4_open_ops, |
| 1573 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1574 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1575 | .flags = RPC_TASK_ASYNC, |
| 1576 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1577 | int status; |
| 1578 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1579 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1580 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1581 | data->rpc_done = 0; |
| 1582 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1583 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1584 | if (isrecover) |
| 1585 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1586 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1587 | if (IS_ERR(task)) |
| 1588 | return PTR_ERR(task); |
| 1589 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1590 | if (status != 0) { |
| 1591 | data->cancelled = 1; |
| 1592 | smp_wmb(); |
| 1593 | } else |
| 1594 | status = data->rpc_status; |
| 1595 | rpc_put_task(task); |
| 1596 | |
| 1597 | return status; |
| 1598 | } |
| 1599 | |
| 1600 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1601 | { |
| 1602 | struct inode *dir = data->dir->d_inode; |
| 1603 | struct nfs_openres *o_res = &data->o_res; |
| 1604 | int status; |
| 1605 | |
| 1606 | status = nfs4_run_open_task(data, 1); |
| 1607 | if (status != 0 || !data->rpc_done) |
| 1608 | return status; |
| 1609 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1610 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1611 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1612 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1613 | status = _nfs4_proc_open_confirm(data); |
| 1614 | if (status != 0) |
| 1615 | return status; |
| 1616 | } |
| 1617 | |
| 1618 | return status; |
| 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1623 | */ |
| 1624 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1625 | { |
| 1626 | struct inode *dir = data->dir->d_inode; |
| 1627 | struct nfs_server *server = NFS_SERVER(dir); |
| 1628 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1629 | struct nfs_openres *o_res = &data->o_res; |
| 1630 | int status; |
| 1631 | |
| 1632 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1633 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1634 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1635 | if (status != 0) { |
| 1636 | if (status == -NFS4ERR_BADNAME && |
| 1637 | !(o_arg->open_flags & O_CREAT)) |
| 1638 | return -ENOENT; |
| 1639 | return status; |
| 1640 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1641 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1642 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1643 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1644 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1645 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1646 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1647 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1649 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1651 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | } |
| 1653 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1654 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1655 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1658 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1659 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1660 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1661 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1662 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1663 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1664 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1665 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1666 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1667 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1668 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1669 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1670 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1671 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1672 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1673 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1674 | } |
| 1675 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1676 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1677 | { |
| 1678 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1679 | } |
| 1680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | /* |
| 1682 | * OPEN_EXPIRED: |
| 1683 | * reclaim state on the server after a network partition. |
| 1684 | * Assumes caller holds the appropriate lock |
| 1685 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1686 | 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] | 1687 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1688 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1689 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1691 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1692 | if (IS_ERR(opendata)) |
| 1693 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1694 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1695 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1696 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1697 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1698 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1701 | 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] | 1702 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1703 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1704 | struct nfs4_exception exception = { }; |
| 1705 | int err; |
| 1706 | |
| 1707 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1708 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1709 | switch (err) { |
| 1710 | default: |
| 1711 | goto out; |
| 1712 | case -NFS4ERR_GRACE: |
| 1713 | case -NFS4ERR_DELAY: |
| 1714 | nfs4_handle_exception(server, err, &exception); |
| 1715 | err = 0; |
| 1716 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1717 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1718 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1719 | return err; |
| 1720 | } |
| 1721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1723 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1725 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1727 | ctx = nfs4_state_find_open_context(state); |
| 1728 | if (IS_ERR(ctx)) |
| 1729 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1730 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1731 | put_nfs_open_context(ctx); |
| 1732 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1735 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1736 | 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] | 1737 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1738 | int status = NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1739 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1740 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1741 | if (state->flags & flags) { |
| 1742 | status = nfs41_test_stateid(server, stateid); |
| 1743 | if (status != NFS_OK) { |
| 1744 | nfs41_free_stateid(server, stateid); |
| 1745 | state->flags &= ~flags; |
| 1746 | } |
| 1747 | } |
| 1748 | return status; |
| 1749 | } |
| 1750 | |
| 1751 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1752 | { |
| 1753 | int deleg_status, open_status; |
| 1754 | int deleg_flags = 1 << NFS_DELEGATED_STATE; |
| 1755 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); |
| 1756 | |
| 1757 | deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); |
| 1758 | open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags); |
| 1759 | |
| 1760 | if ((deleg_status == NFS_OK) && (open_status == NFS_OK)) |
| 1761 | return NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1762 | return nfs4_open_expired(sp, state); |
| 1763 | } |
| 1764 | #endif |
| 1765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1767 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1768 | * fields corresponding to attributes that were used to store the verifier. |
| 1769 | * Make sure we clobber those fields in the later setattr call |
| 1770 | */ |
| 1771 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1772 | { |
| 1773 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1774 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1775 | sattr->ia_valid |= ATTR_ATIME; |
| 1776 | |
| 1777 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1778 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1779 | sattr->ia_valid |= ATTR_MTIME; |
| 1780 | } |
| 1781 | |
| 1782 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1783 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1785 | static int _nfs4_do_open(struct inode *dir, |
| 1786 | struct dentry *dentry, |
| 1787 | fmode_t fmode, |
| 1788 | int flags, |
| 1789 | struct iattr *sattr, |
| 1790 | struct rpc_cred *cred, |
| 1791 | struct nfs4_state **res, |
| 1792 | struct nfs4_threshold **ctx_th) |
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 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1817 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1818 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1819 | if (!opendata->f_attr.mdsthreshold) |
| 1820 | goto err_opendata_put; |
| 1821 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1822 | if (dentry->d_inode != NULL) |
| 1823 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1824 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1825 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1827 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1829 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1830 | status = PTR_ERR(state); |
| 1831 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1832 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1833 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1834 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1835 | |
| 1836 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1837 | nfs4_exclusive_attrset(opendata, sattr); |
| 1838 | |
| 1839 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1840 | status = nfs4_do_setattr(state->inode, cred, |
| 1841 | opendata->o_res.f_attr, sattr, |
| 1842 | state); |
| 1843 | if (status == 0) |
| 1844 | nfs_setattr_update_inode(state->inode, sattr); |
| 1845 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1846 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1847 | |
| 1848 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1849 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1850 | else |
| 1851 | kfree(opendata->f_attr.mdsthreshold); |
| 1852 | opendata->f_attr.mdsthreshold = NULL; |
| 1853 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1854 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | *res = state; |
| 1857 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1858 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1859 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1860 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1861 | err_put_state_owner: |
| 1862 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | *res = NULL; |
| 1865 | return status; |
| 1866 | } |
| 1867 | |
| 1868 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1869 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1870 | struct dentry *dentry, |
| 1871 | fmode_t fmode, |
| 1872 | int flags, |
| 1873 | struct iattr *sattr, |
| 1874 | struct rpc_cred *cred, |
| 1875 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | { |
| 1877 | struct nfs4_exception exception = { }; |
| 1878 | struct nfs4_state *res; |
| 1879 | int status; |
| 1880 | |
| 1881 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1882 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1883 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | if (status == 0) |
| 1885 | break; |
| 1886 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1887 | * book-keeping w.r.t. state-changing operations |
| 1888 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1889 | * It is actually a sign of a bug on the client or on the server. |
| 1890 | * |
| 1891 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1892 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | * have unhashed the old state_owner for us, and that we can |
| 1894 | * therefore safely retry using a new one. We should still warn |
| 1895 | * the user though... |
| 1896 | */ |
| 1897 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 1898 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1899 | " returned a bad sequence-id error!\n", |
| 1900 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | exception.retry = 1; |
| 1902 | continue; |
| 1903 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1904 | /* |
| 1905 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1906 | * state before it received the OPEN_CONFIRM. |
| 1907 | * Recover by retrying the request as per the discussion |
| 1908 | * on Page 181 of RFC3530. |
| 1909 | */ |
| 1910 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1911 | exception.retry = 1; |
| 1912 | continue; |
| 1913 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1914 | if (status == -EAGAIN) { |
| 1915 | /* We must have found a delegation */ |
| 1916 | exception.retry = 1; |
| 1917 | continue; |
| 1918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1920 | status, &exception)); |
| 1921 | } while (exception.retry); |
| 1922 | return res; |
| 1923 | } |
| 1924 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1925 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1926 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1927 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1929 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1931 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | .iap = sattr, |
| 1933 | .server = server, |
| 1934 | .bitmask = server->attr_bitmask, |
| 1935 | }; |
| 1936 | struct nfs_setattrres res = { |
| 1937 | .fattr = fattr, |
| 1938 | .server = server, |
| 1939 | }; |
| 1940 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1941 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1942 | .rpc_argp = &arg, |
| 1943 | .rpc_resp = &res, |
| 1944 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1946 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1947 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1949 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 1951 | if (state != NULL) { |
| 1952 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
| 1953 | current->files, current->tgid); |
| 1954 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 1955 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1956 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1957 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1958 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1960 | 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] | 1961 | if (status == 0 && state != NULL) |
| 1962 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1963 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1966 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1967 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1968 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1970 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1971 | struct nfs4_exception exception = { |
| 1972 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 1973 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1974 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | int err; |
| 1976 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 1977 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 1978 | switch (err) { |
| 1979 | case -NFS4ERR_OPENMODE: |
| 1980 | if (state && !(state->state & FMODE_WRITE)) { |
| 1981 | err = -EBADF; |
| 1982 | if (sattr->ia_valid & ATTR_OPEN) |
| 1983 | err = -EACCES; |
| 1984 | goto out; |
| 1985 | } |
| 1986 | } |
| 1987 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 1989 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | return err; |
| 1991 | } |
| 1992 | |
| 1993 | struct nfs4_closedata { |
| 1994 | struct inode *inode; |
| 1995 | struct nfs4_state *state; |
| 1996 | struct nfs_closeargs arg; |
| 1997 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1998 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1999 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2000 | bool roc; |
| 2001 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | }; |
| 2003 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2004 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2005 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2006 | struct nfs4_closedata *calldata = data; |
| 2007 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2008 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2009 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2010 | if (calldata->roc) |
| 2011 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2012 | nfs4_put_open_state(calldata->state); |
| 2013 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2014 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2015 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2016 | kfree(calldata); |
| 2017 | } |
| 2018 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2019 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2020 | fmode_t fmode) |
| 2021 | { |
| 2022 | spin_lock(&state->owner->so_lock); |
| 2023 | if (!(fmode & FMODE_READ)) |
| 2024 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2025 | if (!(fmode & FMODE_WRITE)) |
| 2026 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2027 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2028 | spin_unlock(&state->owner->so_lock); |
| 2029 | } |
| 2030 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2031 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2033 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2036 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2037 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2038 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2039 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | /* hmm. we are done with the inode, and in the process of freeing |
| 2041 | * the state_owner. we keep this around to process errors |
| 2042 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | switch (task->tk_status) { |
| 2044 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2045 | if (calldata->roc) |
| 2046 | pnfs_roc_set_barrier(state->inode, |
| 2047 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2048 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2049 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2050 | nfs4_close_clear_stateid_flags(state, |
| 2051 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | break; |
| 2053 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2054 | case -NFS4ERR_OLD_STATEID: |
| 2055 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2057 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2058 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2060 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2061 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2063 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2064 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2065 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2068 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2070 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2071 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2072 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2073 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2074 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2075 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2076 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2077 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2078 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2079 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2080 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2081 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2082 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2083 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2084 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2085 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2086 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2087 | } |
| 2088 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2089 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2090 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2091 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2092 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2093 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2094 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2095 | |
| 2096 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2097 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2098 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2099 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2100 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2101 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2102 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2103 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2104 | if (calldata->roc && |
| 2105 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2106 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2107 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2108 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2109 | } |
| 2110 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2111 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2112 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2113 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2114 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2115 | &calldata->arg.seq_args, |
| 2116 | &calldata->res.seq_res, |
| 2117 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2118 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2119 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2120 | out: |
| 2121 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2124 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2125 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2126 | .rpc_call_done = nfs4_close_done, |
| 2127 | .rpc_release = nfs4_free_closedata, |
| 2128 | }; |
| 2129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | /* |
| 2131 | * It is possible for data to be read/written from a mem-mapped file |
| 2132 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2133 | * This means that we can't safely call nfsv4 close on a file until |
| 2134 | * the inode is cleared. This in turn means that we are not good |
| 2135 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2136 | * share state even when we are done with one of the three share |
| 2137 | * stateid's in the inode. |
| 2138 | * |
| 2139 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2140 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2141 | 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] | 2142 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2143 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2145 | struct nfs4_state_owner *sp = state->owner; |
| 2146 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2147 | struct rpc_message msg = { |
| 2148 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2149 | .rpc_cred = state->owner->so_cred, |
| 2150 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2151 | struct rpc_task_setup task_setup_data = { |
| 2152 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2153 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2154 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2155 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2156 | .flags = RPC_TASK_ASYNC, |
| 2157 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2158 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2160 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2162 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2163 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2164 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2166 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2167 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2169 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2170 | if (calldata->arg.seqid == NULL) |
| 2171 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2172 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2173 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2174 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2175 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2176 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2177 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2178 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2179 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2180 | msg.rpc_argp = &calldata->arg; |
| 2181 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2182 | task_setup_data.callback_data = calldata; |
| 2183 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2184 | if (IS_ERR(task)) |
| 2185 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2186 | status = 0; |
| 2187 | if (wait) |
| 2188 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2189 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2190 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2191 | out_free_calldata: |
| 2192 | kfree(calldata); |
| 2193 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2194 | if (roc) |
| 2195 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2196 | nfs4_put_open_state(state); |
| 2197 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2198 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2201 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2202 | 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] | 2203 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | struct nfs4_state *state; |
| 2205 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2206 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2207 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2208 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2209 | if (IS_ERR(state)) |
| 2210 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2211 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2212 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2215 | 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] | 2216 | { |
| 2217 | if (ctx->state == NULL) |
| 2218 | return; |
| 2219 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2220 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2221 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2222 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
| 2225 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2226 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2227 | struct nfs4_server_caps_arg args = { |
| 2228 | .fhandle = fhandle, |
| 2229 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | struct nfs4_server_caps_res res = {}; |
| 2231 | struct rpc_message msg = { |
| 2232 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2233 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | .rpc_resp = &res, |
| 2235 | }; |
| 2236 | int status; |
| 2237 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2238 | 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] | 2239 | if (status == 0) { |
| 2240 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2241 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2242 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2243 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2244 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2245 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2247 | server->caps |= NFS_CAP_ACLS; |
| 2248 | if (res.has_links != 0) |
| 2249 | server->caps |= NFS_CAP_HARDLINKS; |
| 2250 | if (res.has_symlinks != 0) |
| 2251 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2252 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2253 | server->caps |= NFS_CAP_FILEID; |
| 2254 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2255 | server->caps |= NFS_CAP_MODE; |
| 2256 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2257 | server->caps |= NFS_CAP_NLINK; |
| 2258 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2259 | server->caps |= NFS_CAP_OWNER; |
| 2260 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2261 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2262 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2263 | server->caps |= NFS_CAP_ATIME; |
| 2264 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2265 | server->caps |= NFS_CAP_CTIME; |
| 2266 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2267 | server->caps |= NFS_CAP_MTIME; |
| 2268 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2269 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2270 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2271 | 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] | 2272 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2273 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | return status; |
| 2277 | } |
| 2278 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2279 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | { |
| 2281 | struct nfs4_exception exception = { }; |
| 2282 | int err; |
| 2283 | do { |
| 2284 | err = nfs4_handle_exception(server, |
| 2285 | _nfs4_server_capabilities(server, fhandle), |
| 2286 | &exception); |
| 2287 | } while (exception.retry); |
| 2288 | return err; |
| 2289 | } |
| 2290 | |
| 2291 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2292 | struct nfs_fsinfo *info) |
| 2293 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | struct nfs4_lookup_root_arg args = { |
| 2295 | .bitmask = nfs4_fattr_bitmap, |
| 2296 | }; |
| 2297 | struct nfs4_lookup_res res = { |
| 2298 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2299 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | .fh = fhandle, |
| 2301 | }; |
| 2302 | struct rpc_message msg = { |
| 2303 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2304 | .rpc_argp = &args, |
| 2305 | .rpc_resp = &res, |
| 2306 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2307 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2308 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2309 | 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] | 2310 | } |
| 2311 | |
| 2312 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2313 | struct nfs_fsinfo *info) |
| 2314 | { |
| 2315 | struct nfs4_exception exception = { }; |
| 2316 | int err; |
| 2317 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2318 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2319 | switch (err) { |
| 2320 | case 0: |
| 2321 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2322 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2323 | default: |
| 2324 | err = nfs4_handle_exception(server, err, &exception); |
| 2325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2327 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | return err; |
| 2329 | } |
| 2330 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2331 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2332 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2333 | { |
| 2334 | struct rpc_auth *auth; |
| 2335 | int ret; |
| 2336 | |
| 2337 | auth = rpcauth_create(flavor, server->client); |
| 2338 | if (!auth) { |
| 2339 | ret = -EIO; |
| 2340 | goto out; |
| 2341 | } |
| 2342 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2343 | out: |
| 2344 | return ret; |
| 2345 | } |
| 2346 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2347 | 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] | 2348 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2350 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2351 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2353 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2354 | flav_array[len] = RPC_AUTH_NULL; |
| 2355 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2356 | |
| 2357 | for (i = 0; i < len; i++) { |
| 2358 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2359 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2360 | continue; |
| 2361 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2362 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2363 | /* |
| 2364 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2365 | * to access the mount. It could also mean that we tried to mount |
| 2366 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2367 | * existing mount programs don't handle -EACCES very well so it should |
| 2368 | * be mapped to -EPERM instead. |
| 2369 | */ |
| 2370 | if (status == -EACCES) |
| 2371 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2372 | return status; |
| 2373 | } |
| 2374 | |
| 2375 | /* |
| 2376 | * get the file handle for the "/" directory on the server |
| 2377 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2378 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2379 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2380 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2381 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2382 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2383 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2384 | /* |
| 2385 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2386 | * by nfs4_map_errors() as this function exits. |
| 2387 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2388 | 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] | 2389 | if (status == 0) |
| 2390 | status = nfs4_server_capabilities(server, fhandle); |
| 2391 | if (status == 0) |
| 2392 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2393 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2396 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2397 | struct nfs_fsinfo *info) |
| 2398 | { |
| 2399 | int error; |
| 2400 | struct nfs_fattr *fattr = info->fattr; |
| 2401 | |
| 2402 | error = nfs4_server_capabilities(server, mntfh); |
| 2403 | if (error < 0) { |
| 2404 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2405 | return error; |
| 2406 | } |
| 2407 | |
| 2408 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2409 | if (error < 0) { |
| 2410 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2411 | return error; |
| 2412 | } |
| 2413 | |
| 2414 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2415 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2416 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2417 | |
| 2418 | return error; |
| 2419 | } |
| 2420 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2421 | /* |
| 2422 | * Get locations and (maybe) other attributes of a referral. |
| 2423 | * Note that we'll actually follow the referral later when |
| 2424 | * we detect fsid mismatch in inode revalidation |
| 2425 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2426 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2427 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2428 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2429 | { |
| 2430 | int status = -ENOMEM; |
| 2431 | struct page *page = NULL; |
| 2432 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2433 | |
| 2434 | page = alloc_page(GFP_KERNEL); |
| 2435 | if (page == NULL) |
| 2436 | goto out; |
| 2437 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2438 | if (locations == NULL) |
| 2439 | goto out; |
| 2440 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2441 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2442 | if (status != 0) |
| 2443 | goto out; |
| 2444 | /* Make sure server returned a different fsid for the referral */ |
| 2445 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2446 | dprintk("%s: server did not return a different fsid for" |
| 2447 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2448 | status = -EIO; |
| 2449 | goto out; |
| 2450 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2451 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2452 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2453 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2454 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2455 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2456 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2457 | out: |
| 2458 | if (page) |
| 2459 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2460 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2461 | return status; |
| 2462 | } |
| 2463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2465 | { |
| 2466 | struct nfs4_getattr_arg args = { |
| 2467 | .fh = fhandle, |
| 2468 | .bitmask = server->attr_bitmask, |
| 2469 | }; |
| 2470 | struct nfs4_getattr_res res = { |
| 2471 | .fattr = fattr, |
| 2472 | .server = server, |
| 2473 | }; |
| 2474 | struct rpc_message msg = { |
| 2475 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2476 | .rpc_argp = &args, |
| 2477 | .rpc_resp = &res, |
| 2478 | }; |
| 2479 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2480 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2481 | 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] | 2482 | } |
| 2483 | |
| 2484 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2485 | { |
| 2486 | struct nfs4_exception exception = { }; |
| 2487 | int err; |
| 2488 | do { |
| 2489 | err = nfs4_handle_exception(server, |
| 2490 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2491 | &exception); |
| 2492 | } while (exception.retry); |
| 2493 | return err; |
| 2494 | } |
| 2495 | |
| 2496 | /* |
| 2497 | * The file is not closed if it is opened due to the a request to change |
| 2498 | * the size of the file. The open call will not be needed once the |
| 2499 | * VFS layer lookup-intents are implemented. |
| 2500 | * |
| 2501 | * Close is called when the inode is destroyed. |
| 2502 | * If we haven't opened the file for O_WRONLY, we |
| 2503 | * need to in the size_change case to obtain a stateid. |
| 2504 | * |
| 2505 | * Got race? |
| 2506 | * Because OPEN is always done by name in nfsv4, it is |
| 2507 | * possible that we opened a different file by the same |
| 2508 | * name. We can recognize this race condition, but we |
| 2509 | * can't do anything about it besides returning an error. |
| 2510 | * |
| 2511 | * This will be fixed with VFS changes (lookup-intent). |
| 2512 | */ |
| 2513 | static int |
| 2514 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2515 | struct iattr *sattr) |
| 2516 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2517 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2518 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2519 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | int status; |
| 2521 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2522 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2523 | pnfs_return_layout(inode); |
| 2524 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2525 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2527 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2528 | if (sattr->ia_valid & ATTR_FILE) { |
| 2529 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2530 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2531 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2532 | if (ctx) { |
| 2533 | cred = ctx->cred; |
| 2534 | state = ctx->state; |
| 2535 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2536 | } |
| 2537 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 2538 | /* Deal with open(O_TRUNC) */ |
| 2539 | if (sattr->ia_valid & ATTR_OPEN) |
| 2540 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2541 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2542 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2543 | if (status == 0) |
| 2544 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | return status; |
| 2546 | } |
| 2547 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2548 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2549 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2550 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2551 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2552 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2553 | int status; |
| 2554 | struct nfs4_lookup_arg args = { |
| 2555 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2556 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2557 | .name = name, |
| 2558 | }; |
| 2559 | struct nfs4_lookup_res res = { |
| 2560 | .server = server, |
| 2561 | .fattr = fattr, |
| 2562 | .fh = fhandle, |
| 2563 | }; |
| 2564 | struct rpc_message msg = { |
| 2565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2566 | .rpc_argp = &args, |
| 2567 | .rpc_resp = &res, |
| 2568 | }; |
| 2569 | |
| 2570 | nfs_fattr_init(fattr); |
| 2571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2573 | 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] | 2574 | dprintk("NFS reply lookup: %d\n", status); |
| 2575 | return status; |
| 2576 | } |
| 2577 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2578 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2579 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2580 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2581 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2582 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2583 | fattr->nlink = 2; |
| 2584 | } |
| 2585 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2586 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2587 | struct qstr *name, struct nfs_fh *fhandle, |
| 2588 | struct nfs_fattr *fattr) |
| 2589 | { |
| 2590 | struct nfs4_exception exception = { }; |
| 2591 | struct rpc_clnt *client = *clnt; |
| 2592 | int err; |
| 2593 | do { |
| 2594 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2595 | switch (err) { |
| 2596 | case -NFS4ERR_BADNAME: |
| 2597 | err = -ENOENT; |
| 2598 | goto out; |
| 2599 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2600 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2601 | goto out; |
| 2602 | case -NFS4ERR_WRONGSEC: |
| 2603 | err = -EPERM; |
| 2604 | if (client != *clnt) |
| 2605 | goto out; |
| 2606 | |
| 2607 | client = nfs4_create_sec_client(client, dir, name); |
| 2608 | if (IS_ERR(client)) |
| 2609 | return PTR_ERR(client); |
| 2610 | |
| 2611 | exception.retry = 1; |
| 2612 | break; |
| 2613 | default: |
| 2614 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2615 | } |
| 2616 | } while (exception.retry); |
| 2617 | |
| 2618 | out: |
| 2619 | if (err == 0) |
| 2620 | *clnt = client; |
| 2621 | else if (client != *clnt) |
| 2622 | rpc_shutdown_client(client); |
| 2623 | |
| 2624 | return err; |
| 2625 | } |
| 2626 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2627 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2628 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2630 | int status; |
| 2631 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2632 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2633 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2634 | if (client != NFS_CLIENT(dir)) { |
| 2635 | rpc_shutdown_client(client); |
| 2636 | nfs_fixup_secinfo_attributes(fattr); |
| 2637 | } |
| 2638 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2641 | struct rpc_clnt * |
| 2642 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2643 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2644 | { |
| 2645 | int status; |
| 2646 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2647 | |
| 2648 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2649 | if (status < 0) { |
| 2650 | rpc_shutdown_client(client); |
| 2651 | return ERR_PTR(status); |
| 2652 | } |
| 2653 | return client; |
| 2654 | } |
| 2655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2657 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2658 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | struct nfs4_accessargs args = { |
| 2660 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2661 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2663 | struct nfs4_accessres res = { |
| 2664 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2665 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | struct rpc_message msg = { |
| 2667 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2668 | .rpc_argp = &args, |
| 2669 | .rpc_resp = &res, |
| 2670 | .rpc_cred = entry->cred, |
| 2671 | }; |
| 2672 | int mode = entry->mask; |
| 2673 | int status; |
| 2674 | |
| 2675 | /* |
| 2676 | * Determine which access bits we want to ask for... |
| 2677 | */ |
| 2678 | if (mode & MAY_READ) |
| 2679 | args.access |= NFS4_ACCESS_READ; |
| 2680 | if (S_ISDIR(inode->i_mode)) { |
| 2681 | if (mode & MAY_WRITE) |
| 2682 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2683 | if (mode & MAY_EXEC) |
| 2684 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2685 | } else { |
| 2686 | if (mode & MAY_WRITE) |
| 2687 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2688 | if (mode & MAY_EXEC) |
| 2689 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2690 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2691 | |
| 2692 | res.fattr = nfs_alloc_fattr(); |
| 2693 | if (res.fattr == NULL) |
| 2694 | return -ENOMEM; |
| 2695 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2696 | 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] | 2697 | if (!status) { |
| 2698 | entry->mask = 0; |
| 2699 | if (res.access & NFS4_ACCESS_READ) |
| 2700 | entry->mask |= MAY_READ; |
| 2701 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2702 | entry->mask |= MAY_WRITE; |
| 2703 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2704 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2705 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2707 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | return status; |
| 2709 | } |
| 2710 | |
| 2711 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2712 | { |
| 2713 | struct nfs4_exception exception = { }; |
| 2714 | int err; |
| 2715 | do { |
| 2716 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2717 | _nfs4_proc_access(inode, entry), |
| 2718 | &exception); |
| 2719 | } while (exception.retry); |
| 2720 | return err; |
| 2721 | } |
| 2722 | |
| 2723 | /* |
| 2724 | * TODO: For the time being, we don't try to get any attributes |
| 2725 | * along with any of the zero-copy operations READ, READDIR, |
| 2726 | * READLINK, WRITE. |
| 2727 | * |
| 2728 | * In the case of the first three, we want to put the GETATTR |
| 2729 | * after the read-type operation -- this is because it is hard |
| 2730 | * to predict the length of a GETATTR response in v4, and thus |
| 2731 | * align the READ data correctly. This means that the GETATTR |
| 2732 | * may end up partially falling into the page cache, and we should |
| 2733 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2734 | * To do this efficiently, we need to know the total length |
| 2735 | * of data received, which doesn't seem to be available outside |
| 2736 | * of the RPC layer. |
| 2737 | * |
| 2738 | * In the case of WRITE, we also want to put the GETATTR after |
| 2739 | * the operation -- in this case because we want to make sure |
| 2740 | * we get the post-operation mtime and size. This means that |
| 2741 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2742 | * of it which would leave room in the 'tail' iovec. |
| 2743 | * |
| 2744 | * Both of these changes to the XDR layer would in fact be quite |
| 2745 | * minor, but I decided to leave them for a subsequent patch. |
| 2746 | */ |
| 2747 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2748 | unsigned int pgbase, unsigned int pglen) |
| 2749 | { |
| 2750 | struct nfs4_readlink args = { |
| 2751 | .fh = NFS_FH(inode), |
| 2752 | .pgbase = pgbase, |
| 2753 | .pglen = pglen, |
| 2754 | .pages = &page, |
| 2755 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2756 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | struct rpc_message msg = { |
| 2758 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2759 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2760 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | }; |
| 2762 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2763 | 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] | 2764 | } |
| 2765 | |
| 2766 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2767 | unsigned int pgbase, unsigned int pglen) |
| 2768 | { |
| 2769 | struct nfs4_exception exception = { }; |
| 2770 | int err; |
| 2771 | do { |
| 2772 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2773 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2774 | &exception); |
| 2775 | } while (exception.retry); |
| 2776 | return err; |
| 2777 | } |
| 2778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | /* |
| 2780 | * Got race? |
| 2781 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2782 | * Until then, this create/open method is prone to inefficiency and race |
| 2783 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2784 | * placed on the wire. |
| 2785 | * |
| 2786 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2787 | * The file will be opened again in the subsequent VFS open call |
| 2788 | * (nfs4_proc_file_open). |
| 2789 | * |
| 2790 | * The open for read will just hang around to be used by any process that |
| 2791 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2792 | */ |
| 2793 | |
| 2794 | static int |
| 2795 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2796 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2798 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2800 | struct rpc_cred *cred = NULL; |
| 2801 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | int status = 0; |
| 2803 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2804 | if (ctx != NULL) { |
| 2805 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2806 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2807 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2809 | sattr->ia_mode &= ~current_umask(); |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2810 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred, NULL); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2811 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | if (IS_ERR(state)) { |
| 2813 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2814 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2816 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2817 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2818 | if (ctx != NULL) |
| 2819 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2820 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2821 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | out: |
| 2823 | return status; |
| 2824 | } |
| 2825 | |
| 2826 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2827 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2828 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2829 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2831 | .name.len = name->len, |
| 2832 | .name.name = name->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2834 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2835 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2836 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2838 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2839 | .rpc_argp = &args, |
| 2840 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2842 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2843 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2844 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2845 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2846 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | return status; |
| 2848 | } |
| 2849 | |
| 2850 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2851 | { |
| 2852 | struct nfs4_exception exception = { }; |
| 2853 | int err; |
| 2854 | do { |
| 2855 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2856 | _nfs4_proc_remove(dir, name), |
| 2857 | &exception); |
| 2858 | } while (exception.retry); |
| 2859 | return err; |
| 2860 | } |
| 2861 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2862 | 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] | 2863 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2864 | struct nfs_server *server = NFS_SERVER(dir); |
| 2865 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2866 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2868 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2870 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2873 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2874 | { |
| 2875 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2876 | &data->args.seq_args, |
| 2877 | &data->res.seq_res, |
| 2878 | task)) |
| 2879 | return; |
| 2880 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2883 | 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] | 2884 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2885 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2886 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2887 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2888 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2889 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2890 | return 0; |
| 2891 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2892 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2895 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2896 | { |
| 2897 | struct nfs_server *server = NFS_SERVER(dir); |
| 2898 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2899 | struct nfs_renameres *res = msg->rpc_resp; |
| 2900 | |
| 2901 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2902 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2903 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2904 | } |
| 2905 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 2906 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 2907 | { |
| 2908 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 2909 | &data->args.seq_args, |
| 2910 | &data->res.seq_res, |
| 2911 | task)) |
| 2912 | return; |
| 2913 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2917 | struct inode *new_dir) |
| 2918 | { |
| 2919 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2920 | |
| 2921 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2922 | return 0; |
| 2923 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2924 | return 0; |
| 2925 | |
| 2926 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2927 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2928 | return 1; |
| 2929 | } |
| 2930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2932 | struct inode *new_dir, struct qstr *new_name) |
| 2933 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2934 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2935 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | .old_dir = NFS_FH(old_dir), |
| 2937 | .new_dir = NFS_FH(new_dir), |
| 2938 | .old_name = old_name, |
| 2939 | .new_name = new_name, |
| 2940 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2941 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2942 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2943 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | struct rpc_message msg = { |
| 2945 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2946 | .rpc_argp = &arg, |
| 2947 | .rpc_resp = &res, |
| 2948 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2949 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2951 | 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] | 2952 | if (!status) { |
| 2953 | update_changeattr(old_dir, &res.old_cinfo); |
| 2954 | update_changeattr(new_dir, &res.new_cinfo); |
| 2955 | } |
| 2956 | return status; |
| 2957 | } |
| 2958 | |
| 2959 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2960 | struct inode *new_dir, struct qstr *new_name) |
| 2961 | { |
| 2962 | struct nfs4_exception exception = { }; |
| 2963 | int err; |
| 2964 | do { |
| 2965 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2966 | _nfs4_proc_rename(old_dir, old_name, |
| 2967 | new_dir, new_name), |
| 2968 | &exception); |
| 2969 | } while (exception.retry); |
| 2970 | return err; |
| 2971 | } |
| 2972 | |
| 2973 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2974 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2975 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | struct nfs4_link_arg arg = { |
| 2977 | .fh = NFS_FH(inode), |
| 2978 | .dir_fh = NFS_FH(dir), |
| 2979 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2980 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2982 | struct nfs4_link_res res = { |
| 2983 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2984 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | struct rpc_message msg = { |
| 2986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2987 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2988 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2990 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2992 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2993 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2994 | goto out; |
| 2995 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2996 | 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] | 2997 | if (!status) { |
| 2998 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2999 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3000 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3001 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3002 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | return status; |
| 3004 | } |
| 3005 | |
| 3006 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3007 | { |
| 3008 | struct nfs4_exception exception = { }; |
| 3009 | int err; |
| 3010 | do { |
| 3011 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3012 | _nfs4_proc_link(inode, dir, name), |
| 3013 | &exception); |
| 3014 | } while (exception.retry); |
| 3015 | return err; |
| 3016 | } |
| 3017 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3018 | struct nfs4_createdata { |
| 3019 | struct rpc_message msg; |
| 3020 | struct nfs4_create_arg arg; |
| 3021 | struct nfs4_create_res res; |
| 3022 | struct nfs_fh fh; |
| 3023 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3024 | }; |
| 3025 | |
| 3026 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3027 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3028 | { |
| 3029 | struct nfs4_createdata *data; |
| 3030 | |
| 3031 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3032 | if (data != NULL) { |
| 3033 | struct nfs_server *server = NFS_SERVER(dir); |
| 3034 | |
| 3035 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3036 | data->msg.rpc_argp = &data->arg; |
| 3037 | data->msg.rpc_resp = &data->res; |
| 3038 | data->arg.dir_fh = NFS_FH(dir); |
| 3039 | data->arg.server = server; |
| 3040 | data->arg.name = name; |
| 3041 | data->arg.attrs = sattr; |
| 3042 | data->arg.ftype = ftype; |
| 3043 | data->arg.bitmask = server->attr_bitmask; |
| 3044 | data->res.server = server; |
| 3045 | data->res.fh = &data->fh; |
| 3046 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3047 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3048 | } |
| 3049 | return data; |
| 3050 | } |
| 3051 | |
| 3052 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3053 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3054 | 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] | 3055 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3056 | if (status == 0) { |
| 3057 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3058 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3059 | } |
| 3060 | return status; |
| 3061 | } |
| 3062 | |
| 3063 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3064 | { |
| 3065 | kfree(data); |
| 3066 | } |
| 3067 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3068 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3069 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3071 | struct nfs4_createdata *data; |
| 3072 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3074 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3075 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3076 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3077 | status = -ENOMEM; |
| 3078 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3079 | if (data == NULL) |
| 3080 | goto out; |
| 3081 | |
| 3082 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3083 | data->arg.u.symlink.pages = &page; |
| 3084 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3086 | status = nfs4_do_create(dir, dentry, data); |
| 3087 | |
| 3088 | nfs4_free_createdata(data); |
| 3089 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | return status; |
| 3091 | } |
| 3092 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3093 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3094 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | { |
| 3096 | struct nfs4_exception exception = { }; |
| 3097 | int err; |
| 3098 | do { |
| 3099 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3100 | _nfs4_proc_symlink(dir, dentry, page, |
| 3101 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | &exception); |
| 3103 | } while (exception.retry); |
| 3104 | return err; |
| 3105 | } |
| 3106 | |
| 3107 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3108 | struct iattr *sattr) |
| 3109 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3110 | struct nfs4_createdata *data; |
| 3111 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3113 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3114 | if (data == NULL) |
| 3115 | goto out; |
| 3116 | |
| 3117 | status = nfs4_do_create(dir, dentry, data); |
| 3118 | |
| 3119 | nfs4_free_createdata(data); |
| 3120 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | return status; |
| 3122 | } |
| 3123 | |
| 3124 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3125 | struct iattr *sattr) |
| 3126 | { |
| 3127 | struct nfs4_exception exception = { }; |
| 3128 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3129 | |
| 3130 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | do { |
| 3132 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3133 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3134 | &exception); |
| 3135 | } while (exception.retry); |
| 3136 | return err; |
| 3137 | } |
| 3138 | |
| 3139 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3140 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | { |
| 3142 | struct inode *dir = dentry->d_inode; |
| 3143 | struct nfs4_readdir_arg args = { |
| 3144 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3145 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | .pgbase = 0, |
| 3147 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3148 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3149 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | }; |
| 3151 | struct nfs4_readdir_res res; |
| 3152 | struct rpc_message msg = { |
| 3153 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3154 | .rpc_argp = &args, |
| 3155 | .rpc_resp = &res, |
| 3156 | .rpc_cred = cred, |
| 3157 | }; |
| 3158 | int status; |
| 3159 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3160 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3161 | dentry->d_parent->d_name.name, |
| 3162 | dentry->d_name.name, |
| 3163 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3165 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3166 | 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] | 3167 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3169 | status += args.pgbase; |
| 3170 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3171 | |
| 3172 | nfs_invalidate_atime(dir); |
| 3173 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3174 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | return status; |
| 3176 | } |
| 3177 | |
| 3178 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3179 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | { |
| 3181 | struct nfs4_exception exception = { }; |
| 3182 | int err; |
| 3183 | do { |
| 3184 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3185 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3186 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | &exception); |
| 3188 | } while (exception.retry); |
| 3189 | return err; |
| 3190 | } |
| 3191 | |
| 3192 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3193 | struct iattr *sattr, dev_t rdev) |
| 3194 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3195 | struct nfs4_createdata *data; |
| 3196 | int mode = sattr->ia_mode; |
| 3197 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | |
| 3199 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3200 | 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] | 3201 | |
| 3202 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3203 | if (data == NULL) |
| 3204 | goto out; |
| 3205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3207 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3209 | data->arg.ftype = NF4BLK; |
| 3210 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3211 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | } |
| 3213 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3214 | data->arg.ftype = NF4CHR; |
| 3215 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3216 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3219 | status = nfs4_do_create(dir, dentry, data); |
| 3220 | |
| 3221 | nfs4_free_createdata(data); |
| 3222 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | return status; |
| 3224 | } |
| 3225 | |
| 3226 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3227 | struct iattr *sattr, dev_t rdev) |
| 3228 | { |
| 3229 | struct nfs4_exception exception = { }; |
| 3230 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3231 | |
| 3232 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | do { |
| 3234 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3235 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3236 | &exception); |
| 3237 | } while (exception.retry); |
| 3238 | return err; |
| 3239 | } |
| 3240 | |
| 3241 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3242 | struct nfs_fsstat *fsstat) |
| 3243 | { |
| 3244 | struct nfs4_statfs_arg args = { |
| 3245 | .fh = fhandle, |
| 3246 | .bitmask = server->attr_bitmask, |
| 3247 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3248 | struct nfs4_statfs_res res = { |
| 3249 | .fsstat = fsstat, |
| 3250 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | struct rpc_message msg = { |
| 3252 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3253 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3254 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | }; |
| 3256 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3257 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3258 | 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] | 3259 | } |
| 3260 | |
| 3261 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3262 | { |
| 3263 | struct nfs4_exception exception = { }; |
| 3264 | int err; |
| 3265 | do { |
| 3266 | err = nfs4_handle_exception(server, |
| 3267 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3268 | &exception); |
| 3269 | } while (exception.retry); |
| 3270 | return err; |
| 3271 | } |
| 3272 | |
| 3273 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3274 | struct nfs_fsinfo *fsinfo) |
| 3275 | { |
| 3276 | struct nfs4_fsinfo_arg args = { |
| 3277 | .fh = fhandle, |
| 3278 | .bitmask = server->attr_bitmask, |
| 3279 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3280 | struct nfs4_fsinfo_res res = { |
| 3281 | .fsinfo = fsinfo, |
| 3282 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | struct rpc_message msg = { |
| 3284 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3285 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3286 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | }; |
| 3288 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3289 | 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] | 3290 | } |
| 3291 | |
| 3292 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3293 | { |
| 3294 | struct nfs4_exception exception = { }; |
| 3295 | int err; |
| 3296 | |
| 3297 | do { |
| 3298 | err = nfs4_handle_exception(server, |
| 3299 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3300 | &exception); |
| 3301 | } while (exception.retry); |
| 3302 | return err; |
| 3303 | } |
| 3304 | |
| 3305 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3306 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3307 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3309 | } |
| 3310 | |
| 3311 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3312 | struct nfs_pathconf *pathconf) |
| 3313 | { |
| 3314 | struct nfs4_pathconf_arg args = { |
| 3315 | .fh = fhandle, |
| 3316 | .bitmask = server->attr_bitmask, |
| 3317 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3318 | struct nfs4_pathconf_res res = { |
| 3319 | .pathconf = pathconf, |
| 3320 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | struct rpc_message msg = { |
| 3322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3323 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3324 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | }; |
| 3326 | |
| 3327 | /* None of the pathconf attributes are mandatory to implement */ |
| 3328 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3329 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3330 | return 0; |
| 3331 | } |
| 3332 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3333 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3334 | 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] | 3335 | } |
| 3336 | |
| 3337 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3338 | struct nfs_pathconf *pathconf) |
| 3339 | { |
| 3340 | struct nfs4_exception exception = { }; |
| 3341 | int err; |
| 3342 | |
| 3343 | do { |
| 3344 | err = nfs4_handle_exception(server, |
| 3345 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3346 | &exception); |
| 3347 | } while (exception.retry); |
| 3348 | return err; |
| 3349 | } |
| 3350 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3351 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3352 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3353 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3354 | } |
| 3355 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3356 | 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] | 3357 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3358 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3360 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3361 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3362 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3364 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3365 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3367 | renew_lease(server, data->timestamp); |
| 3368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3371 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3372 | { |
| 3373 | |
| 3374 | dprintk("--> %s\n", __func__); |
| 3375 | |
| 3376 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3377 | return -EAGAIN; |
| 3378 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3379 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3380 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3383 | 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] | 3384 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3386 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3387 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3388 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3391 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3392 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3393 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3394 | &data->args.seq_args, |
| 3395 | &data->res.seq_res, |
| 3396 | task)) |
| 3397 | return; |
| 3398 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3401 | 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] | 3402 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3403 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3405 | 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] | 3406 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3407 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3409 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3411 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3412 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3413 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3416 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3417 | { |
| 3418 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3419 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3420 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3421 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3424 | static |
| 3425 | bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data) |
| 3426 | { |
| 3427 | const struct nfs_pgio_header *hdr = data->header; |
| 3428 | |
| 3429 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3430 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3431 | return false; |
| 3432 | /* Otherwise, request attributes if and only if we don't hold |
| 3433 | * a delegation |
| 3434 | */ |
| 3435 | return nfs_have_delegation(hdr->inode, FMODE_READ) == 0; |
| 3436 | } |
| 3437 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3438 | 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] | 3439 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3440 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3441 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3442 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3443 | data->args.bitmask = NULL; |
| 3444 | data->res.fattr = NULL; |
| 3445 | } else |
| 3446 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3447 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3448 | if (!data->write_done_cb) |
| 3449 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3450 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | data->timestamp = jiffies; |
| 3452 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3453 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3454 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3457 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3458 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3459 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3460 | &data->args.seq_args, |
| 3461 | &data->res.seq_res, |
| 3462 | task)) |
| 3463 | return; |
| 3464 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3467 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3468 | { |
| 3469 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3470 | &data->args.seq_args, |
| 3471 | &data->res.seq_res, |
| 3472 | task)) |
| 3473 | return; |
| 3474 | rpc_call_start(task); |
| 3475 | } |
| 3476 | |
| 3477 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3480 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3481 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3482 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3483 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3485 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3488 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data) |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3489 | { |
| 3490 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3491 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3492 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3493 | } |
| 3494 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3495 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3497 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3498 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3499 | if (data->commit_done_cb == NULL) |
| 3500 | data->commit_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 | 16b4289 | 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 | 16b4289 | 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 | 16b4289 | 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 | 16b4289 | 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 | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame^] | 3909 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
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 | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3935 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 3936 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3937 | { |
| 3938 | __be32 verf[2]; |
| 3939 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 3940 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 3941 | /* An impossible timestamp guarantees this value |
| 3942 | * will never match a generated boot time. */ |
| 3943 | verf[0] = 0; |
| 3944 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 3945 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3946 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 3947 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 3948 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 3949 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 3950 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 3951 | } |
| 3952 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3953 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3954 | unsigned short port, struct rpc_cred *cred, |
| 3955 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | { |
| 3957 | nfs4_verifier sc_verifier; |
| 3958 | struct nfs4_setclientid setclientid = { |
| 3959 | .sc_verifier = &sc_verifier, |
| 3960 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3961 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | }; |
| 3963 | struct rpc_message msg = { |
| 3964 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3965 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3966 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3967 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | int loop = 0; |
| 3970 | int status; |
| 3971 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 3972 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | |
| 3974 | for(;;) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3975 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3977 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3978 | clp->cl_ipaddr, |
| 3979 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3980 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3981 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3982 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3983 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | clp->cl_id_uniquifier); |
| 3985 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3986 | sizeof(setclientid.sc_netid), |
| 3987 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3988 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3990 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | clp->cl_ipaddr, port >> 8, port & 255); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3992 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3994 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | if (status != -NFS4ERR_CLID_INUSE) |
| 3996 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3997 | if (loop != 0) { |
| 3998 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4000 | } |
| 4001 | ++loop; |
| 4002 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | } |
| 4004 | return status; |
| 4005 | } |
| 4006 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4007 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4008 | struct nfs4_setclientid_res *arg, |
| 4009 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | { |
| 4011 | struct nfs_fsinfo fsinfo; |
| 4012 | struct rpc_message msg = { |
| 4013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4014 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4016 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | }; |
| 4018 | unsigned long now; |
| 4019 | int status; |
| 4020 | |
| 4021 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4022 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | if (status == 0) { |
| 4024 | spin_lock(&clp->cl_lock); |
| 4025 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4026 | clp->cl_last_renewal = now; |
| 4027 | spin_unlock(&clp->cl_lock); |
| 4028 | } |
| 4029 | return status; |
| 4030 | } |
| 4031 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4032 | struct nfs4_delegreturndata { |
| 4033 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4034 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4035 | struct nfs_fh fh; |
| 4036 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4037 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4038 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4039 | int rpc_status; |
| 4040 | }; |
| 4041 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4042 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4043 | { |
| 4044 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4045 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4046 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4047 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4048 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4049 | switch (task->tk_status) { |
| 4050 | case -NFS4ERR_STALE_STATEID: |
| 4051 | case -NFS4ERR_EXPIRED: |
| 4052 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4053 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4054 | break; |
| 4055 | default: |
| 4056 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4057 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4058 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4059 | return; |
| 4060 | } |
| 4061 | } |
| 4062 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | static void nfs4_delegreturn_release(void *calldata) |
| 4066 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4067 | kfree(calldata); |
| 4068 | } |
| 4069 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4070 | #if defined(CONFIG_NFS_V4_1) |
| 4071 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4072 | { |
| 4073 | struct nfs4_delegreturndata *d_data; |
| 4074 | |
| 4075 | d_data = (struct nfs4_delegreturndata *)data; |
| 4076 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4077 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4078 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4079 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4080 | return; |
| 4081 | rpc_call_start(task); |
| 4082 | } |
| 4083 | #endif /* CONFIG_NFS_V4_1 */ |
| 4084 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4085 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4086 | #if defined(CONFIG_NFS_V4_1) |
| 4087 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4088 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4089 | .rpc_call_done = nfs4_delegreturn_done, |
| 4090 | .rpc_release = nfs4_delegreturn_release, |
| 4091 | }; |
| 4092 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4093 | 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] | 4094 | { |
| 4095 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4096 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4097 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4098 | struct rpc_message msg = { |
| 4099 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4100 | .rpc_cred = cred, |
| 4101 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4102 | struct rpc_task_setup task_setup_data = { |
| 4103 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4104 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4105 | .callback_ops = &nfs4_delegreturn_ops, |
| 4106 | .flags = RPC_TASK_ASYNC, |
| 4107 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4108 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4109 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4110 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4111 | if (data == NULL) |
| 4112 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4113 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4114 | data->args.fhandle = &data->fh; |
| 4115 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4116 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4117 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4118 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4119 | data->res.fattr = &data->fattr; |
| 4120 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4121 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4122 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4123 | data->rpc_status = 0; |
| 4124 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4125 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4126 | msg.rpc_argp = &data->args; |
| 4127 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4128 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4129 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4130 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4131 | if (!issync) |
| 4132 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4133 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4134 | if (status != 0) |
| 4135 | goto out; |
| 4136 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4137 | if (status == 0) |
| 4138 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4139 | else |
| 4140 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4141 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4142 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4143 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | } |
| 4145 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4146 | 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] | 4147 | { |
| 4148 | struct nfs_server *server = NFS_SERVER(inode); |
| 4149 | struct nfs4_exception exception = { }; |
| 4150 | int err; |
| 4151 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4152 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | switch (err) { |
| 4154 | case -NFS4ERR_STALE_STATEID: |
| 4155 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | case 0: |
| 4157 | return 0; |
| 4158 | } |
| 4159 | err = nfs4_handle_exception(server, err, &exception); |
| 4160 | } while (exception.retry); |
| 4161 | return err; |
| 4162 | } |
| 4163 | |
| 4164 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4165 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4166 | |
| 4167 | /* |
| 4168 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4169 | */ |
| 4170 | static unsigned long |
| 4171 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4172 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4173 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | timeout <<= 1; |
| 4175 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4176 | return NFS4_LOCK_MAXTIMEOUT; |
| 4177 | return timeout; |
| 4178 | } |
| 4179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4181 | { |
| 4182 | struct inode *inode = state->inode; |
| 4183 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4184 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4185 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4187 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4189 | struct nfs_lockt_res res = { |
| 4190 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | }; |
| 4192 | struct rpc_message msg = { |
| 4193 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4194 | .rpc_argp = &arg, |
| 4195 | .rpc_resp = &res, |
| 4196 | .rpc_cred = state->owner->so_cred, |
| 4197 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | struct nfs4_lock_state *lsp; |
| 4199 | int status; |
| 4200 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4201 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4202 | status = nfs4_set_lock_state(state, request); |
| 4203 | if (status != 0) |
| 4204 | goto out; |
| 4205 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4206 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4207 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4208 | 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] | 4209 | switch (status) { |
| 4210 | case 0: |
| 4211 | request->fl_type = F_UNLCK; |
| 4212 | break; |
| 4213 | case -NFS4ERR_DENIED: |
| 4214 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4216 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4217 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | return status; |
| 4219 | } |
| 4220 | |
| 4221 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4222 | { |
| 4223 | struct nfs4_exception exception = { }; |
| 4224 | int err; |
| 4225 | |
| 4226 | do { |
| 4227 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4228 | _nfs4_proc_getlk(state, cmd, request), |
| 4229 | &exception); |
| 4230 | } while (exception.retry); |
| 4231 | return err; |
| 4232 | } |
| 4233 | |
| 4234 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4235 | { |
| 4236 | int res = 0; |
| 4237 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4238 | case FL_POSIX: |
| 4239 | res = posix_lock_file_wait(file, fl); |
| 4240 | break; |
| 4241 | case FL_FLOCK: |
| 4242 | res = flock_lock_file_wait(file, fl); |
| 4243 | break; |
| 4244 | default: |
| 4245 | BUG(); |
| 4246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | return res; |
| 4248 | } |
| 4249 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4250 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4251 | struct nfs_locku_args arg; |
| 4252 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4253 | struct nfs4_lock_state *lsp; |
| 4254 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4255 | struct file_lock fl; |
| 4256 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4257 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4258 | }; |
| 4259 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4260 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4261 | struct nfs_open_context *ctx, |
| 4262 | struct nfs4_lock_state *lsp, |
| 4263 | struct nfs_seqid *seqid) |
| 4264 | { |
| 4265 | struct nfs4_unlockdata *p; |
| 4266 | struct inode *inode = lsp->ls_state->inode; |
| 4267 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4268 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4269 | if (p == NULL) |
| 4270 | return NULL; |
| 4271 | p->arg.fh = NFS_FH(inode); |
| 4272 | p->arg.fl = &p->fl; |
| 4273 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4274 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4275 | p->arg.stateid = &lsp->ls_stateid; |
| 4276 | p->lsp = lsp; |
| 4277 | atomic_inc(&lsp->ls_count); |
| 4278 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4279 | p->ctx = get_nfs_open_context(ctx); |
| 4280 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4281 | p->server = NFS_SERVER(inode); |
| 4282 | return p; |
| 4283 | } |
| 4284 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4285 | static void nfs4_locku_release_calldata(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 | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4288 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4289 | nfs4_put_lock_state(calldata->lsp); |
| 4290 | put_nfs_open_context(calldata->ctx); |
| 4291 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4294 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4295 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4296 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4297 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4298 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4299 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4300 | switch (task->tk_status) { |
| 4301 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4302 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4303 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4304 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4305 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4306 | case -NFS4ERR_BAD_STATEID: |
| 4307 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4308 | case -NFS4ERR_STALE_STATEID: |
| 4309 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4310 | break; |
| 4311 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4312 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4313 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4314 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4317 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4318 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4319 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4321 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4322 | return; |
| 4323 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4324 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4325 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4326 | return; |
| 4327 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4328 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4329 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4330 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4331 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4332 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4333 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4336 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4337 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4338 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4339 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4340 | }; |
| 4341 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4342 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4343 | struct nfs_open_context *ctx, |
| 4344 | struct nfs4_lock_state *lsp, |
| 4345 | struct nfs_seqid *seqid) |
| 4346 | { |
| 4347 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4348 | struct rpc_message msg = { |
| 4349 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4350 | .rpc_cred = ctx->cred, |
| 4351 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4352 | struct rpc_task_setup task_setup_data = { |
| 4353 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4354 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4355 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4356 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4357 | .flags = RPC_TASK_ASYNC, |
| 4358 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4359 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4360 | /* Ensure this is an unlock - when canceling a lock, the |
| 4361 | * canceled lock is passed in, and it won't be an unlock. |
| 4362 | */ |
| 4363 | fl->fl_type = F_UNLCK; |
| 4364 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4365 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4366 | if (data == NULL) { |
| 4367 | nfs_free_seqid(seqid); |
| 4368 | return ERR_PTR(-ENOMEM); |
| 4369 | } |
| 4370 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4371 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4372 | msg.rpc_argp = &data->arg; |
| 4373 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4374 | task_setup_data.callback_data = data; |
| 4375 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4376 | } |
| 4377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4379 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4380 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4381 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4382 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4383 | struct rpc_task *task; |
| 4384 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4385 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4387 | status = nfs4_set_lock_state(state, request); |
| 4388 | /* Unlock _before_ we do the RPC call */ |
| 4389 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4390 | down_read(&nfsi->rwsem); |
| 4391 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4392 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4393 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4394 | } |
| 4395 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4396 | if (status != 0) |
| 4397 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4398 | /* Is this a delegated lock? */ |
| 4399 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4400 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4401 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4402 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4403 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4404 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4405 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4406 | 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] | 4407 | status = PTR_ERR(task); |
| 4408 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4409 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4410 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4411 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4412 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4413 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4414 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4417 | struct nfs4_lockdata { |
| 4418 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4419 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4420 | struct nfs4_lock_state *lsp; |
| 4421 | struct nfs_open_context *ctx; |
| 4422 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4423 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4424 | int rpc_status; |
| 4425 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4426 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4427 | }; |
| 4428 | |
| 4429 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4430 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4431 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4432 | { |
| 4433 | struct nfs4_lockdata *p; |
| 4434 | struct inode *inode = lsp->ls_state->inode; |
| 4435 | struct nfs_server *server = NFS_SERVER(inode); |
| 4436 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4437 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4438 | if (p == NULL) |
| 4439 | return NULL; |
| 4440 | |
| 4441 | p->arg.fh = NFS_FH(inode); |
| 4442 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4443 | 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] | 4444 | if (p->arg.open_seqid == NULL) |
| 4445 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4446 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4447 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4448 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4449 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4450 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4451 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4452 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4453 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4454 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4455 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4456 | atomic_inc(&lsp->ls_count); |
| 4457 | p->ctx = get_nfs_open_context(ctx); |
| 4458 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4459 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4460 | out_free_seqid: |
| 4461 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4462 | out_free: |
| 4463 | kfree(p); |
| 4464 | return NULL; |
| 4465 | } |
| 4466 | |
| 4467 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4468 | { |
| 4469 | struct nfs4_lockdata *data = calldata; |
| 4470 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4472 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4473 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4474 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4475 | /* Do we need to do an open_to_lock_owner? */ |
| 4476 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4477 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4478 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4479 | data->arg.open_stateid = &state->stateid; |
| 4480 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4481 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4482 | } else |
| 4483 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4484 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4485 | if (nfs4_setup_sequence(data->server, |
| 4486 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4487 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4488 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4489 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4490 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4493 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4494 | { |
| 4495 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4496 | nfs4_lock_prepare(task, calldata); |
| 4497 | } |
| 4498 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4499 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4500 | { |
| 4501 | struct nfs4_lockdata *data = calldata; |
| 4502 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4503 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4504 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4505 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4506 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4507 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4508 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4509 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4510 | if (data->rpc_status == 0) |
| 4511 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4512 | else |
| 4513 | goto out; |
| 4514 | } |
| 4515 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4516 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4517 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4518 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4519 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4520 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4521 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | static void nfs4_lock_release(void *calldata) |
| 4525 | { |
| 4526 | struct nfs4_lockdata *data = calldata; |
| 4527 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4528 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4529 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4530 | if (data->cancelled != 0) { |
| 4531 | struct rpc_task *task; |
| 4532 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4533 | data->arg.lock_seqid); |
| 4534 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4535 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4536 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4537 | } else |
| 4538 | nfs_free_seqid(data->arg.lock_seqid); |
| 4539 | nfs4_put_lock_state(data->lsp); |
| 4540 | put_nfs_open_context(data->ctx); |
| 4541 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4542 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4546 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4547 | .rpc_call_done = nfs4_lock_done, |
| 4548 | .rpc_release = nfs4_lock_release, |
| 4549 | }; |
| 4550 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4551 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4552 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4553 | .rpc_call_done = nfs4_lock_done, |
| 4554 | .rpc_release = nfs4_lock_release, |
| 4555 | }; |
| 4556 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4557 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4558 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4559 | switch (error) { |
| 4560 | case -NFS4ERR_ADMIN_REVOKED: |
| 4561 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4562 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4563 | if (new_lock_owner != 0 || |
| 4564 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4565 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4566 | break; |
| 4567 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4568 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4569 | case -NFS4ERR_EXPIRED: |
| 4570 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4571 | }; |
| 4572 | } |
| 4573 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4574 | 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] | 4575 | { |
| 4576 | struct nfs4_lockdata *data; |
| 4577 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4578 | struct rpc_message msg = { |
| 4579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4580 | .rpc_cred = state->owner->so_cred, |
| 4581 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4582 | struct rpc_task_setup task_setup_data = { |
| 4583 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4584 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4585 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4586 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4587 | .flags = RPC_TASK_ASYNC, |
| 4588 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4589 | int ret; |
| 4590 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4591 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4592 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4593 | fl->fl_u.nfs4_fl.owner, |
| 4594 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4595 | if (data == NULL) |
| 4596 | return -ENOMEM; |
| 4597 | if (IS_SETLKW(cmd)) |
| 4598 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4599 | if (recovery_type > NFS_LOCK_NEW) { |
| 4600 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4601 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4602 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4603 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4604 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4605 | msg.rpc_argp = &data->arg; |
| 4606 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4607 | task_setup_data.callback_data = data; |
| 4608 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4609 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4610 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4611 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4612 | if (ret == 0) { |
| 4613 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4614 | if (ret) |
| 4615 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4616 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4617 | } else |
| 4618 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4619 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4620 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4621 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4625 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4626 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4627 | struct nfs4_exception exception = { |
| 4628 | .inode = state->inode, |
| 4629 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4630 | int err; |
| 4631 | |
| 4632 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4633 | /* Cache the lock if possible... */ |
| 4634 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4635 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4636 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4637 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4638 | break; |
| 4639 | nfs4_handle_exception(server, err, &exception); |
| 4640 | } while (exception.retry); |
| 4641 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4645 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4646 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4647 | struct nfs4_exception exception = { |
| 4648 | .inode = state->inode, |
| 4649 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4650 | int err; |
| 4651 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4652 | err = nfs4_set_lock_state(state, request); |
| 4653 | if (err != 0) |
| 4654 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4655 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4656 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4657 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4658 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4659 | switch (err) { |
| 4660 | default: |
| 4661 | goto out; |
| 4662 | case -NFS4ERR_GRACE: |
| 4663 | case -NFS4ERR_DELAY: |
| 4664 | nfs4_handle_exception(server, err, &exception); |
| 4665 | err = 0; |
| 4666 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4667 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4668 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4669 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4672 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4673 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4674 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4675 | int status, ret = NFS_OK; |
| 4676 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4677 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4678 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4679 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4680 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4681 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4682 | if (status != NFS_OK) { |
| 4683 | nfs41_free_stateid(server, &lsp->ls_stateid); |
| 4684 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4685 | ret = status; |
| 4686 | } |
| 4687 | } |
| 4688 | }; |
| 4689 | |
| 4690 | return ret; |
| 4691 | } |
| 4692 | |
| 4693 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4694 | { |
| 4695 | int status = NFS_OK; |
| 4696 | |
| 4697 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4698 | status = nfs41_check_expired_locks(state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4699 | if (status == NFS_OK) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4700 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4701 | return nfs4_lock_expired(state, request); |
| 4702 | } |
| 4703 | #endif |
| 4704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4706 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4707 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4708 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4709 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4711 | if ((fl_flags & FL_POSIX) && |
| 4712 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4713 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4714 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4715 | status = nfs4_set_lock_state(state, request); |
| 4716 | if (status != 0) |
| 4717 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4718 | request->fl_flags |= FL_ACCESS; |
| 4719 | status = do_vfs_lock(request->fl_file, request); |
| 4720 | if (status < 0) |
| 4721 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4722 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4723 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4724 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4725 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4726 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4727 | status = do_vfs_lock(request->fl_file, request); |
| 4728 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4729 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4730 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4731 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4732 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4733 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4734 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4735 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4736 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4737 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4738 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4739 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4740 | out: |
| 4741 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | return status; |
| 4743 | } |
| 4744 | |
| 4745 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4746 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4747 | struct nfs4_exception exception = { |
| 4748 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4749 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4750 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | int err; |
| 4752 | |
| 4753 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4754 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4755 | if (err == -NFS4ERR_DENIED) |
| 4756 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4758 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4759 | } while (exception.retry); |
| 4760 | return err; |
| 4761 | } |
| 4762 | |
| 4763 | static int |
| 4764 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4765 | { |
| 4766 | struct nfs_open_context *ctx; |
| 4767 | struct nfs4_state *state; |
| 4768 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4769 | int status; |
| 4770 | |
| 4771 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4772 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | state = ctx->state; |
| 4774 | |
| 4775 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4776 | return -EINVAL; |
| 4777 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4778 | if (IS_GETLK(cmd)) { |
| 4779 | if (state != NULL) |
| 4780 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4781 | return 0; |
| 4782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | |
| 4784 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4785 | return -EINVAL; |
| 4786 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4787 | if (request->fl_type == F_UNLCK) { |
| 4788 | if (state != NULL) |
| 4789 | return nfs4_proc_unlck(state, cmd, request); |
| 4790 | return 0; |
| 4791 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4793 | if (state == NULL) |
| 4794 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4795 | /* |
| 4796 | * Don't rely on the VFS having checked the file open mode, |
| 4797 | * since it won't do this for flock() locks. |
| 4798 | */ |
| 4799 | switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) { |
| 4800 | case F_RDLCK: |
| 4801 | if (!(filp->f_mode & FMODE_READ)) |
| 4802 | return -EBADF; |
| 4803 | break; |
| 4804 | case F_WRLCK: |
| 4805 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4806 | return -EBADF; |
| 4807 | } |
| 4808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | do { |
| 4810 | status = nfs4_proc_setlk(state, cmd, request); |
| 4811 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4812 | break; |
| 4813 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4814 | status = -ERESTARTSYS; |
| 4815 | if (signalled()) |
| 4816 | break; |
| 4817 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | return status; |
| 4819 | } |
| 4820 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4821 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4822 | { |
| 4823 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4824 | struct nfs4_exception exception = { }; |
| 4825 | int err; |
| 4826 | |
| 4827 | err = nfs4_set_lock_state(state, fl); |
| 4828 | if (err != 0) |
| 4829 | goto out; |
| 4830 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4831 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4832 | switch (err) { |
| 4833 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4834 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4835 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4836 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4837 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4838 | goto out; |
| 4839 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4840 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4841 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4842 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4843 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4844 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4845 | case -NFS4ERR_BADSESSION: |
| 4846 | case -NFS4ERR_BADSLOT: |
| 4847 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4848 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4849 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame^] | 4850 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4851 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4852 | case -ERESTARTSYS: |
| 4853 | /* |
| 4854 | * The show must go on: exit, but mark the |
| 4855 | * stateid as needing recovery. |
| 4856 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4857 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4858 | case -NFS4ERR_ADMIN_REVOKED: |
| 4859 | case -NFS4ERR_BAD_STATEID: |
| 4860 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4861 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4862 | err = 0; |
| 4863 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4864 | case -EKEYEXPIRED: |
| 4865 | /* |
| 4866 | * User RPCSEC_GSS context has expired. |
| 4867 | * We cannot recover this stateid now, so |
| 4868 | * skip it and allow recovery thread to |
| 4869 | * proceed. |
| 4870 | */ |
| 4871 | err = 0; |
| 4872 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4873 | case -ENOMEM: |
| 4874 | case -NFS4ERR_DENIED: |
| 4875 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4876 | err = 0; |
| 4877 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4878 | case -NFS4ERR_DELAY: |
| 4879 | break; |
| 4880 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4881 | err = nfs4_handle_exception(server, err, &exception); |
| 4882 | } while (exception.retry); |
| 4883 | out: |
| 4884 | return err; |
| 4885 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4886 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4887 | struct nfs_release_lockowner_data { |
| 4888 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4889 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4890 | struct nfs_release_lockowner_args args; |
| 4891 | }; |
| 4892 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4893 | static void nfs4_release_lockowner_release(void *calldata) |
| 4894 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4895 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4896 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4897 | kfree(calldata); |
| 4898 | } |
| 4899 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 4900 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4901 | .rpc_release = nfs4_release_lockowner_release, |
| 4902 | }; |
| 4903 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4904 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4905 | { |
| 4906 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4907 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4908 | struct rpc_message msg = { |
| 4909 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4910 | }; |
| 4911 | |
| 4912 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4913 | return -EINVAL; |
| 4914 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 4915 | if (!data) |
| 4916 | return -ENOMEM; |
| 4917 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 4918 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 4919 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4920 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 4921 | data->args.lock_owner.s_dev = server->s_dev; |
| 4922 | msg.rpc_argp = &data->args; |
| 4923 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 4924 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4925 | } |
| 4926 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4927 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4928 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4929 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4930 | const void *buf, size_t buflen, |
| 4931 | int flags, 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 | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4935 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4936 | return nfs4_proc_set_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 int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4940 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4941 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4942 | if (strcmp(key, "") != 0) |
| 4943 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4944 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4945 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4948 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4949 | size_t list_len, const char *name, |
| 4950 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4951 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4952 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4953 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4954 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4955 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4956 | |
| 4957 | if (list && len <= list_len) |
| 4958 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4959 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4962 | /* |
| 4963 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4964 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4965 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4966 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4967 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4968 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4969 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4970 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4971 | return; |
| 4972 | |
| 4973 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4974 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4975 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4976 | fattr->nlink = 2; |
| 4977 | } |
| 4978 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4979 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 4980 | const struct qstr *name, |
| 4981 | struct nfs4_fs_locations *fs_locations, |
| 4982 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4983 | { |
| 4984 | struct nfs_server *server = NFS_SERVER(dir); |
| 4985 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4986 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4987 | }; |
| 4988 | struct nfs4_fs_locations_arg args = { |
| 4989 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4990 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4991 | .page = page, |
| 4992 | .bitmask = bitmask, |
| 4993 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4994 | struct nfs4_fs_locations_res res = { |
| 4995 | .fs_locations = fs_locations, |
| 4996 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4997 | struct rpc_message msg = { |
| 4998 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4999 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5000 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5001 | }; |
| 5002 | int status; |
| 5003 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5004 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5005 | |
| 5006 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5007 | * is not supported */ |
| 5008 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5009 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5010 | else |
| 5011 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5012 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5013 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5014 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5015 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5016 | 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] | 5017 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5018 | return status; |
| 5019 | } |
| 5020 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5021 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5022 | const struct qstr *name, |
| 5023 | struct nfs4_fs_locations *fs_locations, |
| 5024 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5025 | { |
| 5026 | struct nfs4_exception exception = { }; |
| 5027 | int err; |
| 5028 | do { |
| 5029 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5030 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5031 | &exception); |
| 5032 | } while (exception.retry); |
| 5033 | return err; |
| 5034 | } |
| 5035 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5036 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5037 | { |
| 5038 | int status; |
| 5039 | struct nfs4_secinfo_arg args = { |
| 5040 | .dir_fh = NFS_FH(dir), |
| 5041 | .name = name, |
| 5042 | }; |
| 5043 | struct nfs4_secinfo_res res = { |
| 5044 | .flavors = flavors, |
| 5045 | }; |
| 5046 | struct rpc_message msg = { |
| 5047 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5048 | .rpc_argp = &args, |
| 5049 | .rpc_resp = &res, |
| 5050 | }; |
| 5051 | |
| 5052 | dprintk("NFS call secinfo %s\n", name->name); |
| 5053 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5054 | dprintk("NFS reply secinfo: %d\n", status); |
| 5055 | return status; |
| 5056 | } |
| 5057 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5058 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5059 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5060 | { |
| 5061 | struct nfs4_exception exception = { }; |
| 5062 | int err; |
| 5063 | do { |
| 5064 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5065 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5066 | &exception); |
| 5067 | } while (exception.retry); |
| 5068 | return err; |
| 5069 | } |
| 5070 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5071 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5072 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5073 | * Check the exchange flags returned by the server for invalid flags, having |
| 5074 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5075 | * DS flags set. |
| 5076 | */ |
| 5077 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5078 | { |
| 5079 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5080 | goto out_inval; |
| 5081 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5082 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5083 | goto out_inval; |
| 5084 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5085 | goto out_inval; |
| 5086 | return NFS_OK; |
| 5087 | out_inval: |
| 5088 | return -NFS4ERR_INVAL; |
| 5089 | } |
| 5090 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5091 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5092 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5093 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5094 | { |
| 5095 | if (a->server_scope_sz == b->server_scope_sz && |
| 5096 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5097 | return true; |
| 5098 | |
| 5099 | return false; |
| 5100 | } |
| 5101 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5102 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5103 | * nfs4_proc_bind_conn_to_session() |
| 5104 | * |
| 5105 | * The 4.1 client currently uses the same TCP connection for the |
| 5106 | * fore and backchannel. |
| 5107 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5108 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5109 | { |
| 5110 | int status; |
| 5111 | struct nfs41_bind_conn_to_session_res res; |
| 5112 | struct rpc_message msg = { |
| 5113 | .rpc_proc = |
| 5114 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5115 | .rpc_argp = clp, |
| 5116 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5117 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5118 | }; |
| 5119 | |
| 5120 | dprintk("--> %s\n", __func__); |
| 5121 | BUG_ON(clp == NULL); |
| 5122 | |
| 5123 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5124 | if (unlikely(res.session == NULL)) { |
| 5125 | status = -ENOMEM; |
| 5126 | goto out; |
| 5127 | } |
| 5128 | |
| 5129 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5130 | if (status == 0) { |
| 5131 | if (memcmp(res.session->sess_id.data, |
| 5132 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5133 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5134 | status = -EIO; |
| 5135 | goto out_session; |
| 5136 | } |
| 5137 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5138 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5139 | __func__); |
| 5140 | status = -EIO; |
| 5141 | goto out_session; |
| 5142 | } |
| 5143 | if (res.use_conn_in_rdma_mode) { |
| 5144 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5145 | __func__); |
| 5146 | status = -EIO; |
| 5147 | goto out_session; |
| 5148 | } |
| 5149 | } |
| 5150 | out_session: |
| 5151 | kfree(res.session); |
| 5152 | out: |
| 5153 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5154 | return status; |
| 5155 | } |
| 5156 | |
| 5157 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5158 | * nfs4_proc_exchange_id() |
| 5159 | * |
| 5160 | * Since the clientid has expired, all compounds using sessions |
| 5161 | * associated with the stale clientid will be returning |
| 5162 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5163 | * be in some phase of session reset. |
| 5164 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5165 | 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] | 5166 | { |
| 5167 | nfs4_verifier verifier; |
| 5168 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5169 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5170 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5171 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5172 | }; |
| 5173 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5174 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5175 | }; |
| 5176 | int status; |
| 5177 | struct rpc_message msg = { |
| 5178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5179 | .rpc_argp = &args, |
| 5180 | .rpc_resp = &res, |
| 5181 | .rpc_cred = cred, |
| 5182 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5183 | |
| 5184 | dprintk("--> %s\n", __func__); |
| 5185 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5186 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5187 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5188 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5189 | args.id_len = scnprintf(args.id, sizeof(args.id), |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5190 | "%s/%s/%u", |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5191 | clp->cl_ipaddr, |
Trond Myklebust | 3617e50 | 2012-04-30 12:04:58 -0400 | [diff] [blame] | 5192 | clp->cl_rpcclient->cl_nodename, |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 5193 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5194 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5195 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5196 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5197 | if (unlikely(res.server_owner == NULL)) { |
| 5198 | status = -ENOMEM; |
| 5199 | goto out; |
| 5200 | } |
| 5201 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5202 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5203 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5204 | if (unlikely(res.server_scope == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5205 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5206 | goto out_server_owner; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5207 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5208 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5209 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5210 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5211 | status = -ENOMEM; |
| 5212 | goto out_server_scope; |
| 5213 | } |
| 5214 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5215 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5216 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5217 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5218 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5219 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5220 | clp->cl_clientid = res.clientid; |
| 5221 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5222 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5223 | clp->cl_seqid = res.seqid; |
| 5224 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5225 | kfree(clp->cl_serverowner); |
| 5226 | clp->cl_serverowner = res.server_owner; |
| 5227 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5228 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5229 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5230 | kfree(clp->cl_implid); |
| 5231 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5232 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5233 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5234 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5235 | res.server_scope)) { |
| 5236 | dprintk("%s: server_scope mismatch detected\n", |
| 5237 | __func__); |
| 5238 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5239 | kfree(clp->cl_serverscope); |
| 5240 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5241 | } |
| 5242 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5243 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5244 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5245 | goto out; |
| 5246 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5247 | } else |
| 5248 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5249 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5250 | out_server_owner: |
| 5251 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5252 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5253 | kfree(res.server_scope); |
| 5254 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5255 | if (clp->cl_implid != NULL) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5256 | dprintk("%s: Server Implementation ID: " |
| 5257 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5258 | __func__, clp->cl_implid->domain, clp->cl_implid->name, |
| 5259 | clp->cl_implid->date.seconds, |
| 5260 | clp->cl_implid->date.nseconds); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5261 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5262 | return status; |
| 5263 | } |
| 5264 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5265 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5266 | struct rpc_cred *cred) |
| 5267 | { |
| 5268 | struct rpc_message msg = { |
| 5269 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5270 | .rpc_argp = clp, |
| 5271 | .rpc_cred = cred, |
| 5272 | }; |
| 5273 | int status; |
| 5274 | |
| 5275 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5276 | if (status) |
| 5277 | pr_warn("NFS: Got error %d from the server %s on " |
| 5278 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5279 | return status; |
| 5280 | } |
| 5281 | |
| 5282 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5283 | struct rpc_cred *cred) |
| 5284 | { |
| 5285 | unsigned int loop; |
| 5286 | int ret; |
| 5287 | |
| 5288 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5289 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5290 | switch (ret) { |
| 5291 | case -NFS4ERR_DELAY: |
| 5292 | case -NFS4ERR_CLIENTID_BUSY: |
| 5293 | ssleep(1); |
| 5294 | break; |
| 5295 | default: |
| 5296 | return ret; |
| 5297 | } |
| 5298 | } |
| 5299 | return 0; |
| 5300 | } |
| 5301 | |
| 5302 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5303 | { |
| 5304 | struct rpc_cred *cred; |
| 5305 | int ret = 0; |
| 5306 | |
| 5307 | if (clp->cl_mvops->minor_version < 1) |
| 5308 | goto out; |
| 5309 | if (clp->cl_exchange_flags == 0) |
| 5310 | goto out; |
| 5311 | cred = nfs4_get_exchange_id_cred(clp); |
| 5312 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5313 | if (cred) |
| 5314 | put_rpccred(cred); |
| 5315 | switch (ret) { |
| 5316 | case 0: |
| 5317 | case -NFS4ERR_STALE_CLIENTID: |
| 5318 | clp->cl_exchange_flags = 0; |
| 5319 | } |
| 5320 | out: |
| 5321 | return ret; |
| 5322 | } |
| 5323 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5324 | struct nfs4_get_lease_time_data { |
| 5325 | struct nfs4_get_lease_time_args *args; |
| 5326 | struct nfs4_get_lease_time_res *res; |
| 5327 | struct nfs_client *clp; |
| 5328 | }; |
| 5329 | |
| 5330 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5331 | void *calldata) |
| 5332 | { |
| 5333 | int ret; |
| 5334 | struct nfs4_get_lease_time_data *data = |
| 5335 | (struct nfs4_get_lease_time_data *)calldata; |
| 5336 | |
| 5337 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5338 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5339 | /* just setup sequence, do not trigger session recovery |
| 5340 | since we're invoked within one */ |
| 5341 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5342 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5343 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5344 | |
| 5345 | BUG_ON(ret == -EAGAIN); |
| 5346 | rpc_call_start(task); |
| 5347 | dprintk("<-- %s\n", __func__); |
| 5348 | } |
| 5349 | |
| 5350 | /* |
| 5351 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5352 | * from sequence operation or clientid errors. |
| 5353 | */ |
| 5354 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5355 | { |
| 5356 | struct nfs4_get_lease_time_data *data = |
| 5357 | (struct nfs4_get_lease_time_data *)calldata; |
| 5358 | |
| 5359 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5360 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5361 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5362 | switch (task->tk_status) { |
| 5363 | case -NFS4ERR_DELAY: |
| 5364 | case -NFS4ERR_GRACE: |
| 5365 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5366 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5367 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5368 | /* fall through */ |
| 5369 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5370 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5371 | return; |
| 5372 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5373 | dprintk("<-- %s\n", __func__); |
| 5374 | } |
| 5375 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5376 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5377 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5378 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5379 | }; |
| 5380 | |
| 5381 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5382 | { |
| 5383 | struct rpc_task *task; |
| 5384 | struct nfs4_get_lease_time_args args; |
| 5385 | struct nfs4_get_lease_time_res res = { |
| 5386 | .lr_fsinfo = fsinfo, |
| 5387 | }; |
| 5388 | struct nfs4_get_lease_time_data data = { |
| 5389 | .args = &args, |
| 5390 | .res = &res, |
| 5391 | .clp = clp, |
| 5392 | }; |
| 5393 | struct rpc_message msg = { |
| 5394 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5395 | .rpc_argp = &args, |
| 5396 | .rpc_resp = &res, |
| 5397 | }; |
| 5398 | struct rpc_task_setup task_setup = { |
| 5399 | .rpc_client = clp->cl_rpcclient, |
| 5400 | .rpc_message = &msg, |
| 5401 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5402 | .callback_data = &data, |
| 5403 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5404 | }; |
| 5405 | int status; |
| 5406 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5407 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5408 | dprintk("--> %s\n", __func__); |
| 5409 | task = rpc_run_task(&task_setup); |
| 5410 | |
| 5411 | if (IS_ERR(task)) |
| 5412 | status = PTR_ERR(task); |
| 5413 | else { |
| 5414 | status = task->tk_status; |
| 5415 | rpc_put_task(task); |
| 5416 | } |
| 5417 | dprintk("<-- %s return %d\n", __func__, status); |
| 5418 | |
| 5419 | return status; |
| 5420 | } |
| 5421 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5422 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5423 | { |
| 5424 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5425 | } |
| 5426 | |
| 5427 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5428 | struct nfs4_slot *new, |
| 5429 | u32 max_slots, |
| 5430 | u32 ivalue) |
| 5431 | { |
| 5432 | struct nfs4_slot *old = NULL; |
| 5433 | u32 i; |
| 5434 | |
| 5435 | spin_lock(&tbl->slot_tbl_lock); |
| 5436 | if (new) { |
| 5437 | old = tbl->slots; |
| 5438 | tbl->slots = new; |
| 5439 | tbl->max_slots = max_slots; |
| 5440 | } |
| 5441 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5442 | for (i = 0; i < tbl->max_slots; i++) |
| 5443 | tbl->slots[i].seq_nr = ivalue; |
| 5444 | spin_unlock(&tbl->slot_tbl_lock); |
| 5445 | kfree(old); |
| 5446 | } |
| 5447 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5448 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5449 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5450 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5451 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5452 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5453 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5454 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5455 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5456 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5457 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5458 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5459 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5460 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5461 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5462 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5463 | if (!new) |
| 5464 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5465 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5466 | ret = 0; |
| 5467 | |
| 5468 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5469 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5470 | tbl, tbl->slots, tbl->max_slots); |
| 5471 | out: |
| 5472 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5473 | return ret; |
| 5474 | } |
| 5475 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5476 | /* Destroy the slot table */ |
| 5477 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5478 | { |
| 5479 | if (session->fc_slot_table.slots != NULL) { |
| 5480 | kfree(session->fc_slot_table.slots); |
| 5481 | session->fc_slot_table.slots = NULL; |
| 5482 | } |
| 5483 | if (session->bc_slot_table.slots != NULL) { |
| 5484 | kfree(session->bc_slot_table.slots); |
| 5485 | session->bc_slot_table.slots = NULL; |
| 5486 | } |
| 5487 | return; |
| 5488 | } |
| 5489 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5490 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5491 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5492 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5493 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5494 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5495 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5496 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5497 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5498 | dprintk("--> %s\n", __func__); |
| 5499 | /* Fore channel */ |
| 5500 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5501 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5502 | if (status) /* -ENOMEM */ |
| 5503 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5504 | /* Back channel */ |
| 5505 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5506 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5507 | if (status && tbl->slots == NULL) |
| 5508 | /* Fore and back channel share a connection so get |
| 5509 | * both slot tables or neither */ |
| 5510 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5511 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5512 | } |
| 5513 | |
| 5514 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5515 | { |
| 5516 | struct nfs4_session *session; |
| 5517 | struct nfs4_slot_table *tbl; |
| 5518 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5519 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5520 | if (!session) |
| 5521 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5522 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5523 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5524 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5525 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5526 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5527 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5528 | |
| 5529 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5530 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5531 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5532 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5533 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5534 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5535 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5536 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5537 | session->clp = clp; |
| 5538 | return session; |
| 5539 | } |
| 5540 | |
| 5541 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5542 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5543 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5544 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5545 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5546 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5547 | nfs4_proc_destroy_session(session, cred); |
| 5548 | if (cred) |
| 5549 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5550 | |
| 5551 | rcu_read_lock(); |
| 5552 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5553 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5554 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5555 | __func__, xprt); |
| 5556 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5557 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5558 | kfree(session); |
| 5559 | } |
| 5560 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5561 | /* |
| 5562 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5563 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5564 | * use them. |
| 5565 | * |
| 5566 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5567 | * always set csa_cachethis to FALSE because the current implementation |
| 5568 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5569 | */ |
| 5570 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5571 | { |
| 5572 | struct nfs4_session *session = args->client->cl_session; |
| 5573 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5574 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5575 | |
| 5576 | if (mxrqst_sz == 0) |
| 5577 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5578 | if (mxresp_sz == 0) |
| 5579 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5580 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5581 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5582 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5583 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5584 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5585 | |
| 5586 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5587 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5588 | __func__, |
| 5589 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5590 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5591 | |
| 5592 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5593 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5594 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5595 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5596 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5597 | args->bc_attrs.max_reqs = 1; |
| 5598 | |
| 5599 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5600 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5601 | __func__, |
| 5602 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5603 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5604 | args->bc_attrs.max_reqs); |
| 5605 | } |
| 5606 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5607 | 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] | 5608 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5609 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5610 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5611 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5612 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5613 | return -EINVAL; |
| 5614 | /* |
| 5615 | * Our requested max_ops is the minimum we need; we're not |
| 5616 | * prepared to break up compounds into smaller pieces than that. |
| 5617 | * So, no point even trying to continue if the server won't |
| 5618 | * cooperate: |
| 5619 | */ |
| 5620 | if (rcvd->max_ops < sent->max_ops) |
| 5621 | return -EINVAL; |
| 5622 | if (rcvd->max_reqs == 0) |
| 5623 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5624 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5625 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5626 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5627 | } |
| 5628 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5629 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5630 | { |
| 5631 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5632 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5633 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5634 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5635 | return -EINVAL; |
| 5636 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5637 | return -EINVAL; |
| 5638 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5639 | return -EINVAL; |
| 5640 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5641 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5642 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5643 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5644 | return -EINVAL; |
| 5645 | return 0; |
| 5646 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5647 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5648 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5649 | struct nfs4_session *session) |
| 5650 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5651 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5652 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5653 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5654 | if (ret) |
| 5655 | return ret; |
| 5656 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5657 | } |
| 5658 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5659 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5660 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5661 | { |
| 5662 | struct nfs4_session *session = clp->cl_session; |
| 5663 | struct nfs41_create_session_args args = { |
| 5664 | .client = clp, |
| 5665 | .cb_program = NFS4_CALLBACK, |
| 5666 | }; |
| 5667 | struct nfs41_create_session_res res = { |
| 5668 | .client = clp, |
| 5669 | }; |
| 5670 | struct rpc_message msg = { |
| 5671 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5672 | .rpc_argp = &args, |
| 5673 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5674 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5675 | }; |
| 5676 | int status; |
| 5677 | |
| 5678 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5679 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5680 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5681 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5682 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5683 | if (!status) |
| 5684 | /* Verify the session's negotiated channel_attrs values */ |
| 5685 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5686 | if (!status) { |
| 5687 | /* Increment the clientid slot sequence id */ |
| 5688 | clp->cl_seqid++; |
| 5689 | } |
| 5690 | |
| 5691 | return status; |
| 5692 | } |
| 5693 | |
| 5694 | /* |
| 5695 | * Issues a CREATE_SESSION operation to the server. |
| 5696 | * It is the responsibility of the caller to verify the session is |
| 5697 | * expired before calling this routine. |
| 5698 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5699 | int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5700 | { |
| 5701 | int status; |
| 5702 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5703 | struct nfs4_session *session = clp->cl_session; |
| 5704 | |
| 5705 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5706 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5707 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5708 | if (status) |
| 5709 | goto out; |
| 5710 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5711 | /* Init or reset the session slot tables */ |
| 5712 | status = nfs4_setup_session_slot_tables(session); |
| 5713 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5714 | if (status) |
| 5715 | goto out; |
| 5716 | |
| 5717 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5718 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5719 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5720 | out: |
| 5721 | dprintk("<-- %s\n", __func__); |
| 5722 | return status; |
| 5723 | } |
| 5724 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5725 | /* |
| 5726 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5727 | * The caller must serialize access to this routine. |
| 5728 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5729 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5730 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5731 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5732 | struct rpc_message msg = { |
| 5733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5734 | .rpc_argp = session, |
| 5735 | .rpc_cred = cred, |
| 5736 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5737 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5738 | |
| 5739 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5740 | |
| 5741 | /* session is still being setup */ |
| 5742 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5743 | return status; |
| 5744 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5745 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5746 | |
| 5747 | if (status) |
| 5748 | printk(KERN_WARNING |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 5749 | "NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5750 | "Session has been destroyed regardless...\n", status); |
| 5751 | |
| 5752 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5753 | return status; |
| 5754 | } |
| 5755 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5756 | /* |
| 5757 | * With sessions, the client is not marked ready until after a |
| 5758 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 5759 | * |
| 5760 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 5761 | * other versions of NFS can be tried. |
| 5762 | */ |
| 5763 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 5764 | { |
| 5765 | int ret; |
| 5766 | |
| 5767 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 5768 | ret = nfs4_client_recover_expired_lease(clp); |
| 5769 | if (ret) |
| 5770 | return ret; |
| 5771 | } |
| 5772 | if (clp->cl_cons_state < NFS_CS_READY) |
| 5773 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 5774 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5775 | return 0; |
| 5776 | } |
| 5777 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5778 | int nfs4_init_session(struct nfs_server *server) |
| 5779 | { |
| 5780 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5781 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5782 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5783 | |
| 5784 | if (!nfs4_has_session(clp)) |
| 5785 | return 0; |
| 5786 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5787 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5788 | spin_lock(&clp->cl_lock); |
| 5789 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5790 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5791 | rsize = server->rsize; |
| 5792 | if (rsize == 0) |
| 5793 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5794 | wsize = server->wsize; |
| 5795 | if (wsize == 0) |
| 5796 | wsize = NFS_MAX_FILE_IO_SIZE; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5797 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5798 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5799 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
| 5800 | } |
| 5801 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5802 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5803 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5804 | } |
| 5805 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5806 | int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time) |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5807 | { |
| 5808 | struct nfs4_session *session = clp->cl_session; |
| 5809 | int ret; |
| 5810 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5811 | spin_lock(&clp->cl_lock); |
| 5812 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 5813 | /* |
| 5814 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 5815 | * DS lease to be equal to the MDS lease. |
| 5816 | */ |
| 5817 | clp->cl_lease_time = lease_time; |
| 5818 | clp->cl_last_renewal = jiffies; |
| 5819 | } |
| 5820 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5821 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5822 | ret = nfs41_check_session_ready(clp); |
| 5823 | if (ret) |
| 5824 | return ret; |
| 5825 | /* Test for the DS role */ |
| 5826 | if (!is_ds_client(clp)) |
| 5827 | return -ENODEV; |
| 5828 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5829 | } |
| 5830 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5831 | |
| 5832 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5833 | /* |
| 5834 | * Renew the cl_session lease. |
| 5835 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5836 | struct nfs4_sequence_data { |
| 5837 | struct nfs_client *clp; |
| 5838 | struct nfs4_sequence_args args; |
| 5839 | struct nfs4_sequence_res res; |
| 5840 | }; |
| 5841 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5842 | static void nfs41_sequence_release(void *data) |
| 5843 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5844 | struct nfs4_sequence_data *calldata = data; |
| 5845 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5846 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5847 | if (atomic_read(&clp->cl_count) > 1) |
| 5848 | nfs4_schedule_state_renewal(clp); |
| 5849 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5850 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5851 | } |
| 5852 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5853 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5854 | { |
| 5855 | switch(task->tk_status) { |
| 5856 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5857 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5858 | return -EAGAIN; |
| 5859 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5860 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5861 | } |
| 5862 | return 0; |
| 5863 | } |
| 5864 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5865 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5866 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5867 | struct nfs4_sequence_data *calldata = data; |
| 5868 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5869 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5870 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5871 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5872 | |
| 5873 | if (task->tk_status < 0) { |
| 5874 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5875 | if (atomic_read(&clp->cl_count) == 1) |
| 5876 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5877 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5878 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5879 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5880 | return; |
| 5881 | } |
| 5882 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5883 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5884 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5885 | dprintk("<-- %s\n", __func__); |
| 5886 | } |
| 5887 | |
| 5888 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5889 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5890 | struct nfs4_sequence_data *calldata = data; |
| 5891 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5892 | struct nfs4_sequence_args *args; |
| 5893 | struct nfs4_sequence_res *res; |
| 5894 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5895 | args = task->tk_msg.rpc_argp; |
| 5896 | res = task->tk_msg.rpc_resp; |
| 5897 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5898 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5899 | return; |
| 5900 | rpc_call_start(task); |
| 5901 | } |
| 5902 | |
| 5903 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5904 | .rpc_call_done = nfs41_sequence_call_done, |
| 5905 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5906 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5907 | }; |
| 5908 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5909 | 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] | 5910 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5911 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5912 | struct rpc_message msg = { |
| 5913 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5914 | .rpc_cred = cred, |
| 5915 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5916 | struct rpc_task_setup task_setup_data = { |
| 5917 | .rpc_client = clp->cl_rpcclient, |
| 5918 | .rpc_message = &msg, |
| 5919 | .callback_ops = &nfs41_sequence_ops, |
| 5920 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5921 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5922 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5923 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5924 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5925 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5926 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5927 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5928 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5929 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5930 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5931 | msg.rpc_argp = &calldata->args; |
| 5932 | msg.rpc_resp = &calldata->res; |
| 5933 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5934 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5935 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5936 | return rpc_run_task(&task_setup_data); |
| 5937 | } |
| 5938 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5939 | 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] | 5940 | { |
| 5941 | struct rpc_task *task; |
| 5942 | int ret = 0; |
| 5943 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5944 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5945 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5946 | task = _nfs41_proc_sequence(clp, cred); |
| 5947 | if (IS_ERR(task)) |
| 5948 | ret = PTR_ERR(task); |
| 5949 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5950 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5951 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5952 | return ret; |
| 5953 | } |
| 5954 | |
| 5955 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5956 | { |
| 5957 | struct rpc_task *task; |
| 5958 | int ret; |
| 5959 | |
| 5960 | task = _nfs41_proc_sequence(clp, cred); |
| 5961 | if (IS_ERR(task)) { |
| 5962 | ret = PTR_ERR(task); |
| 5963 | goto out; |
| 5964 | } |
| 5965 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5966 | if (!ret) { |
| 5967 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5968 | |
| 5969 | if (task->tk_status == 0) |
| 5970 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5971 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5972 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5973 | rpc_put_task(task); |
| 5974 | out: |
| 5975 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5976 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5977 | } |
| 5978 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5979 | struct nfs4_reclaim_complete_data { |
| 5980 | struct nfs_client *clp; |
| 5981 | struct nfs41_reclaim_complete_args arg; |
| 5982 | struct nfs41_reclaim_complete_res res; |
| 5983 | }; |
| 5984 | |
| 5985 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5986 | { |
| 5987 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5988 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5989 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5990 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5991 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5992 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5993 | return; |
| 5994 | |
| 5995 | rpc_call_start(task); |
| 5996 | } |
| 5997 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5998 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5999 | { |
| 6000 | switch(task->tk_status) { |
| 6001 | case 0: |
| 6002 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6003 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6004 | break; |
| 6005 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6006 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6007 | /* fall through */ |
| 6008 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6009 | return -EAGAIN; |
| 6010 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6011 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6012 | } |
| 6013 | return 0; |
| 6014 | } |
| 6015 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6016 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6017 | { |
| 6018 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6019 | struct nfs_client *clp = calldata->clp; |
| 6020 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6021 | |
| 6022 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6023 | if (!nfs41_sequence_done(task, res)) |
| 6024 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6025 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6026 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6027 | rpc_restart_call_prepare(task); |
| 6028 | return; |
| 6029 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6030 | dprintk("<-- %s\n", __func__); |
| 6031 | } |
| 6032 | |
| 6033 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6034 | { |
| 6035 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6036 | |
| 6037 | kfree(calldata); |
| 6038 | } |
| 6039 | |
| 6040 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6041 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6042 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6043 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6044 | }; |
| 6045 | |
| 6046 | /* |
| 6047 | * Issue a global reclaim complete. |
| 6048 | */ |
| 6049 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6050 | { |
| 6051 | struct nfs4_reclaim_complete_data *calldata; |
| 6052 | struct rpc_task *task; |
| 6053 | struct rpc_message msg = { |
| 6054 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6055 | }; |
| 6056 | struct rpc_task_setup task_setup_data = { |
| 6057 | .rpc_client = clp->cl_rpcclient, |
| 6058 | .rpc_message = &msg, |
| 6059 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6060 | .flags = RPC_TASK_ASYNC, |
| 6061 | }; |
| 6062 | int status = -ENOMEM; |
| 6063 | |
| 6064 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6065 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6066 | if (calldata == NULL) |
| 6067 | goto out; |
| 6068 | calldata->clp = clp; |
| 6069 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6070 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6071 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6072 | msg.rpc_argp = &calldata->arg; |
| 6073 | msg.rpc_resp = &calldata->res; |
| 6074 | task_setup_data.callback_data = calldata; |
| 6075 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6076 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6077 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6078 | goto out; |
| 6079 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6080 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6081 | if (status == 0) |
| 6082 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6083 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6084 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6085 | out: |
| 6086 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6087 | return status; |
| 6088 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6089 | |
| 6090 | static void |
| 6091 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6092 | { |
| 6093 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6094 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6095 | |
| 6096 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6097 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6098 | * right now covering the LAYOUTGET we are about to send. |
| 6099 | * However, that is not so catastrophic, and there seems |
| 6100 | * to be no way to prevent it completely. |
| 6101 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6102 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6103 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6104 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6105 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6106 | NFS_I(lgp->args.inode)->layout, |
| 6107 | lgp->args.ctx->state)) { |
| 6108 | rpc_exit(task, NFS4_OK); |
| 6109 | return; |
| 6110 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6111 | rpc_call_start(task); |
| 6112 | } |
| 6113 | |
| 6114 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6115 | { |
| 6116 | struct nfs4_layoutget *lgp = calldata; |
| 6117 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6118 | |
| 6119 | dprintk("--> %s\n", __func__); |
| 6120 | |
| 6121 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 6122 | return; |
| 6123 | |
| 6124 | switch (task->tk_status) { |
| 6125 | case 0: |
| 6126 | break; |
| 6127 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6128 | case -NFS4ERR_RECALLCONFLICT: |
| 6129 | task->tk_status = -NFS4ERR_DELAY; |
| 6130 | /* Fall through */ |
| 6131 | default: |
| 6132 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6133 | rpc_restart_call_prepare(task); |
| 6134 | return; |
| 6135 | } |
| 6136 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6137 | dprintk("<-- %s\n", __func__); |
| 6138 | } |
| 6139 | |
| 6140 | static void nfs4_layoutget_release(void *calldata) |
| 6141 | { |
| 6142 | struct nfs4_layoutget *lgp = calldata; |
| 6143 | |
| 6144 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6145 | put_nfs_open_context(lgp->args.ctx); |
| 6146 | kfree(calldata); |
| 6147 | dprintk("<-- %s\n", __func__); |
| 6148 | } |
| 6149 | |
| 6150 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6151 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6152 | .rpc_call_done = nfs4_layoutget_done, |
| 6153 | .rpc_release = nfs4_layoutget_release, |
| 6154 | }; |
| 6155 | |
| 6156 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 6157 | { |
| 6158 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6159 | struct rpc_task *task; |
| 6160 | struct rpc_message msg = { |
| 6161 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6162 | .rpc_argp = &lgp->args, |
| 6163 | .rpc_resp = &lgp->res, |
| 6164 | }; |
| 6165 | struct rpc_task_setup task_setup_data = { |
| 6166 | .rpc_client = server->client, |
| 6167 | .rpc_message = &msg, |
| 6168 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6169 | .callback_data = lgp, |
| 6170 | .flags = RPC_TASK_ASYNC, |
| 6171 | }; |
| 6172 | int status = 0; |
| 6173 | |
| 6174 | dprintk("--> %s\n", __func__); |
| 6175 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6176 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6177 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6178 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6179 | task = rpc_run_task(&task_setup_data); |
| 6180 | if (IS_ERR(task)) |
| 6181 | return PTR_ERR(task); |
| 6182 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6183 | if (status == 0) |
| 6184 | status = task->tk_status; |
| 6185 | if (status == 0) |
| 6186 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6187 | rpc_put_task(task); |
| 6188 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6189 | return status; |
| 6190 | } |
| 6191 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6192 | static void |
| 6193 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6194 | { |
| 6195 | struct nfs4_layoutreturn *lrp = calldata; |
| 6196 | |
| 6197 | dprintk("--> %s\n", __func__); |
| 6198 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6199 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6200 | return; |
| 6201 | rpc_call_start(task); |
| 6202 | } |
| 6203 | |
| 6204 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6205 | { |
| 6206 | struct nfs4_layoutreturn *lrp = calldata; |
| 6207 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6208 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6209 | |
| 6210 | dprintk("--> %s\n", __func__); |
| 6211 | |
| 6212 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6213 | return; |
| 6214 | |
| 6215 | server = NFS_SERVER(lrp->args.inode); |
| 6216 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6217 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6218 | return; |
| 6219 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6220 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6221 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6222 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6223 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6224 | } else |
| 6225 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 6226 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 6227 | lo->plh_block_lgets--; |
| 6228 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6229 | dprintk("<-- %s\n", __func__); |
| 6230 | } |
| 6231 | |
| 6232 | static void nfs4_layoutreturn_release(void *calldata) |
| 6233 | { |
| 6234 | struct nfs4_layoutreturn *lrp = calldata; |
| 6235 | |
| 6236 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 6237 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6238 | kfree(calldata); |
| 6239 | dprintk("<-- %s\n", __func__); |
| 6240 | } |
| 6241 | |
| 6242 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6243 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6244 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6245 | .rpc_release = nfs4_layoutreturn_release, |
| 6246 | }; |
| 6247 | |
| 6248 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6249 | { |
| 6250 | struct rpc_task *task; |
| 6251 | struct rpc_message msg = { |
| 6252 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6253 | .rpc_argp = &lrp->args, |
| 6254 | .rpc_resp = &lrp->res, |
| 6255 | }; |
| 6256 | struct rpc_task_setup task_setup_data = { |
| 6257 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6258 | .rpc_message = &msg, |
| 6259 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6260 | .callback_data = lrp, |
| 6261 | }; |
| 6262 | int status; |
| 6263 | |
| 6264 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6265 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6266 | task = rpc_run_task(&task_setup_data); |
| 6267 | if (IS_ERR(task)) |
| 6268 | return PTR_ERR(task); |
| 6269 | status = task->tk_status; |
| 6270 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6271 | rpc_put_task(task); |
| 6272 | return status; |
| 6273 | } |
| 6274 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6275 | /* |
| 6276 | * Retrieve the list of Data Server devices from the MDS. |
| 6277 | */ |
| 6278 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6279 | const struct nfs_fh *fh, |
| 6280 | struct pnfs_devicelist *devlist) |
| 6281 | { |
| 6282 | struct nfs4_getdevicelist_args args = { |
| 6283 | .fh = fh, |
| 6284 | .layoutclass = server->pnfs_curr_ld->id, |
| 6285 | }; |
| 6286 | struct nfs4_getdevicelist_res res = { |
| 6287 | .devlist = devlist, |
| 6288 | }; |
| 6289 | struct rpc_message msg = { |
| 6290 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6291 | .rpc_argp = &args, |
| 6292 | .rpc_resp = &res, |
| 6293 | }; |
| 6294 | int status; |
| 6295 | |
| 6296 | dprintk("--> %s\n", __func__); |
| 6297 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6298 | &res.seq_res, 0); |
| 6299 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6300 | return status; |
| 6301 | } |
| 6302 | |
| 6303 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6304 | const struct nfs_fh *fh, |
| 6305 | struct pnfs_devicelist *devlist) |
| 6306 | { |
| 6307 | struct nfs4_exception exception = { }; |
| 6308 | int err; |
| 6309 | |
| 6310 | do { |
| 6311 | err = nfs4_handle_exception(server, |
| 6312 | _nfs4_getdevicelist(server, fh, devlist), |
| 6313 | &exception); |
| 6314 | } while (exception.retry); |
| 6315 | |
| 6316 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6317 | err, devlist->num_devs); |
| 6318 | |
| 6319 | return err; |
| 6320 | } |
| 6321 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6322 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6323 | static int |
| 6324 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6325 | { |
| 6326 | struct nfs4_getdeviceinfo_args args = { |
| 6327 | .pdev = pdev, |
| 6328 | }; |
| 6329 | struct nfs4_getdeviceinfo_res res = { |
| 6330 | .pdev = pdev, |
| 6331 | }; |
| 6332 | struct rpc_message msg = { |
| 6333 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6334 | .rpc_argp = &args, |
| 6335 | .rpc_resp = &res, |
| 6336 | }; |
| 6337 | int status; |
| 6338 | |
| 6339 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6340 | 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] | 6341 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6342 | |
| 6343 | return status; |
| 6344 | } |
| 6345 | |
| 6346 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6347 | { |
| 6348 | struct nfs4_exception exception = { }; |
| 6349 | int err; |
| 6350 | |
| 6351 | do { |
| 6352 | err = nfs4_handle_exception(server, |
| 6353 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6354 | &exception); |
| 6355 | } while (exception.retry); |
| 6356 | return err; |
| 6357 | } |
| 6358 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6359 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6360 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6361 | { |
| 6362 | struct nfs4_layoutcommit_data *data = calldata; |
| 6363 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6364 | |
| 6365 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6366 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6367 | return; |
| 6368 | rpc_call_start(task); |
| 6369 | } |
| 6370 | |
| 6371 | static void |
| 6372 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6373 | { |
| 6374 | struct nfs4_layoutcommit_data *data = calldata; |
| 6375 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6376 | |
| 6377 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6378 | return; |
| 6379 | |
| 6380 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6381 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6382 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6383 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6384 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6385 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6386 | break; |
| 6387 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6388 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6389 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6390 | break; |
| 6391 | default: |
| 6392 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6393 | rpc_restart_call_prepare(task); |
| 6394 | return; |
| 6395 | } |
| 6396 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
| 6399 | static void nfs4_layoutcommit_release(void *calldata) |
| 6400 | { |
| 6401 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6402 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6403 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6404 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6405 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6406 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6407 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6408 | list_del_init(&lseg->pls_lc_list); |
| 6409 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6410 | &lseg->pls_flags)) |
| 6411 | put_lseg(lseg); |
| 6412 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6413 | |
| 6414 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6415 | smp_mb__after_clear_bit(); |
| 6416 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6417 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6418 | put_rpccred(data->cred); |
| 6419 | kfree(data); |
| 6420 | } |
| 6421 | |
| 6422 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6423 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6424 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6425 | .rpc_release = nfs4_layoutcommit_release, |
| 6426 | }; |
| 6427 | |
| 6428 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6429 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6430 | { |
| 6431 | struct rpc_message msg = { |
| 6432 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6433 | .rpc_argp = &data->args, |
| 6434 | .rpc_resp = &data->res, |
| 6435 | .rpc_cred = data->cred, |
| 6436 | }; |
| 6437 | struct rpc_task_setup task_setup_data = { |
| 6438 | .task = &data->task, |
| 6439 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6440 | .rpc_message = &msg, |
| 6441 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6442 | .callback_data = data, |
| 6443 | .flags = RPC_TASK_ASYNC, |
| 6444 | }; |
| 6445 | struct rpc_task *task; |
| 6446 | int status = 0; |
| 6447 | |
| 6448 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6449 | "lbw: %llu inode %lu\n", |
| 6450 | data->task.tk_pid, sync, |
| 6451 | data->args.lastbytewritten, |
| 6452 | data->args.inode->i_ino); |
| 6453 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6454 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6455 | task = rpc_run_task(&task_setup_data); |
| 6456 | if (IS_ERR(task)) |
| 6457 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6458 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6459 | goto out; |
| 6460 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6461 | if (status != 0) |
| 6462 | goto out; |
| 6463 | status = task->tk_status; |
| 6464 | out: |
| 6465 | dprintk("%s: status %d\n", __func__, status); |
| 6466 | rpc_put_task(task); |
| 6467 | return status; |
| 6468 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6469 | |
| 6470 | static int |
| 6471 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6472 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6473 | { |
| 6474 | struct nfs41_secinfo_no_name_args args = { |
| 6475 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6476 | }; |
| 6477 | struct nfs4_secinfo_res res = { |
| 6478 | .flavors = flavors, |
| 6479 | }; |
| 6480 | struct rpc_message msg = { |
| 6481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6482 | .rpc_argp = &args, |
| 6483 | .rpc_resp = &res, |
| 6484 | }; |
| 6485 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6486 | } |
| 6487 | |
| 6488 | static int |
| 6489 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6490 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6491 | { |
| 6492 | struct nfs4_exception exception = { }; |
| 6493 | int err; |
| 6494 | do { |
| 6495 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6496 | switch (err) { |
| 6497 | case 0: |
| 6498 | case -NFS4ERR_WRONGSEC: |
| 6499 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6500 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6501 | default: |
| 6502 | err = nfs4_handle_exception(server, err, &exception); |
| 6503 | } |
| 6504 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6505 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6506 | return err; |
| 6507 | } |
| 6508 | |
| 6509 | static int |
| 6510 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6511 | struct nfs_fsinfo *info) |
| 6512 | { |
| 6513 | int err; |
| 6514 | struct page *page; |
| 6515 | rpc_authflavor_t flavor; |
| 6516 | struct nfs4_secinfo_flavors *flavors; |
| 6517 | |
| 6518 | page = alloc_page(GFP_KERNEL); |
| 6519 | if (!page) { |
| 6520 | err = -ENOMEM; |
| 6521 | goto out; |
| 6522 | } |
| 6523 | |
| 6524 | flavors = page_address(page); |
| 6525 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6526 | |
| 6527 | /* |
| 6528 | * Fall back on "guess and check" method if |
| 6529 | * the server doesn't support SECINFO_NO_NAME |
| 6530 | */ |
| 6531 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6532 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6533 | goto out_freepage; |
| 6534 | } |
| 6535 | if (err) |
| 6536 | goto out_freepage; |
| 6537 | |
| 6538 | flavor = nfs_find_best_sec(flavors); |
| 6539 | if (err == 0) |
| 6540 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6541 | |
| 6542 | out_freepage: |
| 6543 | put_page(page); |
| 6544 | if (err == -EACCES) |
| 6545 | return -EPERM; |
| 6546 | out: |
| 6547 | return err; |
| 6548 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6549 | |
| 6550 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6551 | { |
| 6552 | int status; |
| 6553 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6554 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6555 | }; |
| 6556 | struct nfs41_test_stateid_res res; |
| 6557 | struct rpc_message msg = { |
| 6558 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6559 | .rpc_argp = &args, |
| 6560 | .rpc_resp = &res, |
| 6561 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6562 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6563 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6564 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
| 6565 | |
| 6566 | if (status == NFS_OK) |
| 6567 | return res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6568 | return status; |
| 6569 | } |
| 6570 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6571 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6572 | { |
| 6573 | struct nfs4_exception exception = { }; |
| 6574 | int err; |
| 6575 | do { |
| 6576 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6577 | _nfs41_test_stateid(server, stateid), |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6578 | &exception); |
| 6579 | } while (exception.retry); |
| 6580 | return err; |
| 6581 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6582 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6583 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6584 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6585 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6586 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6587 | }; |
| 6588 | struct nfs41_free_stateid_res res; |
| 6589 | struct rpc_message msg = { |
| 6590 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6591 | .rpc_argp = &args, |
| 6592 | .rpc_resp = &res, |
| 6593 | }; |
| 6594 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6595 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6596 | 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] | 6597 | } |
| 6598 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6599 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6600 | { |
| 6601 | struct nfs4_exception exception = { }; |
| 6602 | int err; |
| 6603 | do { |
| 6604 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6605 | _nfs4_free_stateid(server, stateid), |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6606 | &exception); |
| 6607 | } while (exception.retry); |
| 6608 | return err; |
| 6609 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6610 | |
| 6611 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6612 | const nfs4_stateid *s2) |
| 6613 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6614 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6615 | return false; |
| 6616 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6617 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6618 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6619 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6620 | return true; |
| 6621 | |
| 6622 | return false; |
| 6623 | } |
| 6624 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6625 | #endif /* CONFIG_NFS_V4_1 */ |
| 6626 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6627 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6628 | const nfs4_stateid *s2) |
| 6629 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6630 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6631 | } |
| 6632 | |
| 6633 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6634 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6635 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6636 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6637 | .recover_open = nfs4_open_reclaim, |
| 6638 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6639 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6640 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6641 | }; |
| 6642 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6643 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6644 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6645 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6646 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6647 | .recover_open = nfs4_open_reclaim, |
| 6648 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6649 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6650 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6651 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6652 | }; |
| 6653 | #endif /* CONFIG_NFS_V4_1 */ |
| 6654 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6655 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6656 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6657 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6658 | .recover_open = nfs4_open_expired, |
| 6659 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6660 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6661 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6662 | }; |
| 6663 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6664 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6665 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6666 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6667 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6668 | .recover_open = nfs41_open_expired, |
| 6669 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6670 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6671 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6672 | }; |
| 6673 | #endif /* CONFIG_NFS_V4_1 */ |
| 6674 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6675 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6676 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6677 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6678 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6679 | }; |
| 6680 | |
| 6681 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6682 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6683 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6684 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6685 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6686 | }; |
| 6687 | #endif |
| 6688 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6689 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6690 | .minor_version = 0, |
| 6691 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6692 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6693 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6694 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6695 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6696 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6697 | }; |
| 6698 | |
| 6699 | #if defined(CONFIG_NFS_V4_1) |
| 6700 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6701 | .minor_version = 1, |
| 6702 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6703 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6704 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6705 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6706 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6707 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6708 | }; |
| 6709 | #endif |
| 6710 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6711 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6712 | [0] = &nfs_v4_0_minor_ops, |
| 6713 | #if defined(CONFIG_NFS_V4_1) |
| 6714 | [1] = &nfs_v4_1_minor_ops, |
| 6715 | #endif |
| 6716 | }; |
| 6717 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6718 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6719 | .permission = nfs_permission, |
| 6720 | .getattr = nfs_getattr, |
| 6721 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6722 | .getxattr = generic_getxattr, |
| 6723 | .setxattr = generic_setxattr, |
| 6724 | .listxattr = generic_listxattr, |
| 6725 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6726 | }; |
| 6727 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6728 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6729 | .version = 4, /* protocol version */ |
| 6730 | .dentry_ops = &nfs4_dentry_operations, |
| 6731 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6732 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6733 | .file_ops = &nfs4_file_operations, |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 6734 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6735 | .submount = nfs4_submount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6736 | .getattr = nfs4_proc_getattr, |
| 6737 | .setattr = nfs4_proc_setattr, |
| 6738 | .lookup = nfs4_proc_lookup, |
| 6739 | .access = nfs4_proc_access, |
| 6740 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6741 | .create = nfs4_proc_create, |
| 6742 | .remove = nfs4_proc_remove, |
| 6743 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 6744 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6745 | .unlink_done = nfs4_proc_unlink_done, |
| 6746 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6747 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 6748 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6749 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6750 | .link = nfs4_proc_link, |
| 6751 | .symlink = nfs4_proc_symlink, |
| 6752 | .mkdir = nfs4_proc_mkdir, |
| 6753 | .rmdir = nfs4_proc_remove, |
| 6754 | .readdir = nfs4_proc_readdir, |
| 6755 | .mknod = nfs4_proc_mknod, |
| 6756 | .statfs = nfs4_proc_statfs, |
| 6757 | .fsinfo = nfs4_proc_fsinfo, |
| 6758 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6759 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6760 | .decode_dirent = nfs4_decode_dirent, |
| 6761 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 6762 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6763 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6764 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 6765 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6766 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6767 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 6768 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6769 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6770 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6771 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6772 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6773 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6774 | .init_client = nfs4_init_client, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6775 | }; |
| 6776 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6777 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6778 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6779 | .list = nfs4_xattr_list_nfs4_acl, |
| 6780 | .get = nfs4_xattr_get_nfs4_acl, |
| 6781 | .set = nfs4_xattr_set_nfs4_acl, |
| 6782 | }; |
| 6783 | |
| 6784 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6785 | &nfs4_xattr_nfs4_acl_handler, |
| 6786 | NULL |
| 6787 | }; |
| 6788 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6789 | module_param(max_session_slots, ushort, 0644); |
| 6790 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6791 | "requests the client will negotiate"); |
| 6792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | /* |
| 6794 | * Local variables: |
| 6795 | * c-basic-offset: 8 |
| 6796 | * End: |
| 6797 | */ |