Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 46 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 55 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 56 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 57 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 58 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 59 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 61 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 63 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 64 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 65 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 66 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 75 | static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE; |
| 76 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 77 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 78 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 79 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 81 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 82 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 83 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 84 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 85 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 86 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 87 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 88 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 89 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 90 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 92 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 94 | if (err >= -1000) |
| 95 | return err; |
| 96 | switch (err) { |
| 97 | case -NFS4ERR_RESOURCE: |
| 98 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 99 | case -NFS4ERR_WRONGSEC: |
| 100 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 101 | case -NFS4ERR_BADOWNER: |
| 102 | case -NFS4ERR_BADNAME: |
| 103 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 104 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 106 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 107 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * This is our standard bitmap for GETATTR requests. |
| 114 | */ |
| 115 | const u32 nfs4_fattr_bitmap[2] = { |
| 116 | FATTR4_WORD0_TYPE |
| 117 | | FATTR4_WORD0_CHANGE |
| 118 | | FATTR4_WORD0_SIZE |
| 119 | | FATTR4_WORD0_FSID |
| 120 | | FATTR4_WORD0_FILEID, |
| 121 | FATTR4_WORD1_MODE |
| 122 | | FATTR4_WORD1_NUMLINKS |
| 123 | | FATTR4_WORD1_OWNER |
| 124 | | FATTR4_WORD1_OWNER_GROUP |
| 125 | | FATTR4_WORD1_RAWDEV |
| 126 | | FATTR4_WORD1_SPACE_USED |
| 127 | | FATTR4_WORD1_TIME_ACCESS |
| 128 | | FATTR4_WORD1_TIME_METADATA |
| 129 | | FATTR4_WORD1_TIME_MODIFY |
| 130 | }; |
| 131 | |
| 132 | const u32 nfs4_statfs_bitmap[2] = { |
| 133 | FATTR4_WORD0_FILES_AVAIL |
| 134 | | FATTR4_WORD0_FILES_FREE |
| 135 | | FATTR4_WORD0_FILES_TOTAL, |
| 136 | FATTR4_WORD1_SPACE_AVAIL |
| 137 | | FATTR4_WORD1_SPACE_FREE |
| 138 | | FATTR4_WORD1_SPACE_TOTAL |
| 139 | }; |
| 140 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 141 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | FATTR4_WORD0_MAXLINK |
| 143 | | FATTR4_WORD0_MAXNAME, |
| 144 | 0 |
| 145 | }; |
| 146 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 147 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | | FATTR4_WORD0_MAXREAD |
| 149 | | FATTR4_WORD0_MAXWRITE |
| 150 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 151 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 152 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 153 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 156 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 157 | FATTR4_WORD0_TYPE |
| 158 | | FATTR4_WORD0_CHANGE |
| 159 | | FATTR4_WORD0_SIZE |
| 160 | | FATTR4_WORD0_FSID |
| 161 | | FATTR4_WORD0_FILEID |
| 162 | | FATTR4_WORD0_FS_LOCATIONS, |
| 163 | FATTR4_WORD1_MODE |
| 164 | | FATTR4_WORD1_NUMLINKS |
| 165 | | FATTR4_WORD1_OWNER |
| 166 | | FATTR4_WORD1_OWNER_GROUP |
| 167 | | FATTR4_WORD1_RAWDEV |
| 168 | | FATTR4_WORD1_SPACE_USED |
| 169 | | FATTR4_WORD1_TIME_ACCESS |
| 170 | | FATTR4_WORD1_TIME_METADATA |
| 171 | | FATTR4_WORD1_TIME_MODIFY |
| 172 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 173 | }; |
| 174 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 175 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | struct nfs4_readdir_arg *readdir) |
| 177 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 178 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | BUG_ON(readdir->count < 80); |
| 181 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 182 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | readdir->cookie = 0; |
| 188 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 189 | if (cookie == 2) |
| 190 | return; |
| 191 | |
| 192 | /* |
| 193 | * NFSv4 servers do not return entries for '.' and '..' |
| 194 | * Therefore, we fake these entries here. We let '.' |
| 195 | * have cookie 0 and '..' have cookie 1. Note that |
| 196 | * when talking to the server, we always send cookie 0 |
| 197 | * instead of 1 or 2. |
| 198 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 199 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | if (cookie == 0) { |
| 202 | *p++ = xdr_one; /* next */ |
| 203 | *p++ = xdr_zero; /* cookie, first word */ |
| 204 | *p++ = xdr_one; /* cookie, second word */ |
| 205 | *p++ = xdr_one; /* entry len */ |
| 206 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 207 | p++; |
| 208 | *p++ = xdr_one; /* bitmap length */ |
| 209 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 210 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 211 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | *p++ = xdr_one; /* next */ |
| 215 | *p++ = xdr_zero; /* cookie, first word */ |
| 216 | *p++ = xdr_two; /* cookie, second word */ |
| 217 | *p++ = xdr_two; /* entry len */ |
| 218 | memcpy(p, "..\0\0", 4); /* entry */ |
| 219 | p++; |
| 220 | *p++ = xdr_one; /* bitmap length */ |
| 221 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 222 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 223 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | readdir->pgbase = (char *)p - (char *)start; |
| 226 | readdir->count -= readdir->pgbase; |
| 227 | kunmap_atomic(start, KM_USER0); |
| 228 | } |
| 229 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 230 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 231 | { |
| 232 | int res; |
| 233 | |
| 234 | might_sleep(); |
| 235 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 236 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 237 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 238 | return res; |
| 239 | } |
| 240 | |
| 241 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 242 | { |
| 243 | int res = 0; |
| 244 | |
| 245 | might_sleep(); |
| 246 | |
| 247 | if (*timeout <= 0) |
| 248 | *timeout = NFS4_POLL_RETRY_MIN; |
| 249 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 250 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 251 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 252 | if (fatal_signal_pending(current)) |
| 253 | res = -ERESTARTSYS; |
| 254 | *timeout <<= 1; |
| 255 | return res; |
| 256 | } |
| 257 | |
| 258 | /* This is the error handling routine for processes that are allowed |
| 259 | * to sleep. |
| 260 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 261 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 262 | { |
| 263 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 264 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 265 | int ret = errorcode; |
| 266 | |
| 267 | exception->retry = 0; |
| 268 | switch(errorcode) { |
| 269 | case 0: |
| 270 | return 0; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 271 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 272 | case -NFS4ERR_ADMIN_REVOKED: |
| 273 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 274 | if (state != NULL) |
| 275 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 276 | case -NFS4ERR_OPENMODE: |
| 277 | if (state == NULL) |
| 278 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 279 | nfs4_schedule_stateid_recovery(server, state); |
| 280 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 281 | case -NFS4ERR_EXPIRED: |
| 282 | if (state != NULL) |
| 283 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 284 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 285 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 286 | nfs4_schedule_lease_recovery(clp); |
| 287 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 288 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 289 | case -NFS4ERR_BADSESSION: |
| 290 | case -NFS4ERR_BADSLOT: |
| 291 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 292 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 293 | case -NFS4ERR_DEADSESSION: |
| 294 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 295 | case -NFS4ERR_SEQ_MISORDERED: |
| 296 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 297 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 298 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 299 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 300 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 301 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 302 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 303 | if (exception->timeout > HZ) { |
| 304 | /* We have retried a decent amount, time to |
| 305 | * fail |
| 306 | */ |
| 307 | ret = -EBUSY; |
| 308 | break; |
| 309 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 310 | case -NFS4ERR_GRACE: |
| 311 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 312 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 313 | ret = nfs4_delay(server->client, &exception->timeout); |
| 314 | if (ret != 0) |
| 315 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 316 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 317 | case -NFS4ERR_OLD_STATEID: |
| 318 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 319 | break; |
| 320 | case -NFS4ERR_BADOWNER: |
| 321 | /* The following works around a Linux server bug! */ |
| 322 | case -NFS4ERR_BADNAME: |
| 323 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 324 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 325 | exception->retry = 1; |
| 326 | printk(KERN_WARNING "NFS: v4 server %s " |
| 327 | "does not accept raw " |
| 328 | "uid/gids. " |
| 329 | "Reenabling the idmapper.\n", |
| 330 | server->nfs_client->cl_hostname); |
| 331 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 332 | } |
| 333 | /* We failed to handle the error */ |
| 334 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 335 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 336 | ret = nfs4_wait_clnt_recover(clp); |
| 337 | if (ret == 0) |
| 338 | exception->retry = 1; |
| 339 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 343 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | spin_lock(&clp->cl_lock); |
| 346 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 347 | clp->cl_last_renewal = timestamp; |
| 348 | spin_unlock(&clp->cl_lock); |
| 349 | } |
| 350 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 351 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 352 | { |
| 353 | do_renew_lease(server->nfs_client, timestamp); |
| 354 | } |
| 355 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 356 | #if defined(CONFIG_NFS_V4_1) |
| 357 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 358 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 359 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 360 | * |
| 361 | * freeing a slot is trivially done by clearing its respective bit |
| 362 | * in the bitmap. |
| 363 | * If the freed slotid equals highest_used_slotid we want to update it |
| 364 | * so that the server would be able to size down the slot table if needed, |
| 365 | * otherwise we know that the highest_used_slotid is still in use. |
| 366 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 367 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 368 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 369 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 370 | * |
| 371 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 372 | */ |
| 373 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 374 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 375 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 376 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 377 | /* clear used bit in bitmap */ |
| 378 | __clear_bit(slotid, tbl->used_slots); |
| 379 | |
| 380 | /* update highest_used_slotid when it is freed */ |
| 381 | if (slotid == tbl->highest_used_slotid) { |
| 382 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 383 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 384 | tbl->highest_used_slotid = slotid; |
| 385 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 386 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 387 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 388 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 389 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 392 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 393 | { |
| 394 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 395 | return true; |
| 396 | } |
| 397 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 398 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 399 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 400 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 401 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 402 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 403 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 404 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 405 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 406 | return; |
| 407 | } |
| 408 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 409 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 410 | return; |
| 411 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 412 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 413 | complete(&ses->fc_slot_table.complete); |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * Signal state manager thread if session back channel is drained |
| 418 | */ |
| 419 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 420 | { |
| 421 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 422 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 423 | return; |
| 424 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 425 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 428 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 429 | { |
| 430 | struct nfs4_slot_table *tbl; |
| 431 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 432 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 433 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 434 | /* just wake up the next guy waiting since |
| 435 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 436 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 437 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 438 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 439 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 440 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 441 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 442 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 443 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 444 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 447 | 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] | 448 | { |
| 449 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 450 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 451 | |
| 452 | /* |
| 453 | * sr_status remains 1 if an RPC level error occurred. The server |
| 454 | * may or may not have processed the sequence operation.. |
| 455 | * Proceed as if the server received and processed the sequence |
| 456 | * operation. |
| 457 | */ |
| 458 | if (res->sr_status == 1) |
| 459 | res->sr_status = NFS_OK; |
| 460 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 461 | /* don't increment the sequence number if the task wasn't sent */ |
| 462 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 463 | goto out; |
| 464 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 465 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 466 | switch (res->sr_status) { |
| 467 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 468 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 469 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 470 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 471 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 472 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 473 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 474 | if (res->sr_status_flags != 0) |
| 475 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 476 | break; |
| 477 | case -NFS4ERR_DELAY: |
| 478 | /* The server detected a resend of the RPC call and |
| 479 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 480 | * of RFC5661. |
| 481 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 482 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 483 | __func__, |
| 484 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 485 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 486 | goto out_retry; |
| 487 | default: |
| 488 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 489 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 490 | } |
| 491 | out: |
| 492 | /* The session may be reset by one of the error handlers. */ |
| 493 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 494 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 495 | return 1; |
| 496 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 497 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 498 | goto out; |
| 499 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 500 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 501 | } |
| 502 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 503 | static int nfs4_sequence_done(struct rpc_task *task, |
| 504 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 505 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 506 | if (res->sr_session == NULL) |
| 507 | return 1; |
| 508 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 511 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 512 | * nfs4_find_slot - efficiently look for a free slot |
| 513 | * |
| 514 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 515 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 516 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 517 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 518 | * |
| 519 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 520 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 521 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 522 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 523 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 524 | u32 slotid; |
| 525 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 526 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 527 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 528 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 529 | tbl->max_slots); |
| 530 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 531 | if (slotid >= tbl->max_slots) |
| 532 | goto out; |
| 533 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 534 | if (slotid > tbl->highest_used_slotid || |
| 535 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 536 | tbl->highest_used_slotid = slotid; |
| 537 | ret_id = slotid; |
| 538 | out: |
| 539 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 540 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 541 | return ret_id; |
| 542 | } |
| 543 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 544 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 545 | struct nfs4_sequence_res *res, int cache_reply) |
| 546 | { |
| 547 | args->sa_session = NULL; |
| 548 | args->sa_cache_this = 0; |
| 549 | if (cache_reply) |
| 550 | args->sa_cache_this = 1; |
| 551 | res->sr_session = NULL; |
| 552 | res->sr_slot = NULL; |
| 553 | } |
| 554 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 555 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 556 | struct nfs4_sequence_args *args, |
| 557 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 558 | struct rpc_task *task) |
| 559 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 560 | struct nfs4_slot *slot; |
| 561 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 562 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 563 | |
| 564 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 565 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 566 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 567 | return 0; |
| 568 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 569 | tbl = &session->fc_slot_table; |
| 570 | |
| 571 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 572 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 573 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 574 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 575 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 576 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 577 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 578 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 579 | } |
| 580 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 581 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 582 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 583 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 584 | spin_unlock(&tbl->slot_tbl_lock); |
| 585 | dprintk("%s enforce FIFO order\n", __func__); |
| 586 | return -EAGAIN; |
| 587 | } |
| 588 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 589 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 590 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 591 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 592 | spin_unlock(&tbl->slot_tbl_lock); |
| 593 | dprintk("<-- %s: no free slots\n", __func__); |
| 594 | return -EAGAIN; |
| 595 | } |
| 596 | spin_unlock(&tbl->slot_tbl_lock); |
| 597 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 598 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 599 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 600 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 601 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 602 | |
| 603 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 604 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 605 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 606 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 607 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 608 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 609 | /* |
| 610 | * sr_status is only set in decode_sequence, and so will remain |
| 611 | * set to 1 if an rpc level failure occurs. |
| 612 | */ |
| 613 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | return 0; |
| 615 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 616 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 618 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | struct nfs4_sequence_args *args, |
| 620 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 621 | struct rpc_task *task) |
| 622 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 623 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | int ret = 0; |
| 625 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 626 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 627 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 628 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 629 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 630 | __func__, session->clp, session, res->sr_slot ? |
| 631 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 632 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 633 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | out: |
| 635 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 640 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 641 | struct nfs4_sequence_args *seq_args; |
| 642 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 646 | { |
| 647 | struct nfs41_call_sync_data *data = calldata; |
| 648 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 649 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 650 | |
| 651 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 652 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | return; |
| 654 | rpc_call_start(task); |
| 655 | } |
| 656 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 657 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 658 | { |
| 659 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 660 | nfs41_call_sync_prepare(task, calldata); |
| 661 | } |
| 662 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 663 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 664 | { |
| 665 | struct nfs41_call_sync_data *data = calldata; |
| 666 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 667 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 668 | } |
| 669 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 670 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 671 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 672 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 673 | }; |
| 674 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 675 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 676 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 677 | .rpc_call_done = nfs41_call_sync_done, |
| 678 | }; |
| 679 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 680 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 681 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | struct rpc_message *msg, |
| 683 | struct nfs4_sequence_args *args, |
| 684 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 685 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | { |
| 687 | int ret; |
| 688 | struct rpc_task *task; |
| 689 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 690 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | .seq_args = args, |
| 692 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 693 | }; |
| 694 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 695 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | .rpc_message = msg, |
| 697 | .callback_ops = &nfs41_call_sync_ops, |
| 698 | .callback_data = &data |
| 699 | }; |
| 700 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 701 | if (privileged) |
| 702 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 703 | task = rpc_run_task(&task_setup); |
| 704 | if (IS_ERR(task)) |
| 705 | ret = PTR_ERR(task); |
| 706 | else { |
| 707 | ret = task->tk_status; |
| 708 | rpc_put_task(task); |
| 709 | } |
| 710 | return ret; |
| 711 | } |
| 712 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 713 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 714 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 715 | struct rpc_message *msg, |
| 716 | struct nfs4_sequence_args *args, |
| 717 | struct nfs4_sequence_res *res, |
| 718 | int cache_reply) |
| 719 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 720 | nfs41_init_sequence(args, res, cache_reply); |
| 721 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 724 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 725 | static inline |
| 726 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 727 | struct nfs4_sequence_res *res, int cache_reply) |
| 728 | { |
| 729 | } |
| 730 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 731 | static int nfs4_sequence_done(struct rpc_task *task, |
| 732 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 733 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 734 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 735 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 736 | #endif /* CONFIG_NFS_V4_1 */ |
| 737 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 738 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 739 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 740 | struct rpc_message *msg, |
| 741 | struct nfs4_sequence_args *args, |
| 742 | struct nfs4_sequence_res *res, |
| 743 | int cache_reply) |
| 744 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 745 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 746 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 747 | } |
| 748 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 749 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 750 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 751 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 752 | struct rpc_message *msg, |
| 753 | struct nfs4_sequence_args *args, |
| 754 | struct nfs4_sequence_res *res, |
| 755 | int cache_reply) |
| 756 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 757 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 758 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 759 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 760 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 761 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 763 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 765 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 766 | 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] | 767 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 768 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 769 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 770 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 773 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 774 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 775 | struct nfs_openargs o_arg; |
| 776 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 777 | struct nfs_open_confirmargs c_arg; |
| 778 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 779 | struct nfs4_string owner_name; |
| 780 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 781 | struct nfs_fattr f_attr; |
| 782 | struct nfs_fattr dir_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 783 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 784 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 785 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 786 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 788 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 789 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 790 | int rpc_status; |
| 791 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 792 | }; |
| 793 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 794 | |
| 795 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 796 | { |
| 797 | p->o_res.f_attr = &p->f_attr; |
| 798 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 799 | p->o_res.seqid = p->o_arg.seqid; |
| 800 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 801 | p->o_res.server = p->o_arg.server; |
| 802 | nfs_fattr_init(&p->f_attr); |
| 803 | nfs_fattr_init(&p->dir_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 804 | 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] | 805 | } |
| 806 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 807 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 808 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 809 | const struct iattr *attrs, |
| 810 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 811 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 812 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 813 | struct inode *dir = parent->d_inode; |
| 814 | struct nfs_server *server = NFS_SERVER(dir); |
| 815 | struct nfs4_opendata *p; |
| 816 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 817 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | if (p == NULL) |
| 819 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 820 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | if (p->o_arg.seqid == NULL) |
| 822 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 823 | nfs_sb_active(dentry->d_sb); |
| 824 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | p->dir = parent; |
| 826 | p->owner = sp; |
| 827 | atomic_inc(&sp->so_count); |
| 828 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 829 | p->o_arg.open_flags = flags; |
| 830 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 831 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 832 | p->o_arg.id = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 833 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 834 | p->o_arg.server = server; |
| 835 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 836 | p->o_arg.dir_bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 838 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 839 | u32 *s; |
| 840 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 841 | p->o_arg.u.attrs = &p->attrs; |
| 842 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 843 | s = (u32 *) p->o_arg.u.verifier.data; |
| 844 | s[0] = jiffies; |
| 845 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 846 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 847 | p->c_arg.fh = &p->o_res.fh; |
| 848 | p->c_arg.stateid = &p->o_res.stateid; |
| 849 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 850 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 851 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | return p; |
| 853 | err_free: |
| 854 | kfree(p); |
| 855 | err: |
| 856 | dput(parent); |
| 857 | return NULL; |
| 858 | } |
| 859 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 860 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 861 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 862 | struct nfs4_opendata *p = container_of(kref, |
| 863 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 864 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 865 | |
| 866 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 867 | if (p->state != NULL) |
| 868 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 869 | nfs4_put_state_owner(p->owner); |
| 870 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 871 | dput(p->dentry); |
| 872 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 873 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 874 | kfree(p); |
| 875 | } |
| 876 | |
| 877 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 878 | { |
| 879 | if (p != NULL) |
| 880 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 881 | } |
| 882 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 883 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 884 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 885 | int ret; |
| 886 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 887 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 888 | return ret; |
| 889 | } |
| 890 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 891 | 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] | 892 | { |
| 893 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 895 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 896 | goto out; |
| 897 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 898 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 899 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 900 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 901 | break; |
| 902 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 903 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 904 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 905 | break; |
| 906 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 907 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 908 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 909 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 910 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 911 | return ret; |
| 912 | } |
| 913 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 914 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 915 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 916 | if (delegation == NULL) |
| 917 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 918 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 919 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 920 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 921 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 922 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 923 | return 1; |
| 924 | } |
| 925 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 926 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 927 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 929 | case FMODE_WRITE: |
| 930 | state->n_wronly++; |
| 931 | break; |
| 932 | case FMODE_READ: |
| 933 | state->n_rdonly++; |
| 934 | break; |
| 935 | case FMODE_READ|FMODE_WRITE: |
| 936 | state->n_rdwr++; |
| 937 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 939 | } |
| 940 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 941 | 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] | 942 | { |
| 943 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 944 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 945 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 947 | case FMODE_READ: |
| 948 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 949 | break; |
| 950 | case FMODE_WRITE: |
| 951 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 952 | break; |
| 953 | case FMODE_READ|FMODE_WRITE: |
| 954 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 955 | } |
| 956 | } |
| 957 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 958 | 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] | 959 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 960 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 962 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 963 | } |
| 964 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | 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] | 966 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 967 | /* |
| 968 | * Protect the call to nfs4_state_set_mode_locked and |
| 969 | * serialise the stateid update |
| 970 | */ |
| 971 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 972 | if (deleg_stateid != NULL) { |
| 973 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 974 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 975 | } |
| 976 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 978 | write_sequnlock(&state->seqlock); |
| 979 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 981 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 984 | 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] | 985 | { |
| 986 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 987 | struct nfs_delegation *deleg_cur; |
| 988 | int ret = 0; |
| 989 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 991 | |
| 992 | rcu_read_lock(); |
| 993 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 994 | if (deleg_cur == NULL) |
| 995 | goto no_delegation; |
| 996 | |
| 997 | spin_lock(&deleg_cur->lock); |
| 998 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1000 | goto no_delegation_unlock; |
| 1001 | |
| 1002 | if (delegation == NULL) |
| 1003 | delegation = &deleg_cur->stateid; |
| 1004 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 1005 | goto no_delegation_unlock; |
| 1006 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1007 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1008 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1009 | ret = 1; |
| 1010 | no_delegation_unlock: |
| 1011 | spin_unlock(&deleg_cur->lock); |
| 1012 | no_delegation: |
| 1013 | rcu_read_unlock(); |
| 1014 | |
| 1015 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1016 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1017 | ret = 1; |
| 1018 | } |
| 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1024 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1025 | { |
| 1026 | struct nfs_delegation *delegation; |
| 1027 | |
| 1028 | rcu_read_lock(); |
| 1029 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1031 | rcu_read_unlock(); |
| 1032 | return; |
| 1033 | } |
| 1034 | rcu_read_unlock(); |
| 1035 | nfs_inode_return_delegation(inode); |
| 1036 | } |
| 1037 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1038 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1039 | { |
| 1040 | struct nfs4_state *state = opendata->state; |
| 1041 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1042 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1043 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1044 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1045 | nfs4_stateid stateid; |
| 1046 | int ret = -EAGAIN; |
| 1047 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1049 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1050 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1051 | if (can_open_cached(state, fmode, open_mode)) { |
| 1052 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1053 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1054 | goto out_return_state; |
| 1055 | } |
| 1056 | spin_unlock(&state->owner->so_lock); |
| 1057 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1058 | rcu_read_lock(); |
| 1059 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1060 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1061 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1062 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1063 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1064 | /* Save the delegation */ |
| 1065 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1066 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1067 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1068 | if (ret != 0) |
| 1069 | goto out; |
| 1070 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1071 | |
| 1072 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1073 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1074 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1075 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | out: |
| 1077 | return ERR_PTR(ret); |
| 1078 | out_return_state: |
| 1079 | atomic_inc(&state->count); |
| 1080 | return state; |
| 1081 | } |
| 1082 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1083 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1084 | { |
| 1085 | struct inode *inode; |
| 1086 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1087 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1088 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1089 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1090 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1091 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1092 | goto out; |
| 1093 | } |
| 1094 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1095 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1096 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1097 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1098 | 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] | 1099 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1100 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1101 | goto err; |
| 1102 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1103 | state = nfs4_get_open_state(inode, data->owner); |
| 1104 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1105 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1106 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1107 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1108 | int delegation_flags = 0; |
| 1109 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1110 | rcu_read_lock(); |
| 1111 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1112 | if (delegation) |
| 1113 | delegation_flags = delegation->flags; |
| 1114 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1115 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1116 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1117 | "returning a delegation for " |
| 1118 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1119 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1120 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1121 | nfs_inode_set_delegation(state->inode, |
| 1122 | data->owner->so_cred, |
| 1123 | &data->o_res); |
| 1124 | else |
| 1125 | nfs_inode_reclaim_delegation(state->inode, |
| 1126 | data->owner->so_cred, |
| 1127 | &data->o_res); |
| 1128 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1129 | |
| 1130 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1131 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1132 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1133 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1134 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1135 | err_put_inode: |
| 1136 | iput(inode); |
| 1137 | err: |
| 1138 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1139 | } |
| 1140 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1141 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1142 | { |
| 1143 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1144 | struct nfs_open_context *ctx; |
| 1145 | |
| 1146 | spin_lock(&state->inode->i_lock); |
| 1147 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1148 | if (ctx->state != state) |
| 1149 | continue; |
| 1150 | get_nfs_open_context(ctx); |
| 1151 | spin_unlock(&state->inode->i_lock); |
| 1152 | return ctx; |
| 1153 | } |
| 1154 | spin_unlock(&state->inode->i_lock); |
| 1155 | return ERR_PTR(-ENOENT); |
| 1156 | } |
| 1157 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1158 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1159 | { |
| 1160 | struct nfs4_opendata *opendata; |
| 1161 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1162 | 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] | 1163 | if (opendata == NULL) |
| 1164 | return ERR_PTR(-ENOMEM); |
| 1165 | opendata->state = state; |
| 1166 | atomic_inc(&state->count); |
| 1167 | return opendata; |
| 1168 | } |
| 1169 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1170 | 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] | 1171 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1172 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1173 | int ret; |
| 1174 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1175 | opendata->o_arg.open_flags = 0; |
| 1176 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1177 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1178 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1179 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1180 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1181 | if (ret != 0) |
| 1182 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1183 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1184 | if (IS_ERR(newstate)) |
| 1185 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1186 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1187 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1192 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1194 | int ret; |
| 1195 | |
| 1196 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1197 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | smp_rmb(); |
| 1199 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1200 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1201 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1202 | if (ret != 0) |
| 1203 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | if (newstate != state) |
| 1205 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1206 | } |
| 1207 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1208 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1209 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | if (ret != 0) |
| 1211 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1212 | if (newstate != state) |
| 1213 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1214 | } |
| 1215 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1216 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1217 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | if (ret != 0) |
| 1219 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1220 | if (newstate != state) |
| 1221 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1223 | /* |
| 1224 | * We may have performed cached opens for all three recoveries. |
| 1225 | * Check if we need to update the current stateid. |
| 1226 | */ |
| 1227 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1228 | memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1229 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1230 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1231 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1232 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1233 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | return 0; |
| 1235 | } |
| 1236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | /* |
| 1238 | * OPEN_RECLAIM: |
| 1239 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1241 | 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] | 1242 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1243 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1244 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1245 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | int status; |
| 1247 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1248 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1249 | if (IS_ERR(opendata)) |
| 1250 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1252 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1253 | rcu_read_lock(); |
| 1254 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1255 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1256 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1257 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1258 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1259 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1260 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | return status; |
| 1262 | } |
| 1263 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1264 | 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] | 1265 | { |
| 1266 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1267 | struct nfs4_exception exception = { }; |
| 1268 | int err; |
| 1269 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1270 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1271 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1272 | break; |
| 1273 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | } while (exception.retry); |
| 1275 | return err; |
| 1276 | } |
| 1277 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1278 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1279 | { |
| 1280 | struct nfs_open_context *ctx; |
| 1281 | int ret; |
| 1282 | |
| 1283 | ctx = nfs4_state_find_open_context(state); |
| 1284 | if (IS_ERR(ctx)) |
| 1285 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1286 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1287 | put_nfs_open_context(ctx); |
| 1288 | return ret; |
| 1289 | } |
| 1290 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1291 | 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] | 1292 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1293 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1294 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1296 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1297 | if (IS_ERR(opendata)) |
| 1298 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1299 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1300 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1301 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1302 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1303 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1304 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1307 | 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] | 1308 | { |
| 1309 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1310 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | int err; |
| 1312 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1313 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | switch (err) { |
| 1315 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1316 | case -ENOENT: |
| 1317 | case -ESTALE: |
| 1318 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1319 | case -NFS4ERR_BADSESSION: |
| 1320 | case -NFS4ERR_BADSLOT: |
| 1321 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1322 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1323 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1324 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1325 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | case -NFS4ERR_STALE_CLIENTID: |
| 1327 | case -NFS4ERR_STALE_STATEID: |
| 1328 | case -NFS4ERR_EXPIRED: |
| 1329 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1330 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1331 | goto out; |
| 1332 | case -ERESTARTSYS: |
| 1333 | /* |
| 1334 | * The show must go on: exit, but mark the |
| 1335 | * stateid as needing recovery. |
| 1336 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1337 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1338 | case -NFS4ERR_ADMIN_REVOKED: |
| 1339 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1340 | nfs_inode_find_state_and_recover(state->inode, |
| 1341 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1342 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1343 | case -EKEYEXPIRED: |
| 1344 | /* |
| 1345 | * User RPCSEC_GSS context has expired. |
| 1346 | * We cannot recover this stateid now, so |
| 1347 | * skip it and allow recovery thread to |
| 1348 | * proceed. |
| 1349 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1350 | case -ENOMEM: |
| 1351 | err = 0; |
| 1352 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } |
| 1354 | err = nfs4_handle_exception(server, err, &exception); |
| 1355 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1356 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | return err; |
| 1358 | } |
| 1359 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1360 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1361 | { |
| 1362 | struct nfs4_opendata *data = calldata; |
| 1363 | |
| 1364 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1365 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1366 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1367 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1368 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1369 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1370 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1371 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | static void nfs4_open_confirm_release(void *calldata) |
| 1375 | { |
| 1376 | struct nfs4_opendata *data = calldata; |
| 1377 | struct nfs4_state *state = NULL; |
| 1378 | |
| 1379 | /* If this request hasn't been cancelled, do nothing */ |
| 1380 | if (data->cancelled == 0) |
| 1381 | goto out_free; |
| 1382 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1383 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1384 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1385 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1386 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1387 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1388 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1389 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1393 | .rpc_call_done = nfs4_open_confirm_done, |
| 1394 | .rpc_release = nfs4_open_confirm_release, |
| 1395 | }; |
| 1396 | |
| 1397 | /* |
| 1398 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1399 | */ |
| 1400 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1401 | { |
| 1402 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1403 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1404 | struct rpc_message msg = { |
| 1405 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1406 | .rpc_argp = &data->c_arg, |
| 1407 | .rpc_resp = &data->c_res, |
| 1408 | .rpc_cred = data->owner->so_cred, |
| 1409 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1410 | struct rpc_task_setup task_setup_data = { |
| 1411 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1412 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1413 | .callback_ops = &nfs4_open_confirm_ops, |
| 1414 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1415 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1416 | .flags = RPC_TASK_ASYNC, |
| 1417 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | int status; |
| 1419 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1420 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1421 | data->rpc_done = 0; |
| 1422 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1423 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1424 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1425 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1426 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1427 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1428 | if (status != 0) { |
| 1429 | data->cancelled = 1; |
| 1430 | smp_wmb(); |
| 1431 | } else |
| 1432 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1433 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | return status; |
| 1435 | } |
| 1436 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1437 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1439 | struct nfs4_opendata *data = calldata; |
| 1440 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1441 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1442 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1443 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1444 | /* |
| 1445 | * Check if we still need to send an OPEN call, or if we can use |
| 1446 | * a delegation instead. |
| 1447 | */ |
| 1448 | if (data->state != NULL) { |
| 1449 | struct nfs_delegation *delegation; |
| 1450 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1451 | 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] | 1452 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1453 | rcu_read_lock(); |
| 1454 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1455 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1456 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1457 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1458 | rcu_read_unlock(); |
| 1459 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1460 | /* Update sequence id. */ |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1461 | data->o_arg.id = sp->so_seqid.owner_id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1462 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1463 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1464 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1465 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1466 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1467 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1468 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1469 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1470 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1471 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1472 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1473 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1474 | unlock_no_action: |
| 1475 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1476 | out_no_action: |
| 1477 | task->tk_action = NULL; |
| 1478 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1481 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1482 | { |
| 1483 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1484 | nfs4_open_prepare(task, calldata); |
| 1485 | } |
| 1486 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1487 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1488 | { |
| 1489 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1491 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1492 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1493 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1494 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1495 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | if (task->tk_status == 0) { |
| 1497 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1498 | case S_IFREG: |
| 1499 | break; |
| 1500 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1502 | break; |
| 1503 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1505 | break; |
| 1506 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1507 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1508 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1509 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1510 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1511 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1512 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1513 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1514 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1515 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1516 | static void nfs4_open_release(void *calldata) |
| 1517 | { |
| 1518 | struct nfs4_opendata *data = calldata; |
| 1519 | struct nfs4_state *state = NULL; |
| 1520 | |
| 1521 | /* If this request hasn't been cancelled, do nothing */ |
| 1522 | if (data->cancelled == 0) |
| 1523 | goto out_free; |
| 1524 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1525 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1526 | goto out_free; |
| 1527 | /* In case we need an open_confirm, no cleanup! */ |
| 1528 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1529 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1530 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1531 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1532 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1534 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1538 | .rpc_call_prepare = nfs4_open_prepare, |
| 1539 | .rpc_call_done = nfs4_open_done, |
| 1540 | .rpc_release = nfs4_open_release, |
| 1541 | }; |
| 1542 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1543 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1544 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1545 | .rpc_call_done = nfs4_open_done, |
| 1546 | .rpc_release = nfs4_open_release, |
| 1547 | }; |
| 1548 | |
| 1549 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1550 | { |
| 1551 | struct inode *dir = data->dir->d_inode; |
| 1552 | struct nfs_server *server = NFS_SERVER(dir); |
| 1553 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1554 | struct nfs_openres *o_res = &data->o_res; |
| 1555 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1556 | struct rpc_message msg = { |
| 1557 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1558 | .rpc_argp = o_arg, |
| 1559 | .rpc_resp = o_res, |
| 1560 | .rpc_cred = data->owner->so_cred, |
| 1561 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1562 | struct rpc_task_setup task_setup_data = { |
| 1563 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1564 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1565 | .callback_ops = &nfs4_open_ops, |
| 1566 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1567 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1568 | .flags = RPC_TASK_ASYNC, |
| 1569 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1570 | int status; |
| 1571 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1572 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1573 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1574 | data->rpc_done = 0; |
| 1575 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1576 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1577 | if (isrecover) |
| 1578 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1579 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1580 | if (IS_ERR(task)) |
| 1581 | return PTR_ERR(task); |
| 1582 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1583 | if (status != 0) { |
| 1584 | data->cancelled = 1; |
| 1585 | smp_wmb(); |
| 1586 | } else |
| 1587 | status = data->rpc_status; |
| 1588 | rpc_put_task(task); |
| 1589 | |
| 1590 | return status; |
| 1591 | } |
| 1592 | |
| 1593 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1594 | { |
| 1595 | struct inode *dir = data->dir->d_inode; |
| 1596 | struct nfs_openres *o_res = &data->o_res; |
| 1597 | int status; |
| 1598 | |
| 1599 | status = nfs4_run_open_task(data, 1); |
| 1600 | if (status != 0 || !data->rpc_done) |
| 1601 | return status; |
| 1602 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1603 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1604 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1605 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1606 | |
| 1607 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1608 | status = _nfs4_proc_open_confirm(data); |
| 1609 | if (status != 0) |
| 1610 | return status; |
| 1611 | } |
| 1612 | |
| 1613 | return status; |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1618 | */ |
| 1619 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1620 | { |
| 1621 | struct inode *dir = data->dir->d_inode; |
| 1622 | struct nfs_server *server = NFS_SERVER(dir); |
| 1623 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1624 | struct nfs_openres *o_res = &data->o_res; |
| 1625 | int status; |
| 1626 | |
| 1627 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1628 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1629 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1630 | if (status != 0) { |
| 1631 | if (status == -NFS4ERR_BADNAME && |
| 1632 | !(o_arg->open_flags & O_CREAT)) |
| 1633 | return -ENOENT; |
| 1634 | return status; |
| 1635 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1636 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1637 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1638 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1639 | if (o_arg->open_flags & O_CREAT) { |
| 1640 | update_changeattr(dir, &o_res->cinfo); |
| 1641 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1642 | } else |
| 1643 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1644 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1645 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1647 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1649 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | } |
| 1651 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1652 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1653 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1656 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1657 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1658 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1659 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1660 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1661 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1662 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1663 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1664 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1665 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1666 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1667 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1668 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1669 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1670 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1671 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1674 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1675 | { |
| 1676 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1677 | } |
| 1678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | /* |
| 1680 | * OPEN_EXPIRED: |
| 1681 | * reclaim state on the server after a network partition. |
| 1682 | * Assumes caller holds the appropriate lock |
| 1683 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1684 | 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] | 1685 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1686 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1687 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1689 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1690 | if (IS_ERR(opendata)) |
| 1691 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1692 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1693 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1694 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1695 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1696 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1699 | 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] | 1700 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1701 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1702 | struct nfs4_exception exception = { }; |
| 1703 | int err; |
| 1704 | |
| 1705 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1706 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1707 | switch (err) { |
| 1708 | default: |
| 1709 | goto out; |
| 1710 | case -NFS4ERR_GRACE: |
| 1711 | case -NFS4ERR_DELAY: |
| 1712 | nfs4_handle_exception(server, err, &exception); |
| 1713 | err = 0; |
| 1714 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1715 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1716 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1717 | return err; |
| 1718 | } |
| 1719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1721 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1725 | ctx = nfs4_state_find_open_context(state); |
| 1726 | if (IS_ERR(ctx)) |
| 1727 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1728 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1729 | put_nfs_open_context(ctx); |
| 1730 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1733 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1734 | 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] | 1735 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1736 | int status = NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1737 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1738 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1739 | if (state->flags & flags) { |
| 1740 | status = nfs41_test_stateid(server, stateid); |
| 1741 | if (status != NFS_OK) { |
| 1742 | nfs41_free_stateid(server, stateid); |
| 1743 | state->flags &= ~flags; |
| 1744 | } |
| 1745 | } |
| 1746 | return status; |
| 1747 | } |
| 1748 | |
| 1749 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1750 | { |
| 1751 | int deleg_status, open_status; |
| 1752 | int deleg_flags = 1 << NFS_DELEGATED_STATE; |
| 1753 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); |
| 1754 | |
| 1755 | deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); |
| 1756 | open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags); |
| 1757 | |
| 1758 | if ((deleg_status == NFS_OK) && (open_status == NFS_OK)) |
| 1759 | return NFS_OK; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1760 | return nfs4_open_expired(sp, state); |
| 1761 | } |
| 1762 | #endif |
| 1763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1765 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1766 | * fields corresponding to attributes that were used to store the verifier. |
| 1767 | * Make sure we clobber those fields in the later setattr call |
| 1768 | */ |
| 1769 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1770 | { |
| 1771 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1772 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1773 | sattr->ia_valid |= ATTR_ATIME; |
| 1774 | |
| 1775 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1776 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1777 | sattr->ia_valid |= ATTR_MTIME; |
| 1778 | } |
| 1779 | |
| 1780 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1781 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1783 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
| 1785 | struct nfs4_state_owner *sp; |
| 1786 | struct nfs4_state *state = NULL; |
| 1787 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1788 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1789 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
| 1791 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1793 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1794 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1796 | goto out_err; |
| 1797 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1798 | status = nfs4_recover_expired_lease(server); |
| 1799 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1800 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1801 | if (dentry->d_inode != NULL) |
| 1802 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1803 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1804 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1805 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1806 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1808 | if (dentry->d_inode != NULL) |
| 1809 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1810 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1811 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1813 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1815 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1816 | status = PTR_ERR(state); |
| 1817 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1818 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1819 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1820 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1821 | |
| 1822 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1823 | nfs4_exclusive_attrset(opendata, sattr); |
| 1824 | |
| 1825 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1826 | status = nfs4_do_setattr(state->inode, cred, |
| 1827 | opendata->o_res.f_attr, sattr, |
| 1828 | state); |
| 1829 | if (status == 0) |
| 1830 | nfs_setattr_update_inode(state->inode, sattr); |
| 1831 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1832 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1833 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | *res = state; |
| 1836 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1837 | err_opendata_put: |
| 1838 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1839 | err_put_state_owner: |
| 1840 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | *res = NULL; |
| 1843 | return status; |
| 1844 | } |
| 1845 | |
| 1846 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1847 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | { |
| 1849 | struct nfs4_exception exception = { }; |
| 1850 | struct nfs4_state *res; |
| 1851 | int status; |
| 1852 | |
| 1853 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1854 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | if (status == 0) |
| 1856 | break; |
| 1857 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1858 | * book-keeping w.r.t. state-changing operations |
| 1859 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1860 | * It is actually a sign of a bug on the client or on the server. |
| 1861 | * |
| 1862 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1863 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | * have unhashed the old state_owner for us, and that we can |
| 1865 | * therefore safely retry using a new one. We should still warn |
| 1866 | * the user though... |
| 1867 | */ |
| 1868 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1869 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1870 | " returned a bad sequence-id error!\n", |
| 1871 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | exception.retry = 1; |
| 1873 | continue; |
| 1874 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1875 | /* |
| 1876 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1877 | * state before it received the OPEN_CONFIRM. |
| 1878 | * Recover by retrying the request as per the discussion |
| 1879 | * on Page 181 of RFC3530. |
| 1880 | */ |
| 1881 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1882 | exception.retry = 1; |
| 1883 | continue; |
| 1884 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1885 | if (status == -EAGAIN) { |
| 1886 | /* We must have found a delegation */ |
| 1887 | exception.retry = 1; |
| 1888 | continue; |
| 1889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1891 | status, &exception)); |
| 1892 | } while (exception.retry); |
| 1893 | return res; |
| 1894 | } |
| 1895 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1896 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1897 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1898 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1900 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1902 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | .iap = sattr, |
| 1904 | .server = server, |
| 1905 | .bitmask = server->attr_bitmask, |
| 1906 | }; |
| 1907 | struct nfs_setattrres res = { |
| 1908 | .fattr = fattr, |
| 1909 | .server = server, |
| 1910 | }; |
| 1911 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1912 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1913 | .rpc_argp = &arg, |
| 1914 | .rpc_resp = &res, |
| 1915 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1917 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1918 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1920 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1922 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1923 | /* Use that stateid */ |
| 1924 | } else if (state != NULL) { |
Trond Myklebust | 1e3987c | 2012-03-04 18:13:56 -0500 | [diff] [blame^] | 1925 | nfs4_select_rw_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1926 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1928 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1929 | 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] | 1930 | if (status == 0 && state != NULL) |
| 1931 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1932 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1935 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1936 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1937 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1939 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1940 | struct nfs4_exception exception = { |
| 1941 | .state = state, |
| 1942 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | int err; |
| 1944 | do { |
| 1945 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1946 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | &exception); |
| 1948 | } while (exception.retry); |
| 1949 | return err; |
| 1950 | } |
| 1951 | |
| 1952 | struct nfs4_closedata { |
| 1953 | struct inode *inode; |
| 1954 | struct nfs4_state *state; |
| 1955 | struct nfs_closeargs arg; |
| 1956 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1957 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1958 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1959 | bool roc; |
| 1960 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | }; |
| 1962 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1963 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1964 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1965 | struct nfs4_closedata *calldata = data; |
| 1966 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1967 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1968 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1969 | if (calldata->roc) |
| 1970 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1971 | nfs4_put_open_state(calldata->state); |
| 1972 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1973 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1974 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1975 | kfree(calldata); |
| 1976 | } |
| 1977 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1978 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1979 | fmode_t fmode) |
| 1980 | { |
| 1981 | spin_lock(&state->owner->so_lock); |
| 1982 | if (!(fmode & FMODE_READ)) |
| 1983 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1984 | if (!(fmode & FMODE_WRITE)) |
| 1985 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1986 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1987 | spin_unlock(&state->owner->so_lock); |
| 1988 | } |
| 1989 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1990 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1992 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1995 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 1996 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1997 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1998 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | /* hmm. we are done with the inode, and in the process of freeing |
| 2000 | * the state_owner. we keep this around to process errors |
| 2001 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | switch (task->tk_status) { |
| 2003 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2004 | if (calldata->roc) |
| 2005 | pnfs_roc_set_barrier(state->inode, |
| 2006 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2007 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2008 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2009 | nfs4_close_clear_stateid_flags(state, |
| 2010 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | break; |
| 2012 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2013 | case -NFS4ERR_OLD_STATEID: |
| 2014 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2016 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2017 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2019 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2020 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2022 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2023 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2024 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2027 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2029 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2030 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2031 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2032 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2033 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2034 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2035 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2036 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2037 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2038 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2039 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2040 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2041 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2042 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2043 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2044 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2045 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2046 | } |
| 2047 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2048 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2049 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2050 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2051 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2052 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2053 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2054 | |
| 2055 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2056 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2057 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2058 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2059 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2060 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2061 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2062 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2063 | if (calldata->roc && |
| 2064 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2065 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2066 | task, NULL); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2067 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2068 | } |
| 2069 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2070 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2071 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2072 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2073 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2074 | &calldata->arg.seq_args, |
| 2075 | &calldata->res.seq_res, |
| 2076 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2077 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2078 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2079 | out: |
| 2080 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2083 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2084 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2085 | .rpc_call_done = nfs4_close_done, |
| 2086 | .rpc_release = nfs4_free_closedata, |
| 2087 | }; |
| 2088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | /* |
| 2090 | * It is possible for data to be read/written from a mem-mapped file |
| 2091 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2092 | * This means that we can't safely call nfsv4 close on a file until |
| 2093 | * the inode is cleared. This in turn means that we are not good |
| 2094 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2095 | * share state even when we are done with one of the three share |
| 2096 | * stateid's in the inode. |
| 2097 | * |
| 2098 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2099 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2100 | 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] | 2101 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2102 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2104 | struct nfs4_state_owner *sp = state->owner; |
| 2105 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2106 | struct rpc_message msg = { |
| 2107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2108 | .rpc_cred = state->owner->so_cred, |
| 2109 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2110 | struct rpc_task_setup task_setup_data = { |
| 2111 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2112 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2113 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2114 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2115 | .flags = RPC_TASK_ASYNC, |
| 2116 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2117 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2119 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2121 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2122 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2123 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2125 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2126 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2128 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2129 | if (calldata->arg.seqid == NULL) |
| 2130 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2131 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2132 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2133 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2134 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2135 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2136 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2137 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2138 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2139 | msg.rpc_argp = &calldata->arg; |
| 2140 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2141 | task_setup_data.callback_data = calldata; |
| 2142 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2143 | if (IS_ERR(task)) |
| 2144 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2145 | status = 0; |
| 2146 | if (wait) |
| 2147 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2148 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2149 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2150 | out_free_calldata: |
| 2151 | kfree(calldata); |
| 2152 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2153 | if (roc) |
| 2154 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2155 | nfs4_put_open_state(state); |
| 2156 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2157 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2160 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2161 | 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] | 2162 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | struct nfs4_state *state; |
| 2164 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2165 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2166 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2167 | if (IS_ERR(state)) |
| 2168 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2169 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2170 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2173 | 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] | 2174 | { |
| 2175 | if (ctx->state == NULL) |
| 2176 | return; |
| 2177 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2178 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2179 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2180 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
| 2183 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2184 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2185 | struct nfs4_server_caps_arg args = { |
| 2186 | .fhandle = fhandle, |
| 2187 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | struct nfs4_server_caps_res res = {}; |
| 2189 | struct rpc_message msg = { |
| 2190 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2191 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | .rpc_resp = &res, |
| 2193 | }; |
| 2194 | int status; |
| 2195 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2196 | 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] | 2197 | if (status == 0) { |
| 2198 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2199 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2200 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2201 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2202 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2203 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2205 | server->caps |= NFS_CAP_ACLS; |
| 2206 | if (res.has_links != 0) |
| 2207 | server->caps |= NFS_CAP_HARDLINKS; |
| 2208 | if (res.has_symlinks != 0) |
| 2209 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2210 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2211 | server->caps |= NFS_CAP_FILEID; |
| 2212 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2213 | server->caps |= NFS_CAP_MODE; |
| 2214 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2215 | server->caps |= NFS_CAP_NLINK; |
| 2216 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2217 | server->caps |= NFS_CAP_OWNER; |
| 2218 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2219 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2220 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2221 | server->caps |= NFS_CAP_ATIME; |
| 2222 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2223 | server->caps |= NFS_CAP_CTIME; |
| 2224 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2225 | server->caps |= NFS_CAP_MTIME; |
| 2226 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2227 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2228 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2229 | 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] | 2230 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2231 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | return status; |
| 2235 | } |
| 2236 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2237 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | { |
| 2239 | struct nfs4_exception exception = { }; |
| 2240 | int err; |
| 2241 | do { |
| 2242 | err = nfs4_handle_exception(server, |
| 2243 | _nfs4_server_capabilities(server, fhandle), |
| 2244 | &exception); |
| 2245 | } while (exception.retry); |
| 2246 | return err; |
| 2247 | } |
| 2248 | |
| 2249 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2250 | struct nfs_fsinfo *info) |
| 2251 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | struct nfs4_lookup_root_arg args = { |
| 2253 | .bitmask = nfs4_fattr_bitmap, |
| 2254 | }; |
| 2255 | struct nfs4_lookup_res res = { |
| 2256 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2257 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | .fh = fhandle, |
| 2259 | }; |
| 2260 | struct rpc_message msg = { |
| 2261 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2262 | .rpc_argp = &args, |
| 2263 | .rpc_resp = &res, |
| 2264 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2265 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2266 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2267 | 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] | 2268 | } |
| 2269 | |
| 2270 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2271 | struct nfs_fsinfo *info) |
| 2272 | { |
| 2273 | struct nfs4_exception exception = { }; |
| 2274 | int err; |
| 2275 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2276 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2277 | switch (err) { |
| 2278 | case 0: |
| 2279 | case -NFS4ERR_WRONGSEC: |
| 2280 | break; |
| 2281 | default: |
| 2282 | err = nfs4_handle_exception(server, err, &exception); |
| 2283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } while (exception.retry); |
| 2285 | return err; |
| 2286 | } |
| 2287 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2288 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2289 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2290 | { |
| 2291 | struct rpc_auth *auth; |
| 2292 | int ret; |
| 2293 | |
| 2294 | auth = rpcauth_create(flavor, server->client); |
| 2295 | if (!auth) { |
| 2296 | ret = -EIO; |
| 2297 | goto out; |
| 2298 | } |
| 2299 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2300 | out: |
| 2301 | return ret; |
| 2302 | } |
| 2303 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2304 | 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] | 2305 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2307 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2308 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2310 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2311 | flav_array[len] = RPC_AUTH_NULL; |
| 2312 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2313 | |
| 2314 | for (i = 0; i < len; i++) { |
| 2315 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2316 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2317 | continue; |
| 2318 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2319 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2320 | /* |
| 2321 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2322 | * to access the mount. It could also mean that we tried to mount |
| 2323 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2324 | * existing mount programs don't handle -EACCES very well so it should |
| 2325 | * be mapped to -EPERM instead. |
| 2326 | */ |
| 2327 | if (status == -EACCES) |
| 2328 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2329 | return status; |
| 2330 | } |
| 2331 | |
| 2332 | /* |
| 2333 | * get the file handle for the "/" directory on the server |
| 2334 | */ |
| 2335 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2336 | struct nfs_fsinfo *info) |
| 2337 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2338 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2339 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2340 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2341 | /* |
| 2342 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2343 | * by nfs4_map_errors() as this function exits. |
| 2344 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2345 | 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] | 2346 | if (status == 0) |
| 2347 | status = nfs4_server_capabilities(server, fhandle); |
| 2348 | if (status == 0) |
| 2349 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2350 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2353 | /* |
| 2354 | * Get locations and (maybe) other attributes of a referral. |
| 2355 | * Note that we'll actually follow the referral later when |
| 2356 | * we detect fsid mismatch in inode revalidation |
| 2357 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2358 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2359 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2360 | { |
| 2361 | int status = -ENOMEM; |
| 2362 | struct page *page = NULL; |
| 2363 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2364 | |
| 2365 | page = alloc_page(GFP_KERNEL); |
| 2366 | if (page == NULL) |
| 2367 | goto out; |
| 2368 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2369 | if (locations == NULL) |
| 2370 | goto out; |
| 2371 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2372 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2373 | if (status != 0) |
| 2374 | goto out; |
| 2375 | /* Make sure server returned a different fsid for the referral */ |
| 2376 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2377 | dprintk("%s: server did not return a different fsid for" |
| 2378 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2379 | status = -EIO; |
| 2380 | goto out; |
| 2381 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2382 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2383 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2384 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2385 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2386 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2387 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2388 | out: |
| 2389 | if (page) |
| 2390 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2391 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2392 | return status; |
| 2393 | } |
| 2394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2396 | { |
| 2397 | struct nfs4_getattr_arg args = { |
| 2398 | .fh = fhandle, |
| 2399 | .bitmask = server->attr_bitmask, |
| 2400 | }; |
| 2401 | struct nfs4_getattr_res res = { |
| 2402 | .fattr = fattr, |
| 2403 | .server = server, |
| 2404 | }; |
| 2405 | struct rpc_message msg = { |
| 2406 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2407 | .rpc_argp = &args, |
| 2408 | .rpc_resp = &res, |
| 2409 | }; |
| 2410 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2411 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2412 | 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] | 2413 | } |
| 2414 | |
| 2415 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2416 | { |
| 2417 | struct nfs4_exception exception = { }; |
| 2418 | int err; |
| 2419 | do { |
| 2420 | err = nfs4_handle_exception(server, |
| 2421 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2422 | &exception); |
| 2423 | } while (exception.retry); |
| 2424 | return err; |
| 2425 | } |
| 2426 | |
| 2427 | /* |
| 2428 | * The file is not closed if it is opened due to the a request to change |
| 2429 | * the size of the file. The open call will not be needed once the |
| 2430 | * VFS layer lookup-intents are implemented. |
| 2431 | * |
| 2432 | * Close is called when the inode is destroyed. |
| 2433 | * If we haven't opened the file for O_WRONLY, we |
| 2434 | * need to in the size_change case to obtain a stateid. |
| 2435 | * |
| 2436 | * Got race? |
| 2437 | * Because OPEN is always done by name in nfsv4, it is |
| 2438 | * possible that we opened a different file by the same |
| 2439 | * name. We can recognize this race condition, but we |
| 2440 | * can't do anything about it besides returning an error. |
| 2441 | * |
| 2442 | * This will be fixed with VFS changes (lookup-intent). |
| 2443 | */ |
| 2444 | static int |
| 2445 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2446 | struct iattr *sattr) |
| 2447 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2448 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2449 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2450 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | int status; |
| 2452 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2453 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2454 | pnfs_return_layout(inode); |
| 2455 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2456 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2458 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2459 | if (sattr->ia_valid & ATTR_FILE) { |
| 2460 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2461 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2462 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2463 | if (ctx) { |
| 2464 | cred = ctx->cred; |
| 2465 | state = ctx->state; |
| 2466 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2467 | } |
| 2468 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 2469 | /* Deal with open(O_TRUNC) */ |
| 2470 | if (sattr->ia_valid & ATTR_OPEN) |
| 2471 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2472 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2473 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2474 | if (status == 0) |
| 2475 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | return status; |
| 2477 | } |
| 2478 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2479 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2480 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2481 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2482 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2483 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2484 | int status; |
| 2485 | struct nfs4_lookup_arg args = { |
| 2486 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2487 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2488 | .name = name, |
| 2489 | }; |
| 2490 | struct nfs4_lookup_res res = { |
| 2491 | .server = server, |
| 2492 | .fattr = fattr, |
| 2493 | .fh = fhandle, |
| 2494 | }; |
| 2495 | struct rpc_message msg = { |
| 2496 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2497 | .rpc_argp = &args, |
| 2498 | .rpc_resp = &res, |
| 2499 | }; |
| 2500 | |
| 2501 | nfs_fattr_init(fattr); |
| 2502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2504 | 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] | 2505 | dprintk("NFS reply lookup: %d\n", status); |
| 2506 | return status; |
| 2507 | } |
| 2508 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2509 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2510 | { |
| 2511 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2512 | fattr->fsid.major = 1; |
| 2513 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2514 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2515 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2516 | fattr->nlink = 2; |
| 2517 | } |
| 2518 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2519 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2520 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | { |
| 2522 | struct nfs4_exception exception = { }; |
| 2523 | int err; |
| 2524 | do { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2525 | int status; |
| 2526 | |
| 2527 | status = _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr); |
| 2528 | switch (status) { |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2529 | case -NFS4ERR_BADNAME: |
| 2530 | return -ENOENT; |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2531 | case -NFS4ERR_MOVED: |
Trond Myklebust | a6f498a | 2011-11-07 15:50:32 -0500 | [diff] [blame] | 2532 | return nfs4_get_referral(dir, name, fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2533 | case -NFS4ERR_WRONGSEC: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2534 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2535 | } |
| 2536 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2537 | status, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | } while (exception.retry); |
| 2539 | return err; |
| 2540 | } |
| 2541 | |
| 2542 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2543 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2544 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | struct nfs4_accessargs args = { |
| 2546 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2547 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2549 | struct nfs4_accessres res = { |
| 2550 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2551 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | struct rpc_message msg = { |
| 2553 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2554 | .rpc_argp = &args, |
| 2555 | .rpc_resp = &res, |
| 2556 | .rpc_cred = entry->cred, |
| 2557 | }; |
| 2558 | int mode = entry->mask; |
| 2559 | int status; |
| 2560 | |
| 2561 | /* |
| 2562 | * Determine which access bits we want to ask for... |
| 2563 | */ |
| 2564 | if (mode & MAY_READ) |
| 2565 | args.access |= NFS4_ACCESS_READ; |
| 2566 | if (S_ISDIR(inode->i_mode)) { |
| 2567 | if (mode & MAY_WRITE) |
| 2568 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2569 | if (mode & MAY_EXEC) |
| 2570 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2571 | } else { |
| 2572 | if (mode & MAY_WRITE) |
| 2573 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2574 | if (mode & MAY_EXEC) |
| 2575 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2576 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2577 | |
| 2578 | res.fattr = nfs_alloc_fattr(); |
| 2579 | if (res.fattr == NULL) |
| 2580 | return -ENOMEM; |
| 2581 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2582 | 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] | 2583 | if (!status) { |
| 2584 | entry->mask = 0; |
| 2585 | if (res.access & NFS4_ACCESS_READ) |
| 2586 | entry->mask |= MAY_READ; |
| 2587 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2588 | entry->mask |= MAY_WRITE; |
| 2589 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2590 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2591 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2593 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | return status; |
| 2595 | } |
| 2596 | |
| 2597 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2598 | { |
| 2599 | struct nfs4_exception exception = { }; |
| 2600 | int err; |
| 2601 | do { |
| 2602 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2603 | _nfs4_proc_access(inode, entry), |
| 2604 | &exception); |
| 2605 | } while (exception.retry); |
| 2606 | return err; |
| 2607 | } |
| 2608 | |
| 2609 | /* |
| 2610 | * TODO: For the time being, we don't try to get any attributes |
| 2611 | * along with any of the zero-copy operations READ, READDIR, |
| 2612 | * READLINK, WRITE. |
| 2613 | * |
| 2614 | * In the case of the first three, we want to put the GETATTR |
| 2615 | * after the read-type operation -- this is because it is hard |
| 2616 | * to predict the length of a GETATTR response in v4, and thus |
| 2617 | * align the READ data correctly. This means that the GETATTR |
| 2618 | * may end up partially falling into the page cache, and we should |
| 2619 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2620 | * To do this efficiently, we need to know the total length |
| 2621 | * of data received, which doesn't seem to be available outside |
| 2622 | * of the RPC layer. |
| 2623 | * |
| 2624 | * In the case of WRITE, we also want to put the GETATTR after |
| 2625 | * the operation -- in this case because we want to make sure |
| 2626 | * we get the post-operation mtime and size. This means that |
| 2627 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2628 | * of it which would leave room in the 'tail' iovec. |
| 2629 | * |
| 2630 | * Both of these changes to the XDR layer would in fact be quite |
| 2631 | * minor, but I decided to leave them for a subsequent patch. |
| 2632 | */ |
| 2633 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2634 | unsigned int pgbase, unsigned int pglen) |
| 2635 | { |
| 2636 | struct nfs4_readlink args = { |
| 2637 | .fh = NFS_FH(inode), |
| 2638 | .pgbase = pgbase, |
| 2639 | .pglen = pglen, |
| 2640 | .pages = &page, |
| 2641 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2642 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | struct rpc_message msg = { |
| 2644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2645 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2646 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | }; |
| 2648 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2649 | 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] | 2650 | } |
| 2651 | |
| 2652 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2653 | unsigned int pgbase, unsigned int pglen) |
| 2654 | { |
| 2655 | struct nfs4_exception exception = { }; |
| 2656 | int err; |
| 2657 | do { |
| 2658 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2659 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2660 | &exception); |
| 2661 | } while (exception.retry); |
| 2662 | return err; |
| 2663 | } |
| 2664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | /* |
| 2666 | * Got race? |
| 2667 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2668 | * Until then, this create/open method is prone to inefficiency and race |
| 2669 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2670 | * placed on the wire. |
| 2671 | * |
| 2672 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2673 | * The file will be opened again in the subsequent VFS open call |
| 2674 | * (nfs4_proc_file_open). |
| 2675 | * |
| 2676 | * The open for read will just hang around to be used by any process that |
| 2677 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2678 | */ |
| 2679 | |
| 2680 | static int |
| 2681 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2682 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2684 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2686 | struct rpc_cred *cred = NULL; |
| 2687 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | int status = 0; |
| 2689 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2690 | if (ctx != NULL) { |
| 2691 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2692 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2693 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2695 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2696 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2697 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | if (IS_ERR(state)) { |
| 2699 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2700 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2702 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2703 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2704 | if (ctx != NULL) |
| 2705 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2706 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2707 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | out: |
| 2709 | return status; |
| 2710 | } |
| 2711 | |
| 2712 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2713 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2714 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2715 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2717 | .name.len = name->len, |
| 2718 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2719 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2721 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2722 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2723 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2725 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2726 | .rpc_argp = &args, |
| 2727 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2729 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2731 | res.dir_attr = nfs_alloc_fattr(); |
| 2732 | if (res.dir_attr == NULL) |
| 2733 | goto out; |
| 2734 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2735 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2736 | if (status == 0) { |
| 2737 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2738 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2739 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2740 | nfs_free_fattr(res.dir_attr); |
| 2741 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | return status; |
| 2743 | } |
| 2744 | |
| 2745 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2746 | { |
| 2747 | struct nfs4_exception exception = { }; |
| 2748 | int err; |
| 2749 | do { |
| 2750 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2751 | _nfs4_proc_remove(dir, name), |
| 2752 | &exception); |
| 2753 | } while (exception.retry); |
| 2754 | return err; |
| 2755 | } |
| 2756 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2757 | 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] | 2758 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2759 | struct nfs_server *server = NFS_SERVER(dir); |
| 2760 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2761 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2763 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2764 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2766 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2769 | 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] | 2770 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2771 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2772 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2773 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2774 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2775 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2776 | return 0; |
| 2777 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2778 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2779 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2782 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2783 | { |
| 2784 | struct nfs_server *server = NFS_SERVER(dir); |
| 2785 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2786 | struct nfs_renameres *res = msg->rpc_resp; |
| 2787 | |
| 2788 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2789 | arg->bitmask = server->attr_bitmask; |
| 2790 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2791 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2795 | struct inode *new_dir) |
| 2796 | { |
| 2797 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2798 | |
| 2799 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2800 | return 0; |
| 2801 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2802 | return 0; |
| 2803 | |
| 2804 | update_changeattr(old_dir, &res->old_cinfo); |
| 2805 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2806 | update_changeattr(new_dir, &res->new_cinfo); |
| 2807 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2808 | return 1; |
| 2809 | } |
| 2810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2812 | struct inode *new_dir, struct qstr *new_name) |
| 2813 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2814 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2815 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | .old_dir = NFS_FH(old_dir), |
| 2817 | .new_dir = NFS_FH(new_dir), |
| 2818 | .old_name = old_name, |
| 2819 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2820 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2822 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2823 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2824 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | struct rpc_message msg = { |
| 2826 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2827 | .rpc_argp = &arg, |
| 2828 | .rpc_resp = &res, |
| 2829 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2830 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2832 | res.old_fattr = nfs_alloc_fattr(); |
| 2833 | res.new_fattr = nfs_alloc_fattr(); |
| 2834 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2835 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2837 | 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] | 2838 | if (!status) { |
| 2839 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2840 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2842 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2844 | out: |
| 2845 | nfs_free_fattr(res.new_fattr); |
| 2846 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | return status; |
| 2848 | } |
| 2849 | |
| 2850 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2851 | struct inode *new_dir, struct qstr *new_name) |
| 2852 | { |
| 2853 | struct nfs4_exception exception = { }; |
| 2854 | int err; |
| 2855 | do { |
| 2856 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2857 | _nfs4_proc_rename(old_dir, old_name, |
| 2858 | new_dir, new_name), |
| 2859 | &exception); |
| 2860 | } while (exception.retry); |
| 2861 | return err; |
| 2862 | } |
| 2863 | |
| 2864 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2865 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2866 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | struct nfs4_link_arg arg = { |
| 2868 | .fh = NFS_FH(inode), |
| 2869 | .dir_fh = NFS_FH(dir), |
| 2870 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2871 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2873 | struct nfs4_link_res res = { |
| 2874 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2875 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | struct rpc_message msg = { |
| 2877 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2878 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2879 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2881 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2883 | res.fattr = nfs_alloc_fattr(); |
| 2884 | res.dir_attr = nfs_alloc_fattr(); |
| 2885 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2886 | goto out; |
| 2887 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2888 | 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] | 2889 | if (!status) { |
| 2890 | update_changeattr(dir, &res.cinfo); |
| 2891 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2892 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2893 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2894 | out: |
| 2895 | nfs_free_fattr(res.dir_attr); |
| 2896 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | return status; |
| 2898 | } |
| 2899 | |
| 2900 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2901 | { |
| 2902 | struct nfs4_exception exception = { }; |
| 2903 | int err; |
| 2904 | do { |
| 2905 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2906 | _nfs4_proc_link(inode, dir, name), |
| 2907 | &exception); |
| 2908 | } while (exception.retry); |
| 2909 | return err; |
| 2910 | } |
| 2911 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2912 | struct nfs4_createdata { |
| 2913 | struct rpc_message msg; |
| 2914 | struct nfs4_create_arg arg; |
| 2915 | struct nfs4_create_res res; |
| 2916 | struct nfs_fh fh; |
| 2917 | struct nfs_fattr fattr; |
| 2918 | struct nfs_fattr dir_fattr; |
| 2919 | }; |
| 2920 | |
| 2921 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2922 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2923 | { |
| 2924 | struct nfs4_createdata *data; |
| 2925 | |
| 2926 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2927 | if (data != NULL) { |
| 2928 | struct nfs_server *server = NFS_SERVER(dir); |
| 2929 | |
| 2930 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2931 | data->msg.rpc_argp = &data->arg; |
| 2932 | data->msg.rpc_resp = &data->res; |
| 2933 | data->arg.dir_fh = NFS_FH(dir); |
| 2934 | data->arg.server = server; |
| 2935 | data->arg.name = name; |
| 2936 | data->arg.attrs = sattr; |
| 2937 | data->arg.ftype = ftype; |
| 2938 | data->arg.bitmask = server->attr_bitmask; |
| 2939 | data->res.server = server; |
| 2940 | data->res.fh = &data->fh; |
| 2941 | data->res.fattr = &data->fattr; |
| 2942 | data->res.dir_fattr = &data->dir_fattr; |
| 2943 | nfs_fattr_init(data->res.fattr); |
| 2944 | nfs_fattr_init(data->res.dir_fattr); |
| 2945 | } |
| 2946 | return data; |
| 2947 | } |
| 2948 | |
| 2949 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2950 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2951 | 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] | 2952 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2953 | if (status == 0) { |
| 2954 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2955 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2956 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2957 | } |
| 2958 | return status; |
| 2959 | } |
| 2960 | |
| 2961 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2962 | { |
| 2963 | kfree(data); |
| 2964 | } |
| 2965 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2966 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2967 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2969 | struct nfs4_createdata *data; |
| 2970 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2972 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2973 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2974 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2975 | status = -ENOMEM; |
| 2976 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2977 | if (data == NULL) |
| 2978 | goto out; |
| 2979 | |
| 2980 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2981 | data->arg.u.symlink.pages = &page; |
| 2982 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2984 | status = nfs4_do_create(dir, dentry, data); |
| 2985 | |
| 2986 | nfs4_free_createdata(data); |
| 2987 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | return status; |
| 2989 | } |
| 2990 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2991 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2992 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | { |
| 2994 | struct nfs4_exception exception = { }; |
| 2995 | int err; |
| 2996 | do { |
| 2997 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2998 | _nfs4_proc_symlink(dir, dentry, page, |
| 2999 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | &exception); |
| 3001 | } while (exception.retry); |
| 3002 | return err; |
| 3003 | } |
| 3004 | |
| 3005 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3006 | struct iattr *sattr) |
| 3007 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3008 | struct nfs4_createdata *data; |
| 3009 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3011 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3012 | if (data == NULL) |
| 3013 | goto out; |
| 3014 | |
| 3015 | status = nfs4_do_create(dir, dentry, data); |
| 3016 | |
| 3017 | nfs4_free_createdata(data); |
| 3018 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | return status; |
| 3020 | } |
| 3021 | |
| 3022 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3023 | struct iattr *sattr) |
| 3024 | { |
| 3025 | struct nfs4_exception exception = { }; |
| 3026 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3027 | |
| 3028 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | do { |
| 3030 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3031 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3032 | &exception); |
| 3033 | } while (exception.retry); |
| 3034 | return err; |
| 3035 | } |
| 3036 | |
| 3037 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3038 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | { |
| 3040 | struct inode *dir = dentry->d_inode; |
| 3041 | struct nfs4_readdir_arg args = { |
| 3042 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3043 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | .pgbase = 0, |
| 3045 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3046 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3047 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | }; |
| 3049 | struct nfs4_readdir_res res; |
| 3050 | struct rpc_message msg = { |
| 3051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3052 | .rpc_argp = &args, |
| 3053 | .rpc_resp = &res, |
| 3054 | .rpc_cred = cred, |
| 3055 | }; |
| 3056 | int status; |
| 3057 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3058 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3059 | dentry->d_parent->d_name.name, |
| 3060 | dentry->d_name.name, |
| 3061 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3063 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3064 | 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] | 3065 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3067 | status += args.pgbase; |
| 3068 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3069 | |
| 3070 | nfs_invalidate_atime(dir); |
| 3071 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3072 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | return status; |
| 3074 | } |
| 3075 | |
| 3076 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3077 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | { |
| 3079 | struct nfs4_exception exception = { }; |
| 3080 | int err; |
| 3081 | do { |
| 3082 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3083 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3084 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | &exception); |
| 3086 | } while (exception.retry); |
| 3087 | return err; |
| 3088 | } |
| 3089 | |
| 3090 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3091 | struct iattr *sattr, dev_t rdev) |
| 3092 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3093 | struct nfs4_createdata *data; |
| 3094 | int mode = sattr->ia_mode; |
| 3095 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | |
| 3097 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3098 | 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] | 3099 | |
| 3100 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3101 | if (data == NULL) |
| 3102 | goto out; |
| 3103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3105 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3107 | data->arg.ftype = NF4BLK; |
| 3108 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3109 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | } |
| 3111 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3112 | data->arg.ftype = NF4CHR; |
| 3113 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3114 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 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_mknod(struct inode *dir, struct dentry *dentry, |
| 3125 | struct iattr *sattr, dev_t rdev) |
| 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_mknod(dir, dentry, sattr, rdev), |
| 3134 | &exception); |
| 3135 | } while (exception.retry); |
| 3136 | return err; |
| 3137 | } |
| 3138 | |
| 3139 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3140 | struct nfs_fsstat *fsstat) |
| 3141 | { |
| 3142 | struct nfs4_statfs_arg args = { |
| 3143 | .fh = fhandle, |
| 3144 | .bitmask = server->attr_bitmask, |
| 3145 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3146 | struct nfs4_statfs_res res = { |
| 3147 | .fsstat = fsstat, |
| 3148 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | struct rpc_message msg = { |
| 3150 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3151 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3152 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | }; |
| 3154 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3155 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3156 | 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] | 3157 | } |
| 3158 | |
| 3159 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3160 | { |
| 3161 | struct nfs4_exception exception = { }; |
| 3162 | int err; |
| 3163 | do { |
| 3164 | err = nfs4_handle_exception(server, |
| 3165 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3166 | &exception); |
| 3167 | } while (exception.retry); |
| 3168 | return err; |
| 3169 | } |
| 3170 | |
| 3171 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3172 | struct nfs_fsinfo *fsinfo) |
| 3173 | { |
| 3174 | struct nfs4_fsinfo_arg args = { |
| 3175 | .fh = fhandle, |
| 3176 | .bitmask = server->attr_bitmask, |
| 3177 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3178 | struct nfs4_fsinfo_res res = { |
| 3179 | .fsinfo = fsinfo, |
| 3180 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | struct rpc_message msg = { |
| 3182 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3183 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3184 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | }; |
| 3186 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3187 | 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] | 3188 | } |
| 3189 | |
| 3190 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3191 | { |
| 3192 | struct nfs4_exception exception = { }; |
| 3193 | int err; |
| 3194 | |
| 3195 | do { |
| 3196 | err = nfs4_handle_exception(server, |
| 3197 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3198 | &exception); |
| 3199 | } while (exception.retry); |
| 3200 | return err; |
| 3201 | } |
| 3202 | |
| 3203 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3204 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3205 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3207 | } |
| 3208 | |
| 3209 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3210 | struct nfs_pathconf *pathconf) |
| 3211 | { |
| 3212 | struct nfs4_pathconf_arg args = { |
| 3213 | .fh = fhandle, |
| 3214 | .bitmask = server->attr_bitmask, |
| 3215 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3216 | struct nfs4_pathconf_res res = { |
| 3217 | .pathconf = pathconf, |
| 3218 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | struct rpc_message msg = { |
| 3220 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3221 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3222 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | }; |
| 3224 | |
| 3225 | /* None of the pathconf attributes are mandatory to implement */ |
| 3226 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3227 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3228 | return 0; |
| 3229 | } |
| 3230 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3231 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3232 | 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] | 3233 | } |
| 3234 | |
| 3235 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3236 | struct nfs_pathconf *pathconf) |
| 3237 | { |
| 3238 | struct nfs4_exception exception = { }; |
| 3239 | int err; |
| 3240 | |
| 3241 | do { |
| 3242 | err = nfs4_handle_exception(server, |
| 3243 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3244 | &exception); |
| 3245 | } while (exception.retry); |
| 3246 | return err; |
| 3247 | } |
| 3248 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3249 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3250 | { |
| 3251 | nfs_invalidate_atime(data->inode); |
| 3252 | } |
| 3253 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3254 | 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] | 3255 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3256 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3258 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3259 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3260 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3262 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3263 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3265 | renew_lease(server, data->timestamp); |
| 3266 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | } |
| 3268 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3269 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3270 | { |
| 3271 | |
| 3272 | dprintk("--> %s\n", __func__); |
| 3273 | |
| 3274 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3275 | return -EAGAIN; |
| 3276 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3277 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3278 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3281 | 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] | 3282 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3284 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3285 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3286 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3289 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3290 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3291 | { |
| 3292 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3293 | put_lseg(data->lseg); |
| 3294 | data->lseg = NULL; |
| 3295 | /* offsets will differ in the dense stripe case */ |
| 3296 | data->args.offset = data->mds_offset; |
| 3297 | data->ds_clp = NULL; |
| 3298 | data->args.fh = NFS_FH(data->inode); |
| 3299 | data->read_done_cb = nfs4_read_done_cb; |
| 3300 | task->tk_ops = data->mds_ops; |
| 3301 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3302 | } |
| 3303 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3304 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3305 | 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] | 3306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | struct inode *inode = data->inode; |
| 3308 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3309 | 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] | 3310 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3311 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3313 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3315 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3316 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3317 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3320 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3321 | { |
| 3322 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3323 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3324 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3325 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3328 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3329 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3330 | { |
| 3331 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3332 | put_lseg(data->lseg); |
| 3333 | data->lseg = NULL; |
| 3334 | data->ds_clp = NULL; |
| 3335 | data->write_done_cb = nfs4_write_done_cb; |
| 3336 | data->args.fh = NFS_FH(data->inode); |
| 3337 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3338 | data->args.offset = data->mds_offset; |
| 3339 | data->res.fattr = &data->fattr; |
| 3340 | task->tk_ops = data->mds_ops; |
| 3341 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3342 | } |
| 3343 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3344 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3345 | 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] | 3346 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3347 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3348 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3349 | if (data->lseg) { |
| 3350 | data->args.bitmask = NULL; |
| 3351 | data->res.fattr = NULL; |
| 3352 | } else |
| 3353 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3354 | if (!data->write_done_cb) |
| 3355 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3356 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | data->timestamp = jiffies; |
| 3358 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3359 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3360 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3363 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3366 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3367 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3368 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3369 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3371 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3372 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3375 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3376 | { |
| 3377 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3378 | return -EAGAIN; |
| 3379 | return data->write_done_cb(task, data); |
| 3380 | } |
| 3381 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3382 | static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3384 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3385 | |
| 3386 | if (data->lseg) { |
| 3387 | data->args.bitmask = NULL; |
| 3388 | data->res.fattr = NULL; |
| 3389 | } else |
| 3390 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3391 | if (!data->write_done_cb) |
| 3392 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3393 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3394 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3395 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3398 | struct nfs4_renewdata { |
| 3399 | struct nfs_client *client; |
| 3400 | unsigned long timestamp; |
| 3401 | }; |
| 3402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | /* |
| 3404 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3405 | * standalone procedure for queueing an asynchronous RENEW. |
| 3406 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3407 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3408 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3409 | struct nfs4_renewdata *data = calldata; |
| 3410 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3411 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3412 | if (atomic_read(&clp->cl_count) > 1) |
| 3413 | nfs4_schedule_state_renewal(clp); |
| 3414 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3415 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3416 | } |
| 3417 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3418 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3420 | struct nfs4_renewdata *data = calldata; |
| 3421 | struct nfs_client *clp = data->client; |
| 3422 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
| 3424 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3425 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3426 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3427 | return; |
| 3428 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3429 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3430 | return; |
| 3431 | } |
| 3432 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3434 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3437 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3438 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3439 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3440 | }; |
| 3441 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3442 | 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] | 3443 | { |
| 3444 | struct rpc_message msg = { |
| 3445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3446 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3447 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3449 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3451 | if (renew_flags == 0) |
| 3452 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3453 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3454 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3455 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3456 | if (data == NULL) |
| 3457 | return -ENOMEM; |
| 3458 | data->client = clp; |
| 3459 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3461 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3464 | 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] | 3465 | { |
| 3466 | struct rpc_message msg = { |
| 3467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3468 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3469 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | }; |
| 3471 | unsigned long now = jiffies; |
| 3472 | int status; |
| 3473 | |
| 3474 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3475 | if (status < 0) |
| 3476 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3477 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | return 0; |
| 3479 | } |
| 3480 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3481 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3482 | { |
| 3483 | return (server->caps & NFS_CAP_ACLS) |
| 3484 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3485 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3486 | } |
| 3487 | |
| 3488 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3489 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3490 | * the stack. |
| 3491 | */ |
| 3492 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3493 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3494 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3495 | struct page **pages, unsigned int *pgbase) |
| 3496 | { |
| 3497 | struct page *newpage, **spages; |
| 3498 | int rc = 0; |
| 3499 | size_t len; |
| 3500 | spages = pages; |
| 3501 | |
| 3502 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3503 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3504 | newpage = alloc_page(GFP_KERNEL); |
| 3505 | |
| 3506 | if (newpage == NULL) |
| 3507 | goto unwind; |
| 3508 | memcpy(page_address(newpage), buf, len); |
| 3509 | buf += len; |
| 3510 | buflen -= len; |
| 3511 | *pages++ = newpage; |
| 3512 | rc++; |
| 3513 | } while (buflen != 0); |
| 3514 | |
| 3515 | return rc; |
| 3516 | |
| 3517 | unwind: |
| 3518 | for(; rc > 0; rc--) |
| 3519 | __free_page(spages[rc-1]); |
| 3520 | return -ENOMEM; |
| 3521 | } |
| 3522 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3523 | struct nfs4_cached_acl { |
| 3524 | int cached; |
| 3525 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3526 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3527 | }; |
| 3528 | |
| 3529 | 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] | 3530 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3531 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3532 | |
| 3533 | spin_lock(&inode->i_lock); |
| 3534 | kfree(nfsi->nfs4_acl); |
| 3535 | nfsi->nfs4_acl = acl; |
| 3536 | spin_unlock(&inode->i_lock); |
| 3537 | } |
| 3538 | |
| 3539 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3540 | { |
| 3541 | nfs4_set_cached_acl(inode, NULL); |
| 3542 | } |
| 3543 | |
| 3544 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3545 | { |
| 3546 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3547 | struct nfs4_cached_acl *acl; |
| 3548 | int ret = -ENOENT; |
| 3549 | |
| 3550 | spin_lock(&inode->i_lock); |
| 3551 | acl = nfsi->nfs4_acl; |
| 3552 | if (acl == NULL) |
| 3553 | goto out; |
| 3554 | if (buf == NULL) /* user is just asking for length */ |
| 3555 | goto out_len; |
| 3556 | if (acl->cached == 0) |
| 3557 | goto out; |
| 3558 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3559 | if (acl->len > buflen) |
| 3560 | goto out; |
| 3561 | memcpy(buf, acl->data, acl->len); |
| 3562 | out_len: |
| 3563 | ret = acl->len; |
| 3564 | out: |
| 3565 | spin_unlock(&inode->i_lock); |
| 3566 | return ret; |
| 3567 | } |
| 3568 | |
| 3569 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3570 | { |
| 3571 | struct nfs4_cached_acl *acl; |
| 3572 | |
| 3573 | if (buf && acl_len <= PAGE_SIZE) { |
| 3574 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3575 | if (acl == NULL) |
| 3576 | goto out; |
| 3577 | acl->cached = 1; |
| 3578 | memcpy(acl->data, buf, acl_len); |
| 3579 | } else { |
| 3580 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3581 | if (acl == NULL) |
| 3582 | goto out; |
| 3583 | acl->cached = 0; |
| 3584 | } |
| 3585 | acl->len = acl_len; |
| 3586 | out: |
| 3587 | nfs4_set_cached_acl(inode, acl); |
| 3588 | } |
| 3589 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3590 | /* |
| 3591 | * The getxattr API returns the required buffer length when called with a |
| 3592 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3593 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3594 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3595 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3596 | * the cache. If not so, we throw away the page, and cache the required |
| 3597 | * length. The next getxattr call will then produce another round trip to |
| 3598 | * the server, this time with the input buf of the required size. |
| 3599 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3600 | 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] | 3601 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3602 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3603 | struct nfs_getaclargs args = { |
| 3604 | .fh = NFS_FH(inode), |
| 3605 | .acl_pages = pages, |
| 3606 | .acl_len = buflen, |
| 3607 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3608 | struct nfs_getaclres res = { |
| 3609 | .acl_len = buflen, |
| 3610 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3611 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3612 | struct rpc_message msg = { |
| 3613 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3614 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3615 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3616 | }; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3617 | int ret = -ENOMEM, npages, i, acl_len = 0; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3618 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3619 | npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 3620 | /* As long as we're doing a round trip to the server anyway, |
| 3621 | * let's be prepared for a page of acl data. */ |
| 3622 | if (npages == 0) |
| 3623 | npages = 1; |
| 3624 | |
| 3625 | for (i = 0; i < npages; i++) { |
| 3626 | pages[i] = alloc_page(GFP_KERNEL); |
| 3627 | if (!pages[i]) |
| 3628 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3629 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3630 | if (npages > 1) { |
| 3631 | /* for decoding across pages */ |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3632 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3633 | if (!res.acl_scratch) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3634 | goto out_free; |
| 3635 | } |
| 3636 | args.acl_len = npages * PAGE_SIZE; |
| 3637 | args.acl_pgbase = 0; |
| 3638 | /* Let decode_getfacl know not to fail if the ACL data is larger than |
| 3639 | * the page we send as a guess */ |
| 3640 | if (buf == NULL) |
| 3641 | res.acl_flags |= NFS4_ACL_LEN_REQUEST; |
| 3642 | resp_buf = page_address(pages[0]); |
| 3643 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3644 | 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] | 3645 | __func__, buf, buflen, npages, args.acl_len); |
| 3646 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3647 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3648 | if (ret) |
| 3649 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3650 | |
| 3651 | acl_len = res.acl_len - res.acl_data_offset; |
| 3652 | if (acl_len > args.acl_len) |
| 3653 | nfs4_write_cached_acl(inode, NULL, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3654 | else |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3655 | nfs4_write_cached_acl(inode, resp_buf + res.acl_data_offset, |
| 3656 | acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3657 | if (buf) { |
| 3658 | ret = -ERANGE; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3659 | if (acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3660 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3661 | _copy_from_pages(buf, pages, res.acl_data_offset, |
| 3662 | res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3663 | } |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3664 | ret = acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3665 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3666 | for (i = 0; i < npages; i++) |
| 3667 | if (pages[i]) |
| 3668 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3669 | if (res.acl_scratch) |
| 3670 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3671 | return ret; |
| 3672 | } |
| 3673 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3674 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3675 | { |
| 3676 | struct nfs4_exception exception = { }; |
| 3677 | ssize_t ret; |
| 3678 | do { |
| 3679 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3680 | if (ret >= 0) |
| 3681 | break; |
| 3682 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3683 | } while (exception.retry); |
| 3684 | return ret; |
| 3685 | } |
| 3686 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3687 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3688 | { |
| 3689 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3690 | int ret; |
| 3691 | |
| 3692 | if (!nfs4_server_supports_acls(server)) |
| 3693 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3694 | ret = nfs_revalidate_inode(server, inode); |
| 3695 | if (ret < 0) |
| 3696 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3697 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3698 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3699 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3700 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3701 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3702 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3703 | return ret; |
| 3704 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3705 | } |
| 3706 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3707 | 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] | 3708 | { |
| 3709 | struct nfs_server *server = NFS_SERVER(inode); |
| 3710 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3711 | struct nfs_setaclargs arg = { |
| 3712 | .fh = NFS_FH(inode), |
| 3713 | .acl_pages = pages, |
| 3714 | .acl_len = buflen, |
| 3715 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3716 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3717 | struct rpc_message msg = { |
| 3718 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3719 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3720 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3721 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3722 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3723 | |
| 3724 | if (!nfs4_server_supports_acls(server)) |
| 3725 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3726 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3727 | if (i < 0) |
| 3728 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3729 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3730 | 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] | 3731 | |
| 3732 | /* |
| 3733 | * Free each page after tx, so the only ref left is |
| 3734 | * held by the network stack |
| 3735 | */ |
| 3736 | for (; i > 0; i--) |
| 3737 | put_page(pages[i-1]); |
| 3738 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3739 | /* |
| 3740 | * Acl update can result in inode attribute update. |
| 3741 | * so mark the attribute cache invalid. |
| 3742 | */ |
| 3743 | spin_lock(&inode->i_lock); |
| 3744 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3745 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3746 | nfs_access_zap_cache(inode); |
| 3747 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3748 | return ret; |
| 3749 | } |
| 3750 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3751 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3752 | { |
| 3753 | struct nfs4_exception exception = { }; |
| 3754 | int err; |
| 3755 | do { |
| 3756 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3757 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3758 | &exception); |
| 3759 | } while (exception.retry); |
| 3760 | return err; |
| 3761 | } |
| 3762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3764 | 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] | 3765 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3766 | struct nfs_client *clp = server->nfs_client; |
| 3767 | |
| 3768 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | return 0; |
| 3770 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3771 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3772 | case -NFS4ERR_ADMIN_REVOKED: |
| 3773 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3774 | if (state != NULL) |
| 3775 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3776 | case -NFS4ERR_OPENMODE: |
| 3777 | if (state == NULL) |
| 3778 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3779 | nfs4_schedule_stateid_recovery(server, state); |
| 3780 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3781 | case -NFS4ERR_EXPIRED: |
| 3782 | if (state != NULL) |
| 3783 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3785 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3786 | nfs4_schedule_lease_recovery(clp); |
| 3787 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3788 | #if defined(CONFIG_NFS_V4_1) |
| 3789 | case -NFS4ERR_BADSESSION: |
| 3790 | case -NFS4ERR_BADSLOT: |
| 3791 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3792 | case -NFS4ERR_DEADSESSION: |
| 3793 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3794 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3795 | case -NFS4ERR_SEQ_MISORDERED: |
| 3796 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3797 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3798 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3799 | task->tk_status = 0; |
| 3800 | return -EAGAIN; |
| 3801 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3803 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3804 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3805 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3807 | task->tk_status = 0; |
| 3808 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3809 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | case -NFS4ERR_OLD_STATEID: |
| 3811 | task->tk_status = 0; |
| 3812 | return -EAGAIN; |
| 3813 | } |
| 3814 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3815 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3816 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3817 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3818 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3819 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3820 | task->tk_status = 0; |
| 3821 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | } |
| 3823 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3824 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3825 | unsigned short port, struct rpc_cred *cred, |
| 3826 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | { |
| 3828 | nfs4_verifier sc_verifier; |
| 3829 | struct nfs4_setclientid setclientid = { |
| 3830 | .sc_verifier = &sc_verifier, |
| 3831 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3832 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | }; |
| 3834 | struct rpc_message msg = { |
| 3835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3836 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3837 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3838 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3840 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | int loop = 0; |
| 3842 | int status; |
| 3843 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3844 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3846 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3847 | |
| 3848 | for(;;) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3849 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3851 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3852 | clp->cl_ipaddr, |
| 3853 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3854 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3855 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3856 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3857 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | clp->cl_id_uniquifier); |
| 3859 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3860 | sizeof(setclientid.sc_netid), |
| 3861 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3862 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3864 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | clp->cl_ipaddr, port >> 8, port & 255); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 3866 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3868 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | if (status != -NFS4ERR_CLID_INUSE) |
| 3870 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3871 | if (loop != 0) { |
| 3872 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3874 | } |
| 3875 | ++loop; |
| 3876 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | } |
| 3878 | return status; |
| 3879 | } |
| 3880 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3881 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3882 | struct nfs4_setclientid_res *arg, |
| 3883 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | { |
| 3885 | struct nfs_fsinfo fsinfo; |
| 3886 | struct rpc_message msg = { |
| 3887 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3888 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3890 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | }; |
| 3892 | unsigned long now; |
| 3893 | int status; |
| 3894 | |
| 3895 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3896 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | if (status == 0) { |
| 3898 | spin_lock(&clp->cl_lock); |
| 3899 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3900 | clp->cl_last_renewal = now; |
| 3901 | spin_unlock(&clp->cl_lock); |
| 3902 | } |
| 3903 | return status; |
| 3904 | } |
| 3905 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3906 | struct nfs4_delegreturndata { |
| 3907 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3908 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3909 | struct nfs_fh fh; |
| 3910 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3911 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3912 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3913 | int rpc_status; |
| 3914 | }; |
| 3915 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3916 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3917 | { |
| 3918 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3919 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3920 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3921 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3922 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3923 | switch (task->tk_status) { |
| 3924 | case -NFS4ERR_STALE_STATEID: |
| 3925 | case -NFS4ERR_EXPIRED: |
| 3926 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3927 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3928 | break; |
| 3929 | default: |
| 3930 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3931 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3932 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3933 | return; |
| 3934 | } |
| 3935 | } |
| 3936 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | static void nfs4_delegreturn_release(void *calldata) |
| 3940 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3941 | kfree(calldata); |
| 3942 | } |
| 3943 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3944 | #if defined(CONFIG_NFS_V4_1) |
| 3945 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3946 | { |
| 3947 | struct nfs4_delegreturndata *d_data; |
| 3948 | |
| 3949 | d_data = (struct nfs4_delegreturndata *)data; |
| 3950 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3951 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3952 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3953 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3954 | return; |
| 3955 | rpc_call_start(task); |
| 3956 | } |
| 3957 | #endif /* CONFIG_NFS_V4_1 */ |
| 3958 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3959 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3960 | #if defined(CONFIG_NFS_V4_1) |
| 3961 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3962 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3963 | .rpc_call_done = nfs4_delegreturn_done, |
| 3964 | .rpc_release = nfs4_delegreturn_release, |
| 3965 | }; |
| 3966 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3967 | 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] | 3968 | { |
| 3969 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3970 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3971 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3972 | struct rpc_message msg = { |
| 3973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3974 | .rpc_cred = cred, |
| 3975 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3976 | struct rpc_task_setup task_setup_data = { |
| 3977 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3978 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3979 | .callback_ops = &nfs4_delegreturn_ops, |
| 3980 | .flags = RPC_TASK_ASYNC, |
| 3981 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3982 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3983 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3984 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3985 | if (data == NULL) |
| 3986 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3987 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3988 | data->args.fhandle = &data->fh; |
| 3989 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3990 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3991 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3992 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3993 | data->res.fattr = &data->fattr; |
| 3994 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3995 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3996 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3997 | data->rpc_status = 0; |
| 3998 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3999 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4000 | msg.rpc_argp = &data->args; |
| 4001 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4002 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4003 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4004 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4005 | if (!issync) |
| 4006 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4007 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4008 | if (status != 0) |
| 4009 | goto out; |
| 4010 | status = data->rpc_status; |
| 4011 | if (status != 0) |
| 4012 | goto out; |
| 4013 | nfs_refresh_inode(inode, &data->fattr); |
| 4014 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4015 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4016 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4019 | 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] | 4020 | { |
| 4021 | struct nfs_server *server = NFS_SERVER(inode); |
| 4022 | struct nfs4_exception exception = { }; |
| 4023 | int err; |
| 4024 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4025 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | switch (err) { |
| 4027 | case -NFS4ERR_STALE_STATEID: |
| 4028 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | case 0: |
| 4030 | return 0; |
| 4031 | } |
| 4032 | err = nfs4_handle_exception(server, err, &exception); |
| 4033 | } while (exception.retry); |
| 4034 | return err; |
| 4035 | } |
| 4036 | |
| 4037 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4038 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4039 | |
| 4040 | /* |
| 4041 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4042 | */ |
| 4043 | static unsigned long |
| 4044 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4045 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4046 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | timeout <<= 1; |
| 4048 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4049 | return NFS4_LOCK_MAXTIMEOUT; |
| 4050 | return timeout; |
| 4051 | } |
| 4052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4054 | { |
| 4055 | struct inode *inode = state->inode; |
| 4056 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4057 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4058 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4060 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4062 | struct nfs_lockt_res res = { |
| 4063 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | }; |
| 4065 | struct rpc_message msg = { |
| 4066 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4067 | .rpc_argp = &arg, |
| 4068 | .rpc_resp = &res, |
| 4069 | .rpc_cred = state->owner->so_cred, |
| 4070 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | struct nfs4_lock_state *lsp; |
| 4072 | int status; |
| 4073 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4074 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4075 | status = nfs4_set_lock_state(state, request); |
| 4076 | if (status != 0) |
| 4077 | goto out; |
| 4078 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4079 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4080 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4081 | 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] | 4082 | switch (status) { |
| 4083 | case 0: |
| 4084 | request->fl_type = F_UNLCK; |
| 4085 | break; |
| 4086 | case -NFS4ERR_DENIED: |
| 4087 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4089 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4090 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | return status; |
| 4092 | } |
| 4093 | |
| 4094 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4095 | { |
| 4096 | struct nfs4_exception exception = { }; |
| 4097 | int err; |
| 4098 | |
| 4099 | do { |
| 4100 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4101 | _nfs4_proc_getlk(state, cmd, request), |
| 4102 | &exception); |
| 4103 | } while (exception.retry); |
| 4104 | return err; |
| 4105 | } |
| 4106 | |
| 4107 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4108 | { |
| 4109 | int res = 0; |
| 4110 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4111 | case FL_POSIX: |
| 4112 | res = posix_lock_file_wait(file, fl); |
| 4113 | break; |
| 4114 | case FL_FLOCK: |
| 4115 | res = flock_lock_file_wait(file, fl); |
| 4116 | break; |
| 4117 | default: |
| 4118 | BUG(); |
| 4119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | return res; |
| 4121 | } |
| 4122 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4123 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4124 | struct nfs_locku_args arg; |
| 4125 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4126 | struct nfs4_lock_state *lsp; |
| 4127 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4128 | struct file_lock fl; |
| 4129 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4130 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4131 | }; |
| 4132 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4133 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4134 | struct nfs_open_context *ctx, |
| 4135 | struct nfs4_lock_state *lsp, |
| 4136 | struct nfs_seqid *seqid) |
| 4137 | { |
| 4138 | struct nfs4_unlockdata *p; |
| 4139 | struct inode *inode = lsp->ls_state->inode; |
| 4140 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4141 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4142 | if (p == NULL) |
| 4143 | return NULL; |
| 4144 | p->arg.fh = NFS_FH(inode); |
| 4145 | p->arg.fl = &p->fl; |
| 4146 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4147 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4148 | p->arg.stateid = &lsp->ls_stateid; |
| 4149 | p->lsp = lsp; |
| 4150 | atomic_inc(&lsp->ls_count); |
| 4151 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4152 | p->ctx = get_nfs_open_context(ctx); |
| 4153 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4154 | p->server = NFS_SERVER(inode); |
| 4155 | return p; |
| 4156 | } |
| 4157 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4158 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4159 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4160 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4161 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4162 | nfs4_put_lock_state(calldata->lsp); |
| 4163 | put_nfs_open_context(calldata->ctx); |
| 4164 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4167 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4168 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4169 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4170 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4171 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4172 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4173 | switch (task->tk_status) { |
| 4174 | case 0: |
| 4175 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4176 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4177 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4178 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4179 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4180 | case -NFS4ERR_BAD_STATEID: |
| 4181 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4182 | case -NFS4ERR_STALE_STATEID: |
| 4183 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4184 | break; |
| 4185 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4186 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4187 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4188 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4191 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4192 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4193 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4195 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4196 | return; |
| 4197 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4198 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4199 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4200 | return; |
| 4201 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4202 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4203 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4204 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4205 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4206 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4207 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | } |
| 4209 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4210 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4211 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4212 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4213 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4214 | }; |
| 4215 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4216 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4217 | struct nfs_open_context *ctx, |
| 4218 | struct nfs4_lock_state *lsp, |
| 4219 | struct nfs_seqid *seqid) |
| 4220 | { |
| 4221 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4222 | struct rpc_message msg = { |
| 4223 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4224 | .rpc_cred = ctx->cred, |
| 4225 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4226 | struct rpc_task_setup task_setup_data = { |
| 4227 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4228 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4229 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4230 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4231 | .flags = RPC_TASK_ASYNC, |
| 4232 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4233 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4234 | /* Ensure this is an unlock - when canceling a lock, the |
| 4235 | * canceled lock is passed in, and it won't be an unlock. |
| 4236 | */ |
| 4237 | fl->fl_type = F_UNLCK; |
| 4238 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4239 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4240 | if (data == NULL) { |
| 4241 | nfs_free_seqid(seqid); |
| 4242 | return ERR_PTR(-ENOMEM); |
| 4243 | } |
| 4244 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4245 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4246 | msg.rpc_argp = &data->arg; |
| 4247 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4248 | task_setup_data.callback_data = data; |
| 4249 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4250 | } |
| 4251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4253 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4254 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4255 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4256 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4257 | struct rpc_task *task; |
| 4258 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4259 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4261 | status = nfs4_set_lock_state(state, request); |
| 4262 | /* Unlock _before_ we do the RPC call */ |
| 4263 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4264 | down_read(&nfsi->rwsem); |
| 4265 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4266 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4267 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4268 | } |
| 4269 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4270 | if (status != 0) |
| 4271 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4272 | /* Is this a delegated lock? */ |
| 4273 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4274 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4275 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4276 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4277 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4278 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4279 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4280 | 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] | 4281 | status = PTR_ERR(task); |
| 4282 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4283 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4284 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4285 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4286 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4287 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4288 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4291 | struct nfs4_lockdata { |
| 4292 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4293 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4294 | struct nfs4_lock_state *lsp; |
| 4295 | struct nfs_open_context *ctx; |
| 4296 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4297 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4298 | int rpc_status; |
| 4299 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4300 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4301 | }; |
| 4302 | |
| 4303 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4304 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4305 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4306 | { |
| 4307 | struct nfs4_lockdata *p; |
| 4308 | struct inode *inode = lsp->ls_state->inode; |
| 4309 | struct nfs_server *server = NFS_SERVER(inode); |
| 4310 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4311 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4312 | if (p == NULL) |
| 4313 | return NULL; |
| 4314 | |
| 4315 | p->arg.fh = NFS_FH(inode); |
| 4316 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4317 | 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] | 4318 | if (p->arg.open_seqid == NULL) |
| 4319 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4320 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4321 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4322 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4323 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4324 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4325 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4326 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4327 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4328 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4329 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4330 | atomic_inc(&lsp->ls_count); |
| 4331 | p->ctx = get_nfs_open_context(ctx); |
| 4332 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4333 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4334 | out_free_seqid: |
| 4335 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4336 | out_free: |
| 4337 | kfree(p); |
| 4338 | return NULL; |
| 4339 | } |
| 4340 | |
| 4341 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4342 | { |
| 4343 | struct nfs4_lockdata *data = calldata; |
| 4344 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4346 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4347 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4348 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4349 | /* Do we need to do an open_to_lock_owner? */ |
| 4350 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4351 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4352 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4353 | data->arg.open_stateid = &state->stateid; |
| 4354 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4355 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4356 | } else |
| 4357 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4358 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4359 | if (nfs4_setup_sequence(data->server, |
| 4360 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4361 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4362 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4363 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4364 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4365 | } |
| 4366 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4367 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4368 | { |
| 4369 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4370 | nfs4_lock_prepare(task, calldata); |
| 4371 | } |
| 4372 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4373 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4374 | { |
| 4375 | struct nfs4_lockdata *data = calldata; |
| 4376 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4377 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4378 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4379 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4380 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4381 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4382 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4383 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4384 | if (data->rpc_status == 0) |
| 4385 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4386 | else |
| 4387 | goto out; |
| 4388 | } |
| 4389 | if (data->rpc_status == 0) { |
| 4390 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4391 | sizeof(data->lsp->ls_stateid.data)); |
| 4392 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4393 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4394 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4395 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4396 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | static void nfs4_lock_release(void *calldata) |
| 4400 | { |
| 4401 | struct nfs4_lockdata *data = calldata; |
| 4402 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4403 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4404 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4405 | if (data->cancelled != 0) { |
| 4406 | struct rpc_task *task; |
| 4407 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4408 | data->arg.lock_seqid); |
| 4409 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4410 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4411 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4412 | } else |
| 4413 | nfs_free_seqid(data->arg.lock_seqid); |
| 4414 | nfs4_put_lock_state(data->lsp); |
| 4415 | put_nfs_open_context(data->ctx); |
| 4416 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4417 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4421 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4422 | .rpc_call_done = nfs4_lock_done, |
| 4423 | .rpc_release = nfs4_lock_release, |
| 4424 | }; |
| 4425 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4426 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4427 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4428 | .rpc_call_done = nfs4_lock_done, |
| 4429 | .rpc_release = nfs4_lock_release, |
| 4430 | }; |
| 4431 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4432 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4433 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4434 | switch (error) { |
| 4435 | case -NFS4ERR_ADMIN_REVOKED: |
| 4436 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4437 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4438 | if (new_lock_owner != 0 || |
| 4439 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4440 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4441 | break; |
| 4442 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4443 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4444 | case -NFS4ERR_EXPIRED: |
| 4445 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4446 | }; |
| 4447 | } |
| 4448 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4449 | 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] | 4450 | { |
| 4451 | struct nfs4_lockdata *data; |
| 4452 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4453 | struct rpc_message msg = { |
| 4454 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4455 | .rpc_cred = state->owner->so_cred, |
| 4456 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4457 | struct rpc_task_setup task_setup_data = { |
| 4458 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4459 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4460 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4461 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4462 | .flags = RPC_TASK_ASYNC, |
| 4463 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4464 | int ret; |
| 4465 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4466 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4467 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4468 | fl->fl_u.nfs4_fl.owner, |
| 4469 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4470 | if (data == NULL) |
| 4471 | return -ENOMEM; |
| 4472 | if (IS_SETLKW(cmd)) |
| 4473 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4474 | if (recovery_type > NFS_LOCK_NEW) { |
| 4475 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4476 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4477 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4478 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4479 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4480 | msg.rpc_argp = &data->arg; |
| 4481 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4482 | task_setup_data.callback_data = data; |
| 4483 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4484 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4485 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4486 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4487 | if (ret == 0) { |
| 4488 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4489 | if (ret) |
| 4490 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4491 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4492 | } else |
| 4493 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4494 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4495 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4496 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4500 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4501 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4502 | struct nfs4_exception exception = { }; |
| 4503 | int err; |
| 4504 | |
| 4505 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4506 | /* Cache the lock if possible... */ |
| 4507 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4508 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4509 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4510 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4511 | break; |
| 4512 | nfs4_handle_exception(server, err, &exception); |
| 4513 | } while (exception.retry); |
| 4514 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4518 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4519 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4520 | struct nfs4_exception exception = { }; |
| 4521 | int err; |
| 4522 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4523 | err = nfs4_set_lock_state(state, request); |
| 4524 | if (err != 0) |
| 4525 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4526 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4527 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4528 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4529 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4530 | switch (err) { |
| 4531 | default: |
| 4532 | goto out; |
| 4533 | case -NFS4ERR_GRACE: |
| 4534 | case -NFS4ERR_DELAY: |
| 4535 | nfs4_handle_exception(server, err, &exception); |
| 4536 | err = 0; |
| 4537 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4538 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4539 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4540 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | } |
| 4542 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4543 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4544 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4545 | { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4546 | int status, ret = NFS_OK; |
| 4547 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4548 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4549 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4550 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 4551 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
| 4552 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4553 | if (status != NFS_OK) { |
| 4554 | nfs41_free_stateid(server, &lsp->ls_stateid); |
| 4555 | lsp->ls_flags &= ~NFS_LOCK_INITIALIZED; |
| 4556 | ret = status; |
| 4557 | } |
| 4558 | } |
| 4559 | }; |
| 4560 | |
| 4561 | return ret; |
| 4562 | } |
| 4563 | |
| 4564 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4565 | { |
| 4566 | int status = NFS_OK; |
| 4567 | |
| 4568 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4569 | status = nfs41_check_expired_locks(state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4570 | if (status == NFS_OK) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4571 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4572 | return nfs4_lock_expired(state, request); |
| 4573 | } |
| 4574 | #endif |
| 4575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4577 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4578 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4579 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4580 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4582 | if ((fl_flags & FL_POSIX) && |
| 4583 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4584 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4585 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4586 | status = nfs4_set_lock_state(state, request); |
| 4587 | if (status != 0) |
| 4588 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4589 | request->fl_flags |= FL_ACCESS; |
| 4590 | status = do_vfs_lock(request->fl_file, request); |
| 4591 | if (status < 0) |
| 4592 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4593 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4594 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4595 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4596 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4597 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4598 | status = do_vfs_lock(request->fl_file, request); |
| 4599 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4600 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4601 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4602 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4603 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4604 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4605 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4606 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4607 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4608 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4609 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4610 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4611 | out: |
| 4612 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | return status; |
| 4614 | } |
| 4615 | |
| 4616 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4617 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4618 | struct nfs4_exception exception = { |
| 4619 | .state = state, |
| 4620 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | int err; |
| 4622 | |
| 4623 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4624 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4625 | if (err == -NFS4ERR_DENIED) |
| 4626 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4628 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | } while (exception.retry); |
| 4630 | return err; |
| 4631 | } |
| 4632 | |
| 4633 | static int |
| 4634 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4635 | { |
| 4636 | struct nfs_open_context *ctx; |
| 4637 | struct nfs4_state *state; |
| 4638 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4639 | int status; |
| 4640 | |
| 4641 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4642 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | state = ctx->state; |
| 4644 | |
| 4645 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4646 | return -EINVAL; |
| 4647 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4648 | if (IS_GETLK(cmd)) { |
| 4649 | if (state != NULL) |
| 4650 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4651 | return 0; |
| 4652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | |
| 4654 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4655 | return -EINVAL; |
| 4656 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4657 | if (request->fl_type == F_UNLCK) { |
| 4658 | if (state != NULL) |
| 4659 | return nfs4_proc_unlck(state, cmd, request); |
| 4660 | return 0; |
| 4661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4663 | if (state == NULL) |
| 4664 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | do { |
| 4666 | status = nfs4_proc_setlk(state, cmd, request); |
| 4667 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4668 | break; |
| 4669 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4670 | status = -ERESTARTSYS; |
| 4671 | if (signalled()) |
| 4672 | break; |
| 4673 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | return status; |
| 4675 | } |
| 4676 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4677 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4678 | { |
| 4679 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4680 | struct nfs4_exception exception = { }; |
| 4681 | int err; |
| 4682 | |
| 4683 | err = nfs4_set_lock_state(state, fl); |
| 4684 | if (err != 0) |
| 4685 | goto out; |
| 4686 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4687 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4688 | switch (err) { |
| 4689 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4690 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4691 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4692 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4693 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4694 | goto out; |
| 4695 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4696 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4697 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4698 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4699 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4700 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4701 | case -NFS4ERR_BADSESSION: |
| 4702 | case -NFS4ERR_BADSLOT: |
| 4703 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4704 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4705 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4706 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4707 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4708 | case -ERESTARTSYS: |
| 4709 | /* |
| 4710 | * The show must go on: exit, but mark the |
| 4711 | * stateid as needing recovery. |
| 4712 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4713 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4714 | case -NFS4ERR_ADMIN_REVOKED: |
| 4715 | case -NFS4ERR_BAD_STATEID: |
| 4716 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4717 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4718 | err = 0; |
| 4719 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4720 | case -EKEYEXPIRED: |
| 4721 | /* |
| 4722 | * User RPCSEC_GSS context has expired. |
| 4723 | * We cannot recover this stateid now, so |
| 4724 | * skip it and allow recovery thread to |
| 4725 | * proceed. |
| 4726 | */ |
| 4727 | err = 0; |
| 4728 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4729 | case -ENOMEM: |
| 4730 | case -NFS4ERR_DENIED: |
| 4731 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4732 | err = 0; |
| 4733 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4734 | case -NFS4ERR_DELAY: |
| 4735 | break; |
| 4736 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4737 | err = nfs4_handle_exception(server, err, &exception); |
| 4738 | } while (exception.retry); |
| 4739 | out: |
| 4740 | return err; |
| 4741 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4742 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4743 | static void nfs4_release_lockowner_release(void *calldata) |
| 4744 | { |
| 4745 | kfree(calldata); |
| 4746 | } |
| 4747 | |
| 4748 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4749 | .rpc_release = nfs4_release_lockowner_release, |
| 4750 | }; |
| 4751 | |
| 4752 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4753 | { |
| 4754 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4755 | struct nfs_release_lockowner_args *args; |
| 4756 | struct rpc_message msg = { |
| 4757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4758 | }; |
| 4759 | |
| 4760 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4761 | return; |
| 4762 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4763 | if (!args) |
| 4764 | return; |
| 4765 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4766 | args->lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4767 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4768 | msg.rpc_argp = args; |
| 4769 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4770 | } |
| 4771 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4772 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4773 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4774 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4775 | const void *buf, size_t buflen, |
| 4776 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4777 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4778 | if (strcmp(key, "") != 0) |
| 4779 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4780 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4781 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4784 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4785 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4786 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4787 | if (strcmp(key, "") != 0) |
| 4788 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4789 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4790 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4791 | } |
| 4792 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4793 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4794 | size_t list_len, const char *name, |
| 4795 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4796 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4797 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4798 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4799 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4800 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4801 | |
| 4802 | if (list && len <= list_len) |
| 4803 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4804 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4805 | } |
| 4806 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4807 | /* |
| 4808 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4809 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4810 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4811 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4812 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4813 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4814 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4815 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4816 | return; |
| 4817 | |
| 4818 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 4819 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4820 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4821 | fattr->nlink = 2; |
| 4822 | } |
| 4823 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4824 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4825 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4826 | { |
| 4827 | struct nfs_server *server = NFS_SERVER(dir); |
| 4828 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4829 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4830 | }; |
| 4831 | struct nfs4_fs_locations_arg args = { |
| 4832 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4833 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4834 | .page = page, |
| 4835 | .bitmask = bitmask, |
| 4836 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4837 | struct nfs4_fs_locations_res res = { |
| 4838 | .fs_locations = fs_locations, |
| 4839 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4840 | struct rpc_message msg = { |
| 4841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4842 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4843 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4844 | }; |
| 4845 | int status; |
| 4846 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4847 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4848 | |
| 4849 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4850 | * is not supported */ |
| 4851 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4852 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4853 | else |
| 4854 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4855 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4856 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4857 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4858 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4859 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4860 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4861 | return status; |
| 4862 | } |
| 4863 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4864 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4865 | { |
| 4866 | int status; |
| 4867 | struct nfs4_secinfo_arg args = { |
| 4868 | .dir_fh = NFS_FH(dir), |
| 4869 | .name = name, |
| 4870 | }; |
| 4871 | struct nfs4_secinfo_res res = { |
| 4872 | .flavors = flavors, |
| 4873 | }; |
| 4874 | struct rpc_message msg = { |
| 4875 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4876 | .rpc_argp = &args, |
| 4877 | .rpc_resp = &res, |
| 4878 | }; |
| 4879 | |
| 4880 | dprintk("NFS call secinfo %s\n", name->name); |
| 4881 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4882 | dprintk("NFS reply secinfo: %d\n", status); |
| 4883 | return status; |
| 4884 | } |
| 4885 | |
| 4886 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4887 | { |
| 4888 | struct nfs4_exception exception = { }; |
| 4889 | int err; |
| 4890 | do { |
| 4891 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4892 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4893 | &exception); |
| 4894 | } while (exception.retry); |
| 4895 | return err; |
| 4896 | } |
| 4897 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4898 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4899 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4900 | * Check the exchange flags returned by the server for invalid flags, having |
| 4901 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4902 | * DS flags set. |
| 4903 | */ |
| 4904 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4905 | { |
| 4906 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4907 | goto out_inval; |
| 4908 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4909 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4910 | goto out_inval; |
| 4911 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4912 | goto out_inval; |
| 4913 | return NFS_OK; |
| 4914 | out_inval: |
| 4915 | return -NFS4ERR_INVAL; |
| 4916 | } |
| 4917 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4918 | static bool |
| 4919 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4920 | { |
| 4921 | if (a->server_scope_sz == b->server_scope_sz && |
| 4922 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4923 | return true; |
| 4924 | |
| 4925 | return false; |
| 4926 | } |
| 4927 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4928 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4929 | * nfs4_proc_exchange_id() |
| 4930 | * |
| 4931 | * Since the clientid has expired, all compounds using sessions |
| 4932 | * associated with the stale clientid will be returning |
| 4933 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4934 | * be in some phase of session reset. |
| 4935 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4936 | 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] | 4937 | { |
| 4938 | nfs4_verifier verifier; |
| 4939 | struct nfs41_exchange_id_args args = { |
| 4940 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4941 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4942 | }; |
| 4943 | struct nfs41_exchange_id_res res = { |
| 4944 | .client = clp, |
| 4945 | }; |
| 4946 | int status; |
| 4947 | struct rpc_message msg = { |
| 4948 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4949 | .rpc_argp = &args, |
| 4950 | .rpc_resp = &res, |
| 4951 | .rpc_cred = cred, |
| 4952 | }; |
| 4953 | __be32 *p; |
| 4954 | |
| 4955 | dprintk("--> %s\n", __func__); |
| 4956 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4957 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4958 | p = (u32 *)verifier.data; |
| 4959 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4960 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4961 | args.verifier = &verifier; |
| 4962 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4963 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4964 | "%s/%s.%s/%u", |
| 4965 | clp->cl_ipaddr, |
| 4966 | init_utsname()->nodename, |
| 4967 | init_utsname()->domainname, |
| 4968 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4969 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4970 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 4971 | if (unlikely(!res.server_scope)) { |
| 4972 | status = -ENOMEM; |
| 4973 | goto out; |
| 4974 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4975 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 4976 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_KERNEL); |
| 4977 | if (unlikely(!res.impl_id)) { |
| 4978 | status = -ENOMEM; |
| 4979 | goto out_server_scope; |
| 4980 | } |
| 4981 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4982 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4983 | if (!status) |
| 4984 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4985 | |
| 4986 | if (!status) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 4987 | /* use the most recent implementation id */ |
| 4988 | kfree(clp->impl_id); |
| 4989 | clp->impl_id = res.impl_id; |
| 4990 | } else |
| 4991 | kfree(res.impl_id); |
| 4992 | |
| 4993 | if (!status) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4994 | if (clp->server_scope && |
| 4995 | !nfs41_same_server_scope(clp->server_scope, |
| 4996 | res.server_scope)) { |
| 4997 | dprintk("%s: server_scope mismatch detected\n", |
| 4998 | __func__); |
| 4999 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 5000 | kfree(clp->server_scope); |
| 5001 | clp->server_scope = NULL; |
| 5002 | } |
| 5003 | |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5004 | if (!clp->server_scope) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5005 | clp->server_scope = res.server_scope; |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5006 | goto out; |
| 5007 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5008 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5009 | |
| 5010 | out_server_scope: |
Weston Andros Adamson | 9edbd95 | 2012-02-17 15:20:25 -0500 | [diff] [blame] | 5011 | kfree(res.server_scope); |
| 5012 | out: |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5013 | if (clp->impl_id) |
| 5014 | dprintk("%s: Server Implementation ID: " |
| 5015 | "domain: %s, name: %s, date: %llu,%u\n", |
| 5016 | __func__, clp->impl_id->domain, clp->impl_id->name, |
| 5017 | clp->impl_id->date.seconds, |
| 5018 | clp->impl_id->date.nseconds); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5019 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5020 | return status; |
| 5021 | } |
| 5022 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5023 | struct nfs4_get_lease_time_data { |
| 5024 | struct nfs4_get_lease_time_args *args; |
| 5025 | struct nfs4_get_lease_time_res *res; |
| 5026 | struct nfs_client *clp; |
| 5027 | }; |
| 5028 | |
| 5029 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5030 | void *calldata) |
| 5031 | { |
| 5032 | int ret; |
| 5033 | struct nfs4_get_lease_time_data *data = |
| 5034 | (struct nfs4_get_lease_time_data *)calldata; |
| 5035 | |
| 5036 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5037 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5038 | /* just setup sequence, do not trigger session recovery |
| 5039 | since we're invoked within one */ |
| 5040 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5041 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5042 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5043 | |
| 5044 | BUG_ON(ret == -EAGAIN); |
| 5045 | rpc_call_start(task); |
| 5046 | dprintk("<-- %s\n", __func__); |
| 5047 | } |
| 5048 | |
| 5049 | /* |
| 5050 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5051 | * from sequence operation or clientid errors. |
| 5052 | */ |
| 5053 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5054 | { |
| 5055 | struct nfs4_get_lease_time_data *data = |
| 5056 | (struct nfs4_get_lease_time_data *)calldata; |
| 5057 | |
| 5058 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5059 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5060 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5061 | switch (task->tk_status) { |
| 5062 | case -NFS4ERR_DELAY: |
| 5063 | case -NFS4ERR_GRACE: |
| 5064 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5065 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5066 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5067 | /* fall through */ |
| 5068 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5069 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5070 | return; |
| 5071 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5072 | dprintk("<-- %s\n", __func__); |
| 5073 | } |
| 5074 | |
| 5075 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 5076 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5077 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5078 | }; |
| 5079 | |
| 5080 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5081 | { |
| 5082 | struct rpc_task *task; |
| 5083 | struct nfs4_get_lease_time_args args; |
| 5084 | struct nfs4_get_lease_time_res res = { |
| 5085 | .lr_fsinfo = fsinfo, |
| 5086 | }; |
| 5087 | struct nfs4_get_lease_time_data data = { |
| 5088 | .args = &args, |
| 5089 | .res = &res, |
| 5090 | .clp = clp, |
| 5091 | }; |
| 5092 | struct rpc_message msg = { |
| 5093 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5094 | .rpc_argp = &args, |
| 5095 | .rpc_resp = &res, |
| 5096 | }; |
| 5097 | struct rpc_task_setup task_setup = { |
| 5098 | .rpc_client = clp->cl_rpcclient, |
| 5099 | .rpc_message = &msg, |
| 5100 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5101 | .callback_data = &data, |
| 5102 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5103 | }; |
| 5104 | int status; |
| 5105 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5106 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5107 | dprintk("--> %s\n", __func__); |
| 5108 | task = rpc_run_task(&task_setup); |
| 5109 | |
| 5110 | if (IS_ERR(task)) |
| 5111 | status = PTR_ERR(task); |
| 5112 | else { |
| 5113 | status = task->tk_status; |
| 5114 | rpc_put_task(task); |
| 5115 | } |
| 5116 | dprintk("<-- %s return %d\n", __func__, status); |
| 5117 | |
| 5118 | return status; |
| 5119 | } |
| 5120 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5121 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5122 | { |
| 5123 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5124 | } |
| 5125 | |
| 5126 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5127 | struct nfs4_slot *new, |
| 5128 | u32 max_slots, |
| 5129 | u32 ivalue) |
| 5130 | { |
| 5131 | struct nfs4_slot *old = NULL; |
| 5132 | u32 i; |
| 5133 | |
| 5134 | spin_lock(&tbl->slot_tbl_lock); |
| 5135 | if (new) { |
| 5136 | old = tbl->slots; |
| 5137 | tbl->slots = new; |
| 5138 | tbl->max_slots = max_slots; |
| 5139 | } |
| 5140 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5141 | for (i = 0; i < tbl->max_slots; i++) |
| 5142 | tbl->slots[i].seq_nr = ivalue; |
| 5143 | spin_unlock(&tbl->slot_tbl_lock); |
| 5144 | kfree(old); |
| 5145 | } |
| 5146 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5147 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5148 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5149 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5150 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5151 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5152 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5153 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5154 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5155 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5156 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5157 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5158 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5159 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5160 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5161 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5162 | if (!new) |
| 5163 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5164 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5165 | ret = 0; |
| 5166 | |
| 5167 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5168 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5169 | tbl, tbl->slots, tbl->max_slots); |
| 5170 | out: |
| 5171 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5172 | return ret; |
| 5173 | } |
| 5174 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5175 | /* Destroy the slot table */ |
| 5176 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5177 | { |
| 5178 | if (session->fc_slot_table.slots != NULL) { |
| 5179 | kfree(session->fc_slot_table.slots); |
| 5180 | session->fc_slot_table.slots = NULL; |
| 5181 | } |
| 5182 | if (session->bc_slot_table.slots != NULL) { |
| 5183 | kfree(session->bc_slot_table.slots); |
| 5184 | session->bc_slot_table.slots = NULL; |
| 5185 | } |
| 5186 | return; |
| 5187 | } |
| 5188 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5189 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5190 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5191 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5192 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5193 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5194 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5195 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5196 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5197 | dprintk("--> %s\n", __func__); |
| 5198 | /* Fore channel */ |
| 5199 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5200 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5201 | if (status) /* -ENOMEM */ |
| 5202 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5203 | /* Back channel */ |
| 5204 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5205 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5206 | if (status && tbl->slots == NULL) |
| 5207 | /* Fore and back channel share a connection so get |
| 5208 | * both slot tables or neither */ |
| 5209 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5210 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5214 | { |
| 5215 | struct nfs4_session *session; |
| 5216 | struct nfs4_slot_table *tbl; |
| 5217 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5218 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5219 | if (!session) |
| 5220 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5221 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5222 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5223 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5224 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5225 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5226 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5227 | |
| 5228 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5229 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5230 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5231 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5232 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5233 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5234 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5235 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5236 | session->clp = clp; |
| 5237 | return session; |
| 5238 | } |
| 5239 | |
| 5240 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5241 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5242 | struct rpc_xprt *xprt; |
| 5243 | |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5244 | nfs4_proc_destroy_session(session); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5245 | |
| 5246 | rcu_read_lock(); |
| 5247 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5248 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5249 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5250 | __func__, xprt); |
| 5251 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5252 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5253 | kfree(session); |
| 5254 | } |
| 5255 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5256 | /* |
| 5257 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5258 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5259 | * use them. |
| 5260 | * |
| 5261 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5262 | * always set csa_cachethis to FALSE because the current implementation |
| 5263 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5264 | */ |
| 5265 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5266 | { |
| 5267 | struct nfs4_session *session = args->client->cl_session; |
| 5268 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5269 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5270 | |
| 5271 | if (mxrqst_sz == 0) |
| 5272 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5273 | if (mxresp_sz == 0) |
| 5274 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5275 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5276 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5277 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5278 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5279 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5280 | |
| 5281 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5282 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5283 | __func__, |
| 5284 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5285 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5286 | |
| 5287 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5288 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5289 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5290 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5291 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5292 | args->bc_attrs.max_reqs = 1; |
| 5293 | |
| 5294 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5295 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5296 | __func__, |
| 5297 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5298 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5299 | args->bc_attrs.max_reqs); |
| 5300 | } |
| 5301 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5302 | 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] | 5303 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5304 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5305 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5306 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5307 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5308 | return -EINVAL; |
| 5309 | /* |
| 5310 | * Our requested max_ops is the minimum we need; we're not |
| 5311 | * prepared to break up compounds into smaller pieces than that. |
| 5312 | * So, no point even trying to continue if the server won't |
| 5313 | * cooperate: |
| 5314 | */ |
| 5315 | if (rcvd->max_ops < sent->max_ops) |
| 5316 | return -EINVAL; |
| 5317 | if (rcvd->max_reqs == 0) |
| 5318 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5319 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5320 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5321 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5322 | } |
| 5323 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5324 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5325 | { |
| 5326 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5327 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5328 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5329 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5330 | return -EINVAL; |
| 5331 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5332 | return -EINVAL; |
| 5333 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5334 | return -EINVAL; |
| 5335 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5336 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5337 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5338 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5339 | return -EINVAL; |
| 5340 | return 0; |
| 5341 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5342 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5343 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5344 | struct nfs4_session *session) |
| 5345 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5346 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5347 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5348 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5349 | if (ret) |
| 5350 | return ret; |
| 5351 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5352 | } |
| 5353 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5354 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5355 | { |
| 5356 | struct nfs4_session *session = clp->cl_session; |
| 5357 | struct nfs41_create_session_args args = { |
| 5358 | .client = clp, |
| 5359 | .cb_program = NFS4_CALLBACK, |
| 5360 | }; |
| 5361 | struct nfs41_create_session_res res = { |
| 5362 | .client = clp, |
| 5363 | }; |
| 5364 | struct rpc_message msg = { |
| 5365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5366 | .rpc_argp = &args, |
| 5367 | .rpc_resp = &res, |
| 5368 | }; |
| 5369 | int status; |
| 5370 | |
| 5371 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5372 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5373 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5374 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5375 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5376 | if (!status) |
| 5377 | /* Verify the session's negotiated channel_attrs values */ |
| 5378 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5379 | if (!status) { |
| 5380 | /* Increment the clientid slot sequence id */ |
| 5381 | clp->cl_seqid++; |
| 5382 | } |
| 5383 | |
| 5384 | return status; |
| 5385 | } |
| 5386 | |
| 5387 | /* |
| 5388 | * Issues a CREATE_SESSION operation to the server. |
| 5389 | * It is the responsibility of the caller to verify the session is |
| 5390 | * expired before calling this routine. |
| 5391 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5392 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5393 | { |
| 5394 | int status; |
| 5395 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5396 | struct nfs4_session *session = clp->cl_session; |
| 5397 | |
| 5398 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5399 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5400 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5401 | if (status) |
| 5402 | goto out; |
| 5403 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5404 | /* Init or reset the session slot tables */ |
| 5405 | status = nfs4_setup_session_slot_tables(session); |
| 5406 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5407 | if (status) |
| 5408 | goto out; |
| 5409 | |
| 5410 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5411 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5412 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5413 | out: |
| 5414 | dprintk("<-- %s\n", __func__); |
| 5415 | return status; |
| 5416 | } |
| 5417 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5418 | /* |
| 5419 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5420 | * The caller must serialize access to this routine. |
| 5421 | */ |
| 5422 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5423 | { |
| 5424 | int status = 0; |
| 5425 | struct rpc_message msg; |
| 5426 | |
| 5427 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5428 | |
| 5429 | /* session is still being setup */ |
| 5430 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5431 | return status; |
| 5432 | |
| 5433 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5434 | msg.rpc_argp = session; |
| 5435 | msg.rpc_resp = NULL; |
| 5436 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5437 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5438 | |
| 5439 | if (status) |
| 5440 | printk(KERN_WARNING |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 5441 | "NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5442 | "Session has been destroyed regardless...\n", status); |
| 5443 | |
| 5444 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5445 | return status; |
| 5446 | } |
| 5447 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5448 | int nfs4_init_session(struct nfs_server *server) |
| 5449 | { |
| 5450 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5451 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5452 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5453 | int ret; |
| 5454 | |
| 5455 | if (!nfs4_has_session(clp)) |
| 5456 | return 0; |
| 5457 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5458 | session = clp->cl_session; |
| 5459 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5460 | return 0; |
| 5461 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5462 | rsize = server->rsize; |
| 5463 | if (rsize == 0) |
| 5464 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5465 | wsize = server->wsize; |
| 5466 | if (wsize == 0) |
| 5467 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5468 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5469 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5470 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5471 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5472 | ret = nfs4_recover_expired_lease(server); |
| 5473 | if (!ret) |
| 5474 | ret = nfs4_check_client_ready(clp); |
| 5475 | return ret; |
| 5476 | } |
| 5477 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5478 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5479 | { |
| 5480 | struct nfs4_session *session = clp->cl_session; |
| 5481 | int ret; |
| 5482 | |
| 5483 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5484 | return 0; |
| 5485 | |
| 5486 | ret = nfs4_client_recover_expired_lease(clp); |
| 5487 | if (!ret) |
| 5488 | /* Test for the DS role */ |
| 5489 | if (!is_ds_client(clp)) |
| 5490 | ret = -ENODEV; |
| 5491 | if (!ret) |
| 5492 | ret = nfs4_check_client_ready(clp); |
| 5493 | return ret; |
| 5494 | |
| 5495 | } |
| 5496 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5497 | |
| 5498 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5499 | /* |
| 5500 | * Renew the cl_session lease. |
| 5501 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5502 | struct nfs4_sequence_data { |
| 5503 | struct nfs_client *clp; |
| 5504 | struct nfs4_sequence_args args; |
| 5505 | struct nfs4_sequence_res res; |
| 5506 | }; |
| 5507 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5508 | static void nfs41_sequence_release(void *data) |
| 5509 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5510 | struct nfs4_sequence_data *calldata = data; |
| 5511 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5512 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5513 | if (atomic_read(&clp->cl_count) > 1) |
| 5514 | nfs4_schedule_state_renewal(clp); |
| 5515 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5516 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5517 | } |
| 5518 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5519 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5520 | { |
| 5521 | switch(task->tk_status) { |
| 5522 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5523 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5524 | return -EAGAIN; |
| 5525 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5526 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5527 | } |
| 5528 | return 0; |
| 5529 | } |
| 5530 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5531 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5532 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5533 | struct nfs4_sequence_data *calldata = data; |
| 5534 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5535 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5536 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5537 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5538 | |
| 5539 | if (task->tk_status < 0) { |
| 5540 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5541 | if (atomic_read(&clp->cl_count) == 1) |
| 5542 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5543 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5544 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5545 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5546 | return; |
| 5547 | } |
| 5548 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5549 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5550 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5551 | dprintk("<-- %s\n", __func__); |
| 5552 | } |
| 5553 | |
| 5554 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5555 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5556 | struct nfs4_sequence_data *calldata = data; |
| 5557 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5558 | struct nfs4_sequence_args *args; |
| 5559 | struct nfs4_sequence_res *res; |
| 5560 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5561 | args = task->tk_msg.rpc_argp; |
| 5562 | res = task->tk_msg.rpc_resp; |
| 5563 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5564 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5565 | return; |
| 5566 | rpc_call_start(task); |
| 5567 | } |
| 5568 | |
| 5569 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5570 | .rpc_call_done = nfs41_sequence_call_done, |
| 5571 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5572 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5573 | }; |
| 5574 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5575 | 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] | 5576 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5577 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5578 | struct rpc_message msg = { |
| 5579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5580 | .rpc_cred = cred, |
| 5581 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5582 | struct rpc_task_setup task_setup_data = { |
| 5583 | .rpc_client = clp->cl_rpcclient, |
| 5584 | .rpc_message = &msg, |
| 5585 | .callback_ops = &nfs41_sequence_ops, |
| 5586 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5587 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5588 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5589 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5590 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5591 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5592 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5593 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5594 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5595 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5596 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5597 | msg.rpc_argp = &calldata->args; |
| 5598 | msg.rpc_resp = &calldata->res; |
| 5599 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5600 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5601 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5602 | return rpc_run_task(&task_setup_data); |
| 5603 | } |
| 5604 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5605 | 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] | 5606 | { |
| 5607 | struct rpc_task *task; |
| 5608 | int ret = 0; |
| 5609 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5610 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5611 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5612 | task = _nfs41_proc_sequence(clp, cred); |
| 5613 | if (IS_ERR(task)) |
| 5614 | ret = PTR_ERR(task); |
| 5615 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5616 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5617 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5618 | return ret; |
| 5619 | } |
| 5620 | |
| 5621 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5622 | { |
| 5623 | struct rpc_task *task; |
| 5624 | int ret; |
| 5625 | |
| 5626 | task = _nfs41_proc_sequence(clp, cred); |
| 5627 | if (IS_ERR(task)) { |
| 5628 | ret = PTR_ERR(task); |
| 5629 | goto out; |
| 5630 | } |
| 5631 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5632 | if (!ret) { |
| 5633 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5634 | |
| 5635 | if (task->tk_status == 0) |
| 5636 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5637 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5638 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5639 | rpc_put_task(task); |
| 5640 | out: |
| 5641 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5642 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5643 | } |
| 5644 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5645 | struct nfs4_reclaim_complete_data { |
| 5646 | struct nfs_client *clp; |
| 5647 | struct nfs41_reclaim_complete_args arg; |
| 5648 | struct nfs41_reclaim_complete_res res; |
| 5649 | }; |
| 5650 | |
| 5651 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5652 | { |
| 5653 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5654 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5655 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5656 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5657 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5658 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5659 | return; |
| 5660 | |
| 5661 | rpc_call_start(task); |
| 5662 | } |
| 5663 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5664 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5665 | { |
| 5666 | switch(task->tk_status) { |
| 5667 | case 0: |
| 5668 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5669 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5670 | break; |
| 5671 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5672 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5673 | /* fall through */ |
| 5674 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5675 | return -EAGAIN; |
| 5676 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5677 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5678 | } |
| 5679 | return 0; |
| 5680 | } |
| 5681 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5682 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5683 | { |
| 5684 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5685 | struct nfs_client *clp = calldata->clp; |
| 5686 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5687 | |
| 5688 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5689 | if (!nfs41_sequence_done(task, res)) |
| 5690 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5691 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5692 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5693 | rpc_restart_call_prepare(task); |
| 5694 | return; |
| 5695 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5696 | dprintk("<-- %s\n", __func__); |
| 5697 | } |
| 5698 | |
| 5699 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5700 | { |
| 5701 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5702 | |
| 5703 | kfree(calldata); |
| 5704 | } |
| 5705 | |
| 5706 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5707 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5708 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5709 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5710 | }; |
| 5711 | |
| 5712 | /* |
| 5713 | * Issue a global reclaim complete. |
| 5714 | */ |
| 5715 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5716 | { |
| 5717 | struct nfs4_reclaim_complete_data *calldata; |
| 5718 | struct rpc_task *task; |
| 5719 | struct rpc_message msg = { |
| 5720 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5721 | }; |
| 5722 | struct rpc_task_setup task_setup_data = { |
| 5723 | .rpc_client = clp->cl_rpcclient, |
| 5724 | .rpc_message = &msg, |
| 5725 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5726 | .flags = RPC_TASK_ASYNC, |
| 5727 | }; |
| 5728 | int status = -ENOMEM; |
| 5729 | |
| 5730 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5731 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5732 | if (calldata == NULL) |
| 5733 | goto out; |
| 5734 | calldata->clp = clp; |
| 5735 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5736 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5737 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5738 | msg.rpc_argp = &calldata->arg; |
| 5739 | msg.rpc_resp = &calldata->res; |
| 5740 | task_setup_data.callback_data = calldata; |
| 5741 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5742 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5743 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5744 | goto out; |
| 5745 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5746 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5747 | if (status == 0) |
| 5748 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5749 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5750 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5751 | out: |
| 5752 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5753 | return status; |
| 5754 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5755 | |
| 5756 | static void |
| 5757 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5758 | { |
| 5759 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5760 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5761 | |
| 5762 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5763 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5764 | * right now covering the LAYOUTGET we are about to send. |
| 5765 | * However, that is not so catastrophic, and there seems |
| 5766 | * to be no way to prevent it completely. |
| 5767 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5768 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5769 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5770 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5771 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5772 | NFS_I(lgp->args.inode)->layout, |
| 5773 | lgp->args.ctx->state)) { |
| 5774 | rpc_exit(task, NFS4_OK); |
| 5775 | return; |
| 5776 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5777 | rpc_call_start(task); |
| 5778 | } |
| 5779 | |
| 5780 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5781 | { |
| 5782 | struct nfs4_layoutget *lgp = calldata; |
| 5783 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5784 | |
| 5785 | dprintk("--> %s\n", __func__); |
| 5786 | |
| 5787 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5788 | return; |
| 5789 | |
| 5790 | switch (task->tk_status) { |
| 5791 | case 0: |
| 5792 | break; |
| 5793 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5794 | case -NFS4ERR_RECALLCONFLICT: |
| 5795 | task->tk_status = -NFS4ERR_DELAY; |
| 5796 | /* Fall through */ |
| 5797 | default: |
| 5798 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5799 | rpc_restart_call_prepare(task); |
| 5800 | return; |
| 5801 | } |
| 5802 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5803 | dprintk("<-- %s\n", __func__); |
| 5804 | } |
| 5805 | |
| 5806 | static void nfs4_layoutget_release(void *calldata) |
| 5807 | { |
| 5808 | struct nfs4_layoutget *lgp = calldata; |
| 5809 | |
| 5810 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5811 | put_nfs_open_context(lgp->args.ctx); |
| 5812 | kfree(calldata); |
| 5813 | dprintk("<-- %s\n", __func__); |
| 5814 | } |
| 5815 | |
| 5816 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5817 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5818 | .rpc_call_done = nfs4_layoutget_done, |
| 5819 | .rpc_release = nfs4_layoutget_release, |
| 5820 | }; |
| 5821 | |
| 5822 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5823 | { |
| 5824 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5825 | struct rpc_task *task; |
| 5826 | struct rpc_message msg = { |
| 5827 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5828 | .rpc_argp = &lgp->args, |
| 5829 | .rpc_resp = &lgp->res, |
| 5830 | }; |
| 5831 | struct rpc_task_setup task_setup_data = { |
| 5832 | .rpc_client = server->client, |
| 5833 | .rpc_message = &msg, |
| 5834 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5835 | .callback_data = lgp, |
| 5836 | .flags = RPC_TASK_ASYNC, |
| 5837 | }; |
| 5838 | int status = 0; |
| 5839 | |
| 5840 | dprintk("--> %s\n", __func__); |
| 5841 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5842 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5843 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5844 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5845 | task = rpc_run_task(&task_setup_data); |
| 5846 | if (IS_ERR(task)) |
| 5847 | return PTR_ERR(task); |
| 5848 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5849 | if (status == 0) |
| 5850 | status = task->tk_status; |
| 5851 | if (status == 0) |
| 5852 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5853 | rpc_put_task(task); |
| 5854 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5855 | return status; |
| 5856 | } |
| 5857 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5858 | static void |
| 5859 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5860 | { |
| 5861 | struct nfs4_layoutreturn *lrp = calldata; |
| 5862 | |
| 5863 | dprintk("--> %s\n", __func__); |
| 5864 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5865 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5866 | return; |
| 5867 | rpc_call_start(task); |
| 5868 | } |
| 5869 | |
| 5870 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5871 | { |
| 5872 | struct nfs4_layoutreturn *lrp = calldata; |
| 5873 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5874 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5875 | |
| 5876 | dprintk("--> %s\n", __func__); |
| 5877 | |
| 5878 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5879 | return; |
| 5880 | |
| 5881 | server = NFS_SERVER(lrp->args.inode); |
| 5882 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5883 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5884 | return; |
| 5885 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5886 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5887 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5888 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5889 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5890 | } else |
| 5891 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5892 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5893 | lo->plh_block_lgets--; |
| 5894 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5895 | dprintk("<-- %s\n", __func__); |
| 5896 | } |
| 5897 | |
| 5898 | static void nfs4_layoutreturn_release(void *calldata) |
| 5899 | { |
| 5900 | struct nfs4_layoutreturn *lrp = calldata; |
| 5901 | |
| 5902 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5903 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5904 | kfree(calldata); |
| 5905 | dprintk("<-- %s\n", __func__); |
| 5906 | } |
| 5907 | |
| 5908 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5909 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5910 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5911 | .rpc_release = nfs4_layoutreturn_release, |
| 5912 | }; |
| 5913 | |
| 5914 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5915 | { |
| 5916 | struct rpc_task *task; |
| 5917 | struct rpc_message msg = { |
| 5918 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5919 | .rpc_argp = &lrp->args, |
| 5920 | .rpc_resp = &lrp->res, |
| 5921 | }; |
| 5922 | struct rpc_task_setup task_setup_data = { |
| 5923 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5924 | .rpc_message = &msg, |
| 5925 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5926 | .callback_data = lrp, |
| 5927 | }; |
| 5928 | int status; |
| 5929 | |
| 5930 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5931 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5932 | task = rpc_run_task(&task_setup_data); |
| 5933 | if (IS_ERR(task)) |
| 5934 | return PTR_ERR(task); |
| 5935 | status = task->tk_status; |
| 5936 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5937 | rpc_put_task(task); |
| 5938 | return status; |
| 5939 | } |
| 5940 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 5941 | /* |
| 5942 | * Retrieve the list of Data Server devices from the MDS. |
| 5943 | */ |
| 5944 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 5945 | const struct nfs_fh *fh, |
| 5946 | struct pnfs_devicelist *devlist) |
| 5947 | { |
| 5948 | struct nfs4_getdevicelist_args args = { |
| 5949 | .fh = fh, |
| 5950 | .layoutclass = server->pnfs_curr_ld->id, |
| 5951 | }; |
| 5952 | struct nfs4_getdevicelist_res res = { |
| 5953 | .devlist = devlist, |
| 5954 | }; |
| 5955 | struct rpc_message msg = { |
| 5956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 5957 | .rpc_argp = &args, |
| 5958 | .rpc_resp = &res, |
| 5959 | }; |
| 5960 | int status; |
| 5961 | |
| 5962 | dprintk("--> %s\n", __func__); |
| 5963 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5964 | &res.seq_res, 0); |
| 5965 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5966 | return status; |
| 5967 | } |
| 5968 | |
| 5969 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 5970 | const struct nfs_fh *fh, |
| 5971 | struct pnfs_devicelist *devlist) |
| 5972 | { |
| 5973 | struct nfs4_exception exception = { }; |
| 5974 | int err; |
| 5975 | |
| 5976 | do { |
| 5977 | err = nfs4_handle_exception(server, |
| 5978 | _nfs4_getdevicelist(server, fh, devlist), |
| 5979 | &exception); |
| 5980 | } while (exception.retry); |
| 5981 | |
| 5982 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 5983 | err, devlist->num_devs); |
| 5984 | |
| 5985 | return err; |
| 5986 | } |
| 5987 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 5988 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5989 | static int |
| 5990 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5991 | { |
| 5992 | struct nfs4_getdeviceinfo_args args = { |
| 5993 | .pdev = pdev, |
| 5994 | }; |
| 5995 | struct nfs4_getdeviceinfo_res res = { |
| 5996 | .pdev = pdev, |
| 5997 | }; |
| 5998 | struct rpc_message msg = { |
| 5999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6000 | .rpc_argp = &args, |
| 6001 | .rpc_resp = &res, |
| 6002 | }; |
| 6003 | int status; |
| 6004 | |
| 6005 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6006 | 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] | 6007 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6008 | |
| 6009 | return status; |
| 6010 | } |
| 6011 | |
| 6012 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6013 | { |
| 6014 | struct nfs4_exception exception = { }; |
| 6015 | int err; |
| 6016 | |
| 6017 | do { |
| 6018 | err = nfs4_handle_exception(server, |
| 6019 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6020 | &exception); |
| 6021 | } while (exception.retry); |
| 6022 | return err; |
| 6023 | } |
| 6024 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6025 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6026 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6027 | { |
| 6028 | struct nfs4_layoutcommit_data *data = calldata; |
| 6029 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6030 | |
| 6031 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6032 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6033 | return; |
| 6034 | rpc_call_start(task); |
| 6035 | } |
| 6036 | |
| 6037 | static void |
| 6038 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6039 | { |
| 6040 | struct nfs4_layoutcommit_data *data = calldata; |
| 6041 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6042 | |
| 6043 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6044 | return; |
| 6045 | |
| 6046 | switch (task->tk_status) { /* Just ignore these failures */ |
| 6047 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6048 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6049 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 6050 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 6051 | task->tk_status = 0; |
| 6052 | } |
| 6053 | |
| 6054 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6055 | rpc_restart_call_prepare(task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6056 | return; |
| 6057 | } |
| 6058 | |
| 6059 | if (task->tk_status == 0) |
| 6060 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6061 | data->res.fattr); |
| 6062 | } |
| 6063 | |
| 6064 | static void nfs4_layoutcommit_release(void *calldata) |
| 6065 | { |
| 6066 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6067 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6068 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6069 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6070 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6071 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6072 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6073 | list_del_init(&lseg->pls_lc_list); |
| 6074 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6075 | &lseg->pls_flags)) |
| 6076 | put_lseg(lseg); |
| 6077 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6078 | |
| 6079 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6080 | smp_mb__after_clear_bit(); |
| 6081 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6082 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6083 | put_rpccred(data->cred); |
| 6084 | kfree(data); |
| 6085 | } |
| 6086 | |
| 6087 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6088 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6089 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6090 | .rpc_release = nfs4_layoutcommit_release, |
| 6091 | }; |
| 6092 | |
| 6093 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6094 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6095 | { |
| 6096 | struct rpc_message msg = { |
| 6097 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6098 | .rpc_argp = &data->args, |
| 6099 | .rpc_resp = &data->res, |
| 6100 | .rpc_cred = data->cred, |
| 6101 | }; |
| 6102 | struct rpc_task_setup task_setup_data = { |
| 6103 | .task = &data->task, |
| 6104 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6105 | .rpc_message = &msg, |
| 6106 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6107 | .callback_data = data, |
| 6108 | .flags = RPC_TASK_ASYNC, |
| 6109 | }; |
| 6110 | struct rpc_task *task; |
| 6111 | int status = 0; |
| 6112 | |
| 6113 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6114 | "lbw: %llu inode %lu\n", |
| 6115 | data->task.tk_pid, sync, |
| 6116 | data->args.lastbytewritten, |
| 6117 | data->args.inode->i_ino); |
| 6118 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6119 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6120 | task = rpc_run_task(&task_setup_data); |
| 6121 | if (IS_ERR(task)) |
| 6122 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6123 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6124 | goto out; |
| 6125 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6126 | if (status != 0) |
| 6127 | goto out; |
| 6128 | status = task->tk_status; |
| 6129 | out: |
| 6130 | dprintk("%s: status %d\n", __func__, status); |
| 6131 | rpc_put_task(task); |
| 6132 | return status; |
| 6133 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6134 | |
| 6135 | static int |
| 6136 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6137 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6138 | { |
| 6139 | struct nfs41_secinfo_no_name_args args = { |
| 6140 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6141 | }; |
| 6142 | struct nfs4_secinfo_res res = { |
| 6143 | .flavors = flavors, |
| 6144 | }; |
| 6145 | struct rpc_message msg = { |
| 6146 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6147 | .rpc_argp = &args, |
| 6148 | .rpc_resp = &res, |
| 6149 | }; |
| 6150 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6151 | } |
| 6152 | |
| 6153 | static int |
| 6154 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6155 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6156 | { |
| 6157 | struct nfs4_exception exception = { }; |
| 6158 | int err; |
| 6159 | do { |
| 6160 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6161 | switch (err) { |
| 6162 | case 0: |
| 6163 | case -NFS4ERR_WRONGSEC: |
| 6164 | case -NFS4ERR_NOTSUPP: |
| 6165 | break; |
| 6166 | default: |
| 6167 | err = nfs4_handle_exception(server, err, &exception); |
| 6168 | } |
| 6169 | } while (exception.retry); |
| 6170 | return err; |
| 6171 | } |
| 6172 | |
| 6173 | static int |
| 6174 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6175 | struct nfs_fsinfo *info) |
| 6176 | { |
| 6177 | int err; |
| 6178 | struct page *page; |
| 6179 | rpc_authflavor_t flavor; |
| 6180 | struct nfs4_secinfo_flavors *flavors; |
| 6181 | |
| 6182 | page = alloc_page(GFP_KERNEL); |
| 6183 | if (!page) { |
| 6184 | err = -ENOMEM; |
| 6185 | goto out; |
| 6186 | } |
| 6187 | |
| 6188 | flavors = page_address(page); |
| 6189 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6190 | |
| 6191 | /* |
| 6192 | * Fall back on "guess and check" method if |
| 6193 | * the server doesn't support SECINFO_NO_NAME |
| 6194 | */ |
| 6195 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6196 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6197 | goto out_freepage; |
| 6198 | } |
| 6199 | if (err) |
| 6200 | goto out_freepage; |
| 6201 | |
| 6202 | flavor = nfs_find_best_sec(flavors); |
| 6203 | if (err == 0) |
| 6204 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6205 | |
| 6206 | out_freepage: |
| 6207 | put_page(page); |
| 6208 | if (err == -EACCES) |
| 6209 | return -EPERM; |
| 6210 | out: |
| 6211 | return err; |
| 6212 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6213 | |
| 6214 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6215 | { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6216 | int status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6217 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6218 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6219 | }; |
| 6220 | struct nfs41_test_stateid_res res; |
| 6221 | struct rpc_message msg = { |
| 6222 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6223 | .rpc_argp = &args, |
| 6224 | .rpc_resp = &res, |
| 6225 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6226 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6227 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6228 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
| 6229 | |
| 6230 | if (status == NFS_OK) |
| 6231 | return res.status; |
| 6232 | return status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6233 | } |
| 6234 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6235 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6236 | { |
| 6237 | struct nfs4_exception exception = { }; |
| 6238 | int err; |
| 6239 | do { |
| 6240 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6241 | _nfs41_test_stateid(server, stateid), |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6242 | &exception); |
| 6243 | } while (exception.retry); |
| 6244 | return err; |
| 6245 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6246 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6247 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6248 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6249 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6250 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6251 | }; |
| 6252 | struct nfs41_free_stateid_res res; |
| 6253 | struct rpc_message msg = { |
| 6254 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6255 | .rpc_argp = &args, |
| 6256 | .rpc_resp = &res, |
| 6257 | }; |
| 6258 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6259 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6260 | 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] | 6261 | } |
| 6262 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6263 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6264 | { |
| 6265 | struct nfs4_exception exception = { }; |
| 6266 | int err; |
| 6267 | do { |
| 6268 | err = nfs4_handle_exception(server, |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6269 | _nfs4_free_stateid(server, stateid), |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6270 | &exception); |
| 6271 | } while (exception.retry); |
| 6272 | return err; |
| 6273 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6274 | |
| 6275 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6276 | const nfs4_stateid *s2) |
| 6277 | { |
| 6278 | if (memcmp(s1->stateid.other, s2->stateid.other, |
| 6279 | sizeof(s1->stateid.other)) != 0) |
| 6280 | return false; |
| 6281 | |
| 6282 | if (s1->stateid.seqid == s2->stateid.seqid) |
| 6283 | return true; |
| 6284 | if (s1->stateid.seqid == 0 || s2->stateid.seqid == 0) |
| 6285 | return true; |
| 6286 | |
| 6287 | return false; |
| 6288 | } |
| 6289 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6290 | #endif /* CONFIG_NFS_V4_1 */ |
| 6291 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6292 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6293 | const nfs4_stateid *s2) |
| 6294 | { |
| 6295 | return memcmp(s1->data, s2->data, sizeof(s1->data)) == 0; |
| 6296 | } |
| 6297 | |
| 6298 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6299 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6300 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6301 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | .recover_open = nfs4_open_reclaim, |
| 6303 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6304 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6305 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | }; |
| 6307 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6308 | #if defined(CONFIG_NFS_V4_1) |
| 6309 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6310 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6311 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6312 | .recover_open = nfs4_open_reclaim, |
| 6313 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6314 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6315 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6316 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6317 | }; |
| 6318 | #endif /* CONFIG_NFS_V4_1 */ |
| 6319 | |
| 6320 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6321 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6322 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6323 | .recover_open = nfs4_open_expired, |
| 6324 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6325 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6326 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6327 | }; |
| 6328 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6329 | #if defined(CONFIG_NFS_V4_1) |
| 6330 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6331 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6332 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6333 | .recover_open = nfs41_open_expired, |
| 6334 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6335 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6336 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6337 | }; |
| 6338 | #endif /* CONFIG_NFS_V4_1 */ |
| 6339 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6340 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6341 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6342 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6343 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6344 | }; |
| 6345 | |
| 6346 | #if defined(CONFIG_NFS_V4_1) |
| 6347 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6348 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6349 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6350 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6351 | }; |
| 6352 | #endif |
| 6353 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6354 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6355 | .minor_version = 0, |
| 6356 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6357 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6358 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6359 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6360 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6361 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6362 | }; |
| 6363 | |
| 6364 | #if defined(CONFIG_NFS_V4_1) |
| 6365 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6366 | .minor_version = 1, |
| 6367 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6368 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6369 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6370 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6371 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6372 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6373 | }; |
| 6374 | #endif |
| 6375 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6376 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6377 | [0] = &nfs_v4_0_minor_ops, |
| 6378 | #if defined(CONFIG_NFS_V4_1) |
| 6379 | [1] = &nfs_v4_1_minor_ops, |
| 6380 | #endif |
| 6381 | }; |
| 6382 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6383 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6384 | .permission = nfs_permission, |
| 6385 | .getattr = nfs_getattr, |
| 6386 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6387 | .getxattr = generic_getxattr, |
| 6388 | .setxattr = generic_setxattr, |
| 6389 | .listxattr = generic_listxattr, |
| 6390 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6391 | }; |
| 6392 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6393 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6394 | .version = 4, /* protocol version */ |
| 6395 | .dentry_ops = &nfs4_dentry_operations, |
| 6396 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6397 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6398 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | .getroot = nfs4_proc_get_root, |
| 6400 | .getattr = nfs4_proc_getattr, |
| 6401 | .setattr = nfs4_proc_setattr, |
| 6402 | .lookup = nfs4_proc_lookup, |
| 6403 | .access = nfs4_proc_access, |
| 6404 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6405 | .create = nfs4_proc_create, |
| 6406 | .remove = nfs4_proc_remove, |
| 6407 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6408 | .unlink_done = nfs4_proc_unlink_done, |
| 6409 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6410 | .rename_setup = nfs4_proc_rename_setup, |
| 6411 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6412 | .link = nfs4_proc_link, |
| 6413 | .symlink = nfs4_proc_symlink, |
| 6414 | .mkdir = nfs4_proc_mkdir, |
| 6415 | .rmdir = nfs4_proc_remove, |
| 6416 | .readdir = nfs4_proc_readdir, |
| 6417 | .mknod = nfs4_proc_mknod, |
| 6418 | .statfs = nfs4_proc_statfs, |
| 6419 | .fsinfo = nfs4_proc_fsinfo, |
| 6420 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6421 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6422 | .decode_dirent = nfs4_decode_dirent, |
| 6423 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6424 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6425 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6426 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6427 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6428 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6429 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6430 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6431 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6432 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6433 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6434 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6435 | }; |
| 6436 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6437 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6438 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6439 | .list = nfs4_xattr_list_nfs4_acl, |
| 6440 | .get = nfs4_xattr_get_nfs4_acl, |
| 6441 | .set = nfs4_xattr_set_nfs4_acl, |
| 6442 | }; |
| 6443 | |
| 6444 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6445 | &nfs4_xattr_nfs4_acl_handler, |
| 6446 | NULL |
| 6447 | }; |
| 6448 | |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 6449 | module_param(max_session_slots, ushort, 0644); |
| 6450 | MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 " |
| 6451 | "requests the client will negotiate"); |
| 6452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6453 | /* |
| 6454 | * Local variables: |
| 6455 | * c-basic-offset: 8 |
| 6456 | * End: |
| 6457 | */ |