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> |
| 39 | #include <linux/utsname.h> |
| 40 | #include <linux/delay.h> |
| 41 | #include <linux/errno.h> |
| 42 | #include <linux/string.h> |
| 43 | #include <linux/sunrpc/clnt.h> |
| 44 | #include <linux/nfs.h> |
| 45 | #include <linux/nfs4.h> |
| 46 | #include <linux/nfs_fs.h> |
| 47 | #include <linux/nfs_page.h> |
| 48 | #include <linux/smp_lock.h> |
| 49 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 50 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 52 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 54 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 55 | #include "iostat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 58 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 59 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 61 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 62 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 63 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | 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] | 65 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 66 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 67 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 70 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | if (err < -1000) { |
| 73 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 74 | __func__, -err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return -EIO; |
| 76 | } |
| 77 | return err; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * This is our standard bitmap for GETATTR requests. |
| 82 | */ |
| 83 | const u32 nfs4_fattr_bitmap[2] = { |
| 84 | FATTR4_WORD0_TYPE |
| 85 | | FATTR4_WORD0_CHANGE |
| 86 | | FATTR4_WORD0_SIZE |
| 87 | | FATTR4_WORD0_FSID |
| 88 | | FATTR4_WORD0_FILEID, |
| 89 | FATTR4_WORD1_MODE |
| 90 | | FATTR4_WORD1_NUMLINKS |
| 91 | | FATTR4_WORD1_OWNER |
| 92 | | FATTR4_WORD1_OWNER_GROUP |
| 93 | | FATTR4_WORD1_RAWDEV |
| 94 | | FATTR4_WORD1_SPACE_USED |
| 95 | | FATTR4_WORD1_TIME_ACCESS |
| 96 | | FATTR4_WORD1_TIME_METADATA |
| 97 | | FATTR4_WORD1_TIME_MODIFY |
| 98 | }; |
| 99 | |
| 100 | const u32 nfs4_statfs_bitmap[2] = { |
| 101 | FATTR4_WORD0_FILES_AVAIL |
| 102 | | FATTR4_WORD0_FILES_FREE |
| 103 | | FATTR4_WORD0_FILES_TOTAL, |
| 104 | FATTR4_WORD1_SPACE_AVAIL |
| 105 | | FATTR4_WORD1_SPACE_FREE |
| 106 | | FATTR4_WORD1_SPACE_TOTAL |
| 107 | }; |
| 108 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 109 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | FATTR4_WORD0_MAXLINK |
| 111 | | FATTR4_WORD0_MAXNAME, |
| 112 | 0 |
| 113 | }; |
| 114 | |
| 115 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 116 | | FATTR4_WORD0_MAXREAD |
| 117 | | FATTR4_WORD0_MAXWRITE |
| 118 | | FATTR4_WORD0_LEASE_TIME, |
| 119 | 0 |
| 120 | }; |
| 121 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 122 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 123 | FATTR4_WORD0_TYPE |
| 124 | | FATTR4_WORD0_CHANGE |
| 125 | | FATTR4_WORD0_SIZE |
| 126 | | FATTR4_WORD0_FSID |
| 127 | | FATTR4_WORD0_FILEID |
| 128 | | FATTR4_WORD0_FS_LOCATIONS, |
| 129 | FATTR4_WORD1_MODE |
| 130 | | FATTR4_WORD1_NUMLINKS |
| 131 | | FATTR4_WORD1_OWNER |
| 132 | | FATTR4_WORD1_OWNER_GROUP |
| 133 | | FATTR4_WORD1_RAWDEV |
| 134 | | FATTR4_WORD1_SPACE_USED |
| 135 | | FATTR4_WORD1_TIME_ACCESS |
| 136 | | FATTR4_WORD1_TIME_METADATA |
| 137 | | FATTR4_WORD1_TIME_MODIFY |
| 138 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 139 | }; |
| 140 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 141 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | struct nfs4_readdir_arg *readdir) |
| 143 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 144 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | BUG_ON(readdir->count < 80); |
| 147 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 148 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | readdir->cookie = 0; |
| 154 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 155 | if (cookie == 2) |
| 156 | return; |
| 157 | |
| 158 | /* |
| 159 | * NFSv4 servers do not return entries for '.' and '..' |
| 160 | * Therefore, we fake these entries here. We let '.' |
| 161 | * have cookie 0 and '..' have cookie 1. Note that |
| 162 | * when talking to the server, we always send cookie 0 |
| 163 | * instead of 1 or 2. |
| 164 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 165 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | if (cookie == 0) { |
| 168 | *p++ = xdr_one; /* next */ |
| 169 | *p++ = xdr_zero; /* cookie, first word */ |
| 170 | *p++ = xdr_one; /* cookie, second word */ |
| 171 | *p++ = xdr_one; /* entry len */ |
| 172 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 173 | p++; |
| 174 | *p++ = xdr_one; /* bitmap length */ |
| 175 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 176 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 177 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | *p++ = xdr_one; /* next */ |
| 181 | *p++ = xdr_zero; /* cookie, first word */ |
| 182 | *p++ = xdr_two; /* cookie, second word */ |
| 183 | *p++ = xdr_two; /* entry len */ |
| 184 | memcpy(p, "..\0\0", 4); /* entry */ |
| 185 | p++; |
| 186 | *p++ = xdr_one; /* bitmap length */ |
| 187 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 188 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 189 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | readdir->pgbase = (char *)p - (char *)start; |
| 192 | readdir->count -= readdir->pgbase; |
| 193 | kunmap_atomic(start, KM_USER0); |
| 194 | } |
| 195 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 196 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 197 | { |
| 198 | int res; |
| 199 | |
| 200 | might_sleep(); |
| 201 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 202 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 203 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 204 | return res; |
| 205 | } |
| 206 | |
| 207 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 208 | { |
| 209 | int res = 0; |
| 210 | |
| 211 | might_sleep(); |
| 212 | |
| 213 | if (*timeout <= 0) |
| 214 | *timeout = NFS4_POLL_RETRY_MIN; |
| 215 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 216 | *timeout = NFS4_POLL_RETRY_MAX; |
| 217 | schedule_timeout_killable(*timeout); |
| 218 | if (fatal_signal_pending(current)) |
| 219 | res = -ERESTARTSYS; |
| 220 | *timeout <<= 1; |
| 221 | return res; |
| 222 | } |
| 223 | |
| 224 | /* This is the error handling routine for processes that are allowed |
| 225 | * to sleep. |
| 226 | */ |
| 227 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 228 | { |
| 229 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 230 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 231 | int ret = errorcode; |
| 232 | |
| 233 | exception->retry = 0; |
| 234 | switch(errorcode) { |
| 235 | case 0: |
| 236 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 237 | case -NFS4ERR_ADMIN_REVOKED: |
| 238 | case -NFS4ERR_BAD_STATEID: |
| 239 | case -NFS4ERR_OPENMODE: |
| 240 | if (state == NULL) |
| 241 | break; |
| 242 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 243 | case -NFS4ERR_STALE_CLIENTID: |
| 244 | case -NFS4ERR_STALE_STATEID: |
| 245 | case -NFS4ERR_EXPIRED: |
| 246 | nfs4_schedule_state_recovery(clp); |
| 247 | ret = nfs4_wait_clnt_recover(clp); |
| 248 | if (ret == 0) |
| 249 | exception->retry = 1; |
| 250 | break; |
| 251 | case -NFS4ERR_FILE_OPEN: |
| 252 | case -NFS4ERR_GRACE: |
| 253 | case -NFS4ERR_DELAY: |
| 254 | ret = nfs4_delay(server->client, &exception->timeout); |
| 255 | if (ret != 0) |
| 256 | break; |
| 257 | case -NFS4ERR_OLD_STATEID: |
| 258 | exception->retry = 1; |
| 259 | } |
| 260 | /* We failed to handle the error */ |
| 261 | return nfs4_map_errors(ret); |
| 262 | } |
| 263 | |
| 264 | |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 265 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 267 | struct nfs_client *clp = server->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | spin_lock(&clp->cl_lock); |
| 269 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 270 | clp->cl_last_renewal = timestamp; |
| 271 | spin_unlock(&clp->cl_lock); |
| 272 | } |
| 273 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 274 | #if defined(CONFIG_NFS_V4_1) |
| 275 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame^] | 276 | /* |
| 277 | * nfs4_find_slot - efficiently look for a free slot |
| 278 | * |
| 279 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 280 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 281 | * and respectively set up the sequence operation args. |
| 282 | * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. |
| 283 | */ |
| 284 | static u8 |
| 285 | nfs4_find_slot(struct nfs4_slot_table *tbl, struct rpc_task *task) |
| 286 | { |
| 287 | int slotid; |
| 288 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 289 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 290 | |
| 291 | spin_lock(&tbl->slot_tbl_lock); |
| 292 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 293 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 294 | tbl->max_slots); |
| 295 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 296 | if (slotid >= tbl->max_slots) |
| 297 | goto out; |
| 298 | __set_bit(slotid, tbl->used_slots); |
| 299 | if (slotid > tbl->highest_used_slotid) |
| 300 | tbl->highest_used_slotid = slotid; |
| 301 | ret_id = slotid; |
| 302 | out: |
| 303 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 304 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
| 305 | spin_unlock(&tbl->slot_tbl_lock); |
| 306 | return ret_id; |
| 307 | } |
| 308 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 309 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 310 | struct nfs4_sequence_args *args, |
| 311 | struct nfs4_sequence_res *res, |
| 312 | int cache_reply, |
| 313 | struct rpc_task *task) |
| 314 | { |
| 315 | /* slot already allocated? */ |
| 316 | if (res->sr_slotid != NFS4_MAX_SLOT_TABLE) |
| 317 | return 0; |
| 318 | |
| 319 | memset(res, 0, sizeof(*res)); |
| 320 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | int nfs4_setup_sequence(struct nfs_client *clp, |
| 325 | struct nfs4_sequence_args *args, |
| 326 | struct nfs4_sequence_res *res, |
| 327 | int cache_reply, |
| 328 | struct rpc_task *task) |
| 329 | { |
| 330 | int ret = 0; |
| 331 | |
| 332 | dprintk("--> %s clp %p session %p sr_slotid %d\n", |
| 333 | __func__, clp, clp->cl_session, res->sr_slotid); |
| 334 | |
| 335 | if (!nfs4_has_session(clp)) |
| 336 | goto out; |
| 337 | ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply, |
| 338 | task); |
| 339 | if (ret != -EAGAIN) { |
| 340 | /* terminate rpc task */ |
| 341 | task->tk_status = ret; |
| 342 | task->tk_action = NULL; |
| 343 | } |
| 344 | out: |
| 345 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 346 | return ret; |
| 347 | } |
| 348 | |
| 349 | struct nfs41_call_sync_data { |
| 350 | struct nfs_client *clp; |
| 351 | struct nfs4_sequence_args *seq_args; |
| 352 | struct nfs4_sequence_res *seq_res; |
| 353 | int cache_reply; |
| 354 | }; |
| 355 | |
| 356 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 357 | { |
| 358 | struct nfs41_call_sync_data *data = calldata; |
| 359 | |
| 360 | dprintk("--> %s data->clp->cl_session %p\n", __func__, |
| 361 | data->clp->cl_session); |
| 362 | if (nfs4_setup_sequence(data->clp, data->seq_args, |
| 363 | data->seq_res, data->cache_reply, task)) |
| 364 | return; |
| 365 | rpc_call_start(task); |
| 366 | } |
| 367 | |
| 368 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 369 | .rpc_call_prepare = nfs41_call_sync_prepare, |
| 370 | }; |
| 371 | |
| 372 | static int nfs4_call_sync_sequence(struct nfs_client *clp, |
| 373 | struct rpc_clnt *clnt, |
| 374 | struct rpc_message *msg, |
| 375 | struct nfs4_sequence_args *args, |
| 376 | struct nfs4_sequence_res *res, |
| 377 | int cache_reply) |
| 378 | { |
| 379 | int ret; |
| 380 | struct rpc_task *task; |
| 381 | struct nfs41_call_sync_data data = { |
| 382 | .clp = clp, |
| 383 | .seq_args = args, |
| 384 | .seq_res = res, |
| 385 | .cache_reply = cache_reply, |
| 386 | }; |
| 387 | struct rpc_task_setup task_setup = { |
| 388 | .rpc_client = clnt, |
| 389 | .rpc_message = msg, |
| 390 | .callback_ops = &nfs41_call_sync_ops, |
| 391 | .callback_data = &data |
| 392 | }; |
| 393 | |
| 394 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 395 | task = rpc_run_task(&task_setup); |
| 396 | if (IS_ERR(task)) |
| 397 | ret = PTR_ERR(task); |
| 398 | else { |
| 399 | ret = task->tk_status; |
| 400 | rpc_put_task(task); |
| 401 | } |
| 402 | return ret; |
| 403 | } |
| 404 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 405 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 406 | struct rpc_message *msg, |
| 407 | struct nfs4_sequence_args *args, |
| 408 | struct nfs4_sequence_res *res, |
| 409 | int cache_reply) |
| 410 | { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 411 | return nfs4_call_sync_sequence(server->nfs_client, server->client, |
| 412 | msg, args, res, cache_reply); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | #endif /* CONFIG_NFS_V4_1 */ |
| 416 | |
| 417 | int _nfs4_call_sync(struct nfs_server *server, |
| 418 | struct rpc_message *msg, |
| 419 | struct nfs4_sequence_args *args, |
| 420 | struct nfs4_sequence_res *res, |
| 421 | int cache_reply) |
| 422 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 423 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 424 | return rpc_call_sync(server->client, msg, 0); |
| 425 | } |
| 426 | |
| 427 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
| 428 | (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \ |
| 429 | &(res)->seq_res, (cache_reply)) |
| 430 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 431 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 433 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 435 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 436 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 437 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 438 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 439 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 440 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 443 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 444 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 445 | struct nfs_openargs o_arg; |
| 446 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 447 | struct nfs_open_confirmargs c_arg; |
| 448 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 449 | struct nfs_fattr f_attr; |
| 450 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 451 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 452 | struct dentry *dir; |
| 453 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 454 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 455 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 456 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 457 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 458 | int rpc_status; |
| 459 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 460 | }; |
| 461 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 462 | |
| 463 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 464 | { |
| 465 | p->o_res.f_attr = &p->f_attr; |
| 466 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 467 | p->o_res.seqid = p->o_arg.seqid; |
| 468 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 469 | p->o_res.server = p->o_arg.server; |
| 470 | nfs_fattr_init(&p->f_attr); |
| 471 | nfs_fattr_init(&p->dir_attr); |
| 472 | } |
| 473 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 474 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 475 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 476 | const struct iattr *attrs) |
| 477 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 478 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 479 | struct inode *dir = parent->d_inode; |
| 480 | struct nfs_server *server = NFS_SERVER(dir); |
| 481 | struct nfs4_opendata *p; |
| 482 | |
| 483 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 484 | if (p == NULL) |
| 485 | goto err; |
| 486 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); |
| 487 | if (p->o_arg.seqid == NULL) |
| 488 | goto err_free; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 489 | p->path.mnt = mntget(path->mnt); |
| 490 | p->path.dentry = dget(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 491 | p->dir = parent; |
| 492 | p->owner = sp; |
| 493 | atomic_inc(&sp->so_count); |
| 494 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 495 | p->o_arg.open_flags = flags; |
| 496 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 497 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 498 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 499 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 500 | p->o_arg.server = server; |
| 501 | p->o_arg.bitmask = server->attr_bitmask; |
| 502 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 503 | p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 504 | if (flags & O_EXCL) { |
| 505 | u32 *s = (u32 *) p->o_arg.u.verifier.data; |
| 506 | s[0] = jiffies; |
| 507 | s[1] = current->pid; |
| 508 | } else if (flags & O_CREAT) { |
| 509 | p->o_arg.u.attrs = &p->attrs; |
| 510 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
| 511 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 512 | p->c_arg.fh = &p->o_res.fh; |
| 513 | p->c_arg.stateid = &p->o_res.stateid; |
| 514 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 515 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 516 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 517 | return p; |
| 518 | err_free: |
| 519 | kfree(p); |
| 520 | err: |
| 521 | dput(parent); |
| 522 | return NULL; |
| 523 | } |
| 524 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 525 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 526 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 527 | struct nfs4_opendata *p = container_of(kref, |
| 528 | struct nfs4_opendata, kref); |
| 529 | |
| 530 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 531 | if (p->state != NULL) |
| 532 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 533 | nfs4_put_state_owner(p->owner); |
| 534 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 535 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 536 | kfree(p); |
| 537 | } |
| 538 | |
| 539 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 540 | { |
| 541 | if (p != NULL) |
| 542 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 545 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 546 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 547 | int ret; |
| 548 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 549 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 550 | return ret; |
| 551 | } |
| 552 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 553 | 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] | 554 | { |
| 555 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 556 | |
| 557 | if (open_mode & O_EXCL) |
| 558 | goto out; |
| 559 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 560 | case FMODE_READ: |
| 561 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 562 | break; |
| 563 | case FMODE_WRITE: |
| 564 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 565 | break; |
| 566 | case FMODE_READ|FMODE_WRITE: |
| 567 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0; |
| 568 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 569 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 570 | return ret; |
| 571 | } |
| 572 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 573 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 574 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 575 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 576 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 577 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 578 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 579 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 580 | return 1; |
| 581 | } |
| 582 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 583 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 584 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 585 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 586 | case FMODE_WRITE: |
| 587 | state->n_wronly++; |
| 588 | break; |
| 589 | case FMODE_READ: |
| 590 | state->n_rdonly++; |
| 591 | break; |
| 592 | case FMODE_READ|FMODE_WRITE: |
| 593 | state->n_rdwr++; |
| 594 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 595 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 596 | } |
| 597 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 598 | 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] | 599 | { |
| 600 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 601 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 602 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 603 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 604 | case FMODE_READ: |
| 605 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 606 | break; |
| 607 | case FMODE_WRITE: |
| 608 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 609 | break; |
| 610 | case FMODE_READ|FMODE_WRITE: |
| 611 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 612 | } |
| 613 | } |
| 614 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 615 | 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] | 616 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 617 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 618 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 619 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 620 | } |
| 621 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 622 | 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] | 623 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 624 | /* |
| 625 | * Protect the call to nfs4_state_set_mode_locked and |
| 626 | * serialise the stateid update |
| 627 | */ |
| 628 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 629 | if (deleg_stateid != NULL) { |
| 630 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 631 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 632 | } |
| 633 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 634 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 635 | write_sequnlock(&state->seqlock); |
| 636 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 637 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 638 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 641 | 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] | 642 | { |
| 643 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 644 | struct nfs_delegation *deleg_cur; |
| 645 | int ret = 0; |
| 646 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 647 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 648 | |
| 649 | rcu_read_lock(); |
| 650 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 651 | if (deleg_cur == NULL) |
| 652 | goto no_delegation; |
| 653 | |
| 654 | spin_lock(&deleg_cur->lock); |
| 655 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 656 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 657 | goto no_delegation_unlock; |
| 658 | |
| 659 | if (delegation == NULL) |
| 660 | delegation = &deleg_cur->stateid; |
| 661 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 662 | goto no_delegation_unlock; |
| 663 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 664 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 665 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 666 | ret = 1; |
| 667 | no_delegation_unlock: |
| 668 | spin_unlock(&deleg_cur->lock); |
| 669 | no_delegation: |
| 670 | rcu_read_unlock(); |
| 671 | |
| 672 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 673 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 674 | ret = 1; |
| 675 | } |
| 676 | |
| 677 | return ret; |
| 678 | } |
| 679 | |
| 680 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 681 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 682 | { |
| 683 | struct nfs_delegation *delegation; |
| 684 | |
| 685 | rcu_read_lock(); |
| 686 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 687 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 688 | rcu_read_unlock(); |
| 689 | return; |
| 690 | } |
| 691 | rcu_read_unlock(); |
| 692 | nfs_inode_return_delegation(inode); |
| 693 | } |
| 694 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 695 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 696 | { |
| 697 | struct nfs4_state *state = opendata->state; |
| 698 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 699 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 700 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 701 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 702 | nfs4_stateid stateid; |
| 703 | int ret = -EAGAIN; |
| 704 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 705 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 706 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 707 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 708 | if (can_open_cached(state, fmode, open_mode)) { |
| 709 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 710 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 711 | goto out_return_state; |
| 712 | } |
| 713 | spin_unlock(&state->owner->so_lock); |
| 714 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 715 | rcu_read_lock(); |
| 716 | delegation = rcu_dereference(nfsi->delegation); |
| 717 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 718 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 719 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 720 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 721 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 722 | /* Save the delegation */ |
| 723 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 724 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 725 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 726 | if (ret != 0) |
| 727 | goto out; |
| 728 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 729 | |
| 730 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 731 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 732 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 733 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 734 | out: |
| 735 | return ERR_PTR(ret); |
| 736 | out_return_state: |
| 737 | atomic_inc(&state->count); |
| 738 | return state; |
| 739 | } |
| 740 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 741 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 742 | { |
| 743 | struct inode *inode; |
| 744 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 745 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 746 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 747 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 748 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 749 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 750 | goto out; |
| 751 | } |
| 752 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 753 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 754 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 755 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 756 | 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] | 757 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 758 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 759 | goto err; |
| 760 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 761 | state = nfs4_get_open_state(inode, data->owner); |
| 762 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 763 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 764 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 765 | int delegation_flags = 0; |
| 766 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 767 | rcu_read_lock(); |
| 768 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 769 | if (delegation) |
| 770 | delegation_flags = delegation->flags; |
| 771 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 772 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 773 | nfs_inode_set_delegation(state->inode, |
| 774 | data->owner->so_cred, |
| 775 | &data->o_res); |
| 776 | else |
| 777 | nfs_inode_reclaim_delegation(state->inode, |
| 778 | data->owner->so_cred, |
| 779 | &data->o_res); |
| 780 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 781 | |
| 782 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 783 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 784 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 785 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 786 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 787 | err_put_inode: |
| 788 | iput(inode); |
| 789 | err: |
| 790 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 791 | } |
| 792 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 793 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 794 | { |
| 795 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 796 | struct nfs_open_context *ctx; |
| 797 | |
| 798 | spin_lock(&state->inode->i_lock); |
| 799 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 800 | if (ctx->state != state) |
| 801 | continue; |
| 802 | get_nfs_open_context(ctx); |
| 803 | spin_unlock(&state->inode->i_lock); |
| 804 | return ctx; |
| 805 | } |
| 806 | spin_unlock(&state->inode->i_lock); |
| 807 | return ERR_PTR(-ENOENT); |
| 808 | } |
| 809 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 810 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 811 | { |
| 812 | struct nfs4_opendata *opendata; |
| 813 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 814 | opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 815 | if (opendata == NULL) |
| 816 | return ERR_PTR(-ENOMEM); |
| 817 | opendata->state = state; |
| 818 | atomic_inc(&state->count); |
| 819 | return opendata; |
| 820 | } |
| 821 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 822 | 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] | 823 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 824 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 825 | int ret; |
| 826 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 827 | opendata->o_arg.open_flags = 0; |
| 828 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 829 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 830 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 831 | nfs4_init_opendata_res(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 832 | ret = _nfs4_proc_open(opendata); |
| 833 | if (ret != 0) |
| 834 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 835 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 836 | if (IS_ERR(newstate)) |
| 837 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 838 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 839 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 844 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 845 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 846 | int ret; |
| 847 | |
| 848 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 849 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 850 | smp_rmb(); |
| 851 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 852 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 853 | if (ret != 0) |
| 854 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 855 | if (newstate != state) |
| 856 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 857 | } |
| 858 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 859 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 860 | if (ret != 0) |
| 861 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 862 | if (newstate != state) |
| 863 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 864 | } |
| 865 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 866 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 867 | if (ret != 0) |
| 868 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 869 | if (newstate != state) |
| 870 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 871 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 872 | /* |
| 873 | * We may have performed cached opens for all three recoveries. |
| 874 | * Check if we need to update the current stateid. |
| 875 | */ |
| 876 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 877 | 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] | 878 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 879 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 880 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 881 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 882 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 883 | return 0; |
| 884 | } |
| 885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | /* |
| 887 | * OPEN_RECLAIM: |
| 888 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 890 | 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] | 891 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 892 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 893 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | int status; |
| 896 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 897 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 898 | if (IS_ERR(opendata)) |
| 899 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 900 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 901 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 902 | rcu_read_lock(); |
| 903 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 904 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 905 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 906 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 907 | opendata->o_arg.u.delegation_type = delegation_type; |
| 908 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 909 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | return status; |
| 911 | } |
| 912 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 913 | 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] | 914 | { |
| 915 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 916 | struct nfs4_exception exception = { }; |
| 917 | int err; |
| 918 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 919 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 920 | if (err != -NFS4ERR_DELAY) |
| 921 | break; |
| 922 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } while (exception.retry); |
| 924 | return err; |
| 925 | } |
| 926 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 927 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 928 | { |
| 929 | struct nfs_open_context *ctx; |
| 930 | int ret; |
| 931 | |
| 932 | ctx = nfs4_state_find_open_context(state); |
| 933 | if (IS_ERR(ctx)) |
| 934 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 935 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 936 | put_nfs_open_context(ctx); |
| 937 | return ret; |
| 938 | } |
| 939 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 940 | 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] | 941 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 942 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 943 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 945 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 946 | if (IS_ERR(opendata)) |
| 947 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 948 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 949 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 950 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 951 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 952 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 953 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 956 | 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] | 957 | { |
| 958 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 959 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | int err; |
| 961 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 962 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | switch (err) { |
| 964 | case 0: |
| 965 | return err; |
| 966 | case -NFS4ERR_STALE_CLIENTID: |
| 967 | case -NFS4ERR_STALE_STATEID: |
| 968 | case -NFS4ERR_EXPIRED: |
| 969 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 970 | nfs4_schedule_state_recovery(server->nfs_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | return err; |
| 972 | } |
| 973 | err = nfs4_handle_exception(server, err, &exception); |
| 974 | } while (exception.retry); |
| 975 | return err; |
| 976 | } |
| 977 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 978 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 979 | { |
| 980 | struct nfs4_opendata *data = calldata; |
| 981 | |
| 982 | data->rpc_status = task->tk_status; |
| 983 | if (RPC_ASSASSINATED(task)) |
| 984 | return; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 985 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 986 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 987 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 988 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 989 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 990 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 991 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | static void nfs4_open_confirm_release(void *calldata) |
| 995 | { |
| 996 | struct nfs4_opendata *data = calldata; |
| 997 | struct nfs4_state *state = NULL; |
| 998 | |
| 999 | /* If this request hasn't been cancelled, do nothing */ |
| 1000 | if (data->cancelled == 0) |
| 1001 | goto out_free; |
| 1002 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1003 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1004 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1005 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1006 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1007 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1008 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1009 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1013 | .rpc_call_done = nfs4_open_confirm_done, |
| 1014 | .rpc_release = nfs4_open_confirm_release, |
| 1015 | }; |
| 1016 | |
| 1017 | /* |
| 1018 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1019 | */ |
| 1020 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1021 | { |
| 1022 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1023 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1024 | struct rpc_message msg = { |
| 1025 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1026 | .rpc_argp = &data->c_arg, |
| 1027 | .rpc_resp = &data->c_res, |
| 1028 | .rpc_cred = data->owner->so_cred, |
| 1029 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1030 | struct rpc_task_setup task_setup_data = { |
| 1031 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1032 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1033 | .callback_ops = &nfs4_open_confirm_ops, |
| 1034 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1035 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1036 | .flags = RPC_TASK_ASYNC, |
| 1037 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | int status; |
| 1039 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1040 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1041 | data->rpc_done = 0; |
| 1042 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1043 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1044 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1045 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1046 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1047 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1048 | if (status != 0) { |
| 1049 | data->cancelled = 1; |
| 1050 | smp_wmb(); |
| 1051 | } else |
| 1052 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1053 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | return status; |
| 1055 | } |
| 1056 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1057 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1059 | struct nfs4_opendata *data = calldata; |
| 1060 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1061 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1062 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1063 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1064 | /* |
| 1065 | * Check if we still need to send an OPEN call, or if we can use |
| 1066 | * a delegation instead. |
| 1067 | */ |
| 1068 | if (data->state != NULL) { |
| 1069 | struct nfs_delegation *delegation; |
| 1070 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1071 | 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] | 1072 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1073 | rcu_read_lock(); |
| 1074 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1075 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1076 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1077 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1078 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1079 | } |
| 1080 | rcu_read_unlock(); |
| 1081 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1082 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1083 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1084 | data->o_arg.clientid = sp->so_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1085 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1086 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1087 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1088 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1089 | data->timestamp = jiffies; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1090 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1091 | return; |
| 1092 | out_no_action: |
| 1093 | task->tk_action = NULL; |
| 1094 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1097 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1098 | { |
| 1099 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1101 | data->rpc_status = task->tk_status; |
| 1102 | if (RPC_ASSASSINATED(task)) |
| 1103 | return; |
| 1104 | if (task->tk_status == 0) { |
| 1105 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1106 | case S_IFREG: |
| 1107 | break; |
| 1108 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1109 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1110 | break; |
| 1111 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1112 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1113 | break; |
| 1114 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1115 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1116 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1117 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1118 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1119 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1120 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1121 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1122 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1123 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1124 | static void nfs4_open_release(void *calldata) |
| 1125 | { |
| 1126 | struct nfs4_opendata *data = calldata; |
| 1127 | struct nfs4_state *state = NULL; |
| 1128 | |
| 1129 | /* If this request hasn't been cancelled, do nothing */ |
| 1130 | if (data->cancelled == 0) |
| 1131 | goto out_free; |
| 1132 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1133 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1134 | goto out_free; |
| 1135 | /* In case we need an open_confirm, no cleanup! */ |
| 1136 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1137 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1138 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1139 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1140 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1141 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1142 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1146 | .rpc_call_prepare = nfs4_open_prepare, |
| 1147 | .rpc_call_done = nfs4_open_done, |
| 1148 | .rpc_release = nfs4_open_release, |
| 1149 | }; |
| 1150 | |
| 1151 | /* |
| 1152 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1153 | */ |
| 1154 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1155 | { |
| 1156 | struct inode *dir = data->dir->d_inode; |
| 1157 | struct nfs_server *server = NFS_SERVER(dir); |
| 1158 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1159 | struct nfs_openres *o_res = &data->o_res; |
| 1160 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1161 | struct rpc_message msg = { |
| 1162 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1163 | .rpc_argp = o_arg, |
| 1164 | .rpc_resp = o_res, |
| 1165 | .rpc_cred = data->owner->so_cred, |
| 1166 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1167 | struct rpc_task_setup task_setup_data = { |
| 1168 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1169 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1170 | .callback_ops = &nfs4_open_ops, |
| 1171 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1172 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1173 | .flags = RPC_TASK_ASYNC, |
| 1174 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1175 | int status; |
| 1176 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1177 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1178 | data->rpc_done = 0; |
| 1179 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1180 | data->cancelled = 0; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1181 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1182 | if (IS_ERR(task)) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1183 | return PTR_ERR(task); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1184 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1185 | if (status != 0) { |
| 1186 | data->cancelled = 1; |
| 1187 | smp_wmb(); |
| 1188 | } else |
| 1189 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1190 | rpc_put_task(task); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1191 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1192 | return status; |
| 1193 | |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1194 | if (o_res->fh.size == 0) |
| 1195 | _nfs4_proc_lookup(dir, o_arg->name, &o_res->fh, o_res->f_attr); |
| 1196 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1197 | if (o_arg->open_flags & O_CREAT) { |
| 1198 | update_changeattr(dir, &o_res->cinfo); |
| 1199 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1200 | } else |
| 1201 | nfs_refresh_inode(dir, o_res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1203 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1205 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } |
| 1207 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1208 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1209 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Trond Myklebust | 10afec90 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1212 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1213 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1214 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1215 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1216 | |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1217 | for (;;) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1218 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1219 | if (ret != 0) |
| 1220 | return ret; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1221 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1222 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1223 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1224 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1225 | } |
| 1226 | return 0; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1227 | } |
| 1228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | /* |
| 1230 | * OPEN_EXPIRED: |
| 1231 | * reclaim state on the server after a network partition. |
| 1232 | * Assumes caller holds the appropriate lock |
| 1233 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1234 | 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] | 1235 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1236 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1237 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1239 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1240 | if (IS_ERR(opendata)) |
| 1241 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1242 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1243 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1244 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1245 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1246 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1249 | static inline 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] | 1250 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1251 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1252 | struct nfs4_exception exception = { }; |
| 1253 | int err; |
| 1254 | |
| 1255 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1256 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 027b6ca | 2008-12-23 16:04:13 -0500 | [diff] [blame] | 1257 | if (err != -NFS4ERR_DELAY) |
| 1258 | break; |
| 1259 | nfs4_handle_exception(server, err, &exception); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1260 | } while (exception.retry); |
| 1261 | return err; |
| 1262 | } |
| 1263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1265 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1267 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1269 | ctx = nfs4_state_find_open_context(state); |
| 1270 | if (IS_ERR(ctx)) |
| 1271 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1272 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1273 | put_nfs_open_context(ctx); |
| 1274 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1278 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1279 | * fields corresponding to attributes that were used to store the verifier. |
| 1280 | * Make sure we clobber those fields in the later setattr call |
| 1281 | */ |
| 1282 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1283 | { |
| 1284 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1285 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1286 | sattr->ia_valid |= ATTR_ATIME; |
| 1287 | |
| 1288 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1289 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1290 | sattr->ia_valid |= ATTR_MTIME; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1294 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1296 | static int _nfs4_do_open(struct inode *dir, struct path *path, 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] | 1297 | { |
| 1298 | struct nfs4_state_owner *sp; |
| 1299 | struct nfs4_state *state = NULL; |
| 1300 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1301 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1302 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | status = -ENOMEM; |
| 1306 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1307 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1308 | goto out_err; |
| 1309 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1310 | status = nfs4_recover_expired_lease(server); |
| 1311 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1312 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1313 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1314 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1315 | status = -ENOMEM; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1316 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1317 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1318 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1320 | if (path->dentry->d_inode != NULL) |
| 1321 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1322 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1323 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1325 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1327 | if (opendata->o_arg.open_flags & O_EXCL) |
| 1328 | nfs4_exclusive_attrset(opendata, sattr); |
| 1329 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1330 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1331 | status = PTR_ERR(state); |
| 1332 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1333 | goto err_opendata_put; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1334 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | *res = state; |
| 1337 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1338 | err_opendata_put: |
| 1339 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1340 | err_put_state_owner: |
| 1341 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | *res = NULL; |
| 1344 | return status; |
| 1345 | } |
| 1346 | |
| 1347 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | { |
| 1350 | struct nfs4_exception exception = { }; |
| 1351 | struct nfs4_state *res; |
| 1352 | int status; |
| 1353 | |
| 1354 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | if (status == 0) |
| 1357 | break; |
| 1358 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1359 | * book-keeping w.r.t. state-changing operations |
| 1360 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1361 | * It is actually a sign of a bug on the client or on the server. |
| 1362 | * |
| 1363 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1364 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | * have unhashed the old state_owner for us, and that we can |
| 1366 | * therefore safely retry using a new one. We should still warn |
| 1367 | * the user though... |
| 1368 | */ |
| 1369 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1370 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1371 | " returned a bad sequence-id error!\n", |
| 1372 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | exception.retry = 1; |
| 1374 | continue; |
| 1375 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1376 | /* |
| 1377 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1378 | * state before it received the OPEN_CONFIRM. |
| 1379 | * Recover by retrying the request as per the discussion |
| 1380 | * on Page 181 of RFC3530. |
| 1381 | */ |
| 1382 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1383 | exception.retry = 1; |
| 1384 | continue; |
| 1385 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1386 | if (status == -EAGAIN) { |
| 1387 | /* We must have found a delegation */ |
| 1388 | exception.retry = 1; |
| 1389 | continue; |
| 1390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1392 | status, &exception)); |
| 1393 | } while (exception.retry); |
| 1394 | return res; |
| 1395 | } |
| 1396 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1397 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1398 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1399 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1401 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1403 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | .iap = sattr, |
| 1405 | .server = server, |
| 1406 | .bitmask = server->attr_bitmask, |
| 1407 | }; |
| 1408 | struct nfs_setattrres res = { |
| 1409 | .fattr = fattr, |
| 1410 | .server = server, |
| 1411 | }; |
| 1412 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1414 | .rpc_argp = &arg, |
| 1415 | .rpc_resp = &res, |
| 1416 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1418 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1419 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1421 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1423 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1424 | /* Use that stateid */ |
| 1425 | } else if (state != NULL) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1426 | nfs4_copy_stateid(&arg.stateid, state, current->files); |
| 1427 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1429 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1430 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1431 | if (status == 0 && state != NULL) |
| 1432 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1433 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1436 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1437 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1438 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1440 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | struct nfs4_exception exception = { }; |
| 1442 | int err; |
| 1443 | do { |
| 1444 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1445 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | &exception); |
| 1447 | } while (exception.retry); |
| 1448 | return err; |
| 1449 | } |
| 1450 | |
| 1451 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1452 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | struct inode *inode; |
| 1454 | struct nfs4_state *state; |
| 1455 | struct nfs_closeargs arg; |
| 1456 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1457 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1458 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | }; |
| 1460 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1461 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1462 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1463 | struct nfs4_closedata *calldata = data; |
| 1464 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1465 | |
| 1466 | nfs4_put_open_state(calldata->state); |
| 1467 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1468 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1469 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1470 | kfree(calldata); |
| 1471 | } |
| 1472 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1473 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1475 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1478 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1479 | if (RPC_ASSASSINATED(task)) |
| 1480 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | /* hmm. we are done with the inode, and in the process of freeing |
| 1482 | * the state_owner. we keep this around to process errors |
| 1483 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | switch (task->tk_status) { |
| 1485 | case 0: |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1486 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1487 | renew_lease(server, calldata->timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | break; |
| 1489 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1490 | case -NFS4ERR_OLD_STATEID: |
| 1491 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1493 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1494 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1496 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | rpc_restart_call(task); |
| 1498 | return; |
| 1499 | } |
| 1500 | } |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1501 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1504 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1506 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1507 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1508 | int clear_rd, clear_wr, clear_rdwr; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1509 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1510 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1511 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1512 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1513 | clear_rd = clear_wr = clear_rdwr = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1514 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1515 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1516 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1517 | if (state->n_rdonly == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1518 | clear_rd |= test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1519 | clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1520 | } |
| 1521 | if (state->n_wronly == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1522 | clear_wr |= test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1523 | clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1524 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1525 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1526 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1527 | if (!clear_rd && !clear_wr && !clear_rdwr) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1528 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1529 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1530 | return; |
| 1531 | } |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1532 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1533 | if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1534 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1535 | calldata->arg.fmode = FMODE_READ; |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1536 | } else if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1537 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1538 | calldata->arg.fmode = FMODE_WRITE; |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1539 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1540 | calldata->timestamp = jiffies; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1541 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1544 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1545 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1546 | .rpc_call_done = nfs4_close_done, |
| 1547 | .rpc_release = nfs4_free_closedata, |
| 1548 | }; |
| 1549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | /* |
| 1551 | * It is possible for data to be read/written from a mem-mapped file |
| 1552 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1553 | * This means that we can't safely call nfsv4 close on a file until |
| 1554 | * the inode is cleared. This in turn means that we are not good |
| 1555 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1556 | * share state even when we are done with one of the three share |
| 1557 | * stateid's in the inode. |
| 1558 | * |
| 1559 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1560 | */ |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1561 | int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1563 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1565 | struct nfs4_state_owner *sp = state->owner; |
| 1566 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1567 | struct rpc_message msg = { |
| 1568 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1569 | .rpc_cred = state->owner->so_cred, |
| 1570 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1571 | struct rpc_task_setup task_setup_data = { |
| 1572 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1573 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1574 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1575 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1576 | .flags = RPC_TASK_ASYNC, |
| 1577 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1578 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1580 | calldata = kmalloc(sizeof(*calldata), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1582 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1583 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1585 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1586 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | /* Serialization for the sequence id */ |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1588 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1589 | if (calldata->arg.seqid == NULL) |
| 1590 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1591 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 1592 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1593 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 1594 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1595 | calldata->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 1596 | calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1597 | calldata->path.mnt = mntget(path->mnt); |
| 1598 | calldata->path.dentry = dget(path->dentry); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1599 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1600 | msg.rpc_argp = &calldata->arg, |
| 1601 | msg.rpc_resp = &calldata->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1602 | task_setup_data.callback_data = calldata; |
| 1603 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1604 | if (IS_ERR(task)) |
| 1605 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1606 | status = 0; |
| 1607 | if (wait) |
| 1608 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1609 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1610 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1611 | out_free_calldata: |
| 1612 | kfree(calldata); |
| 1613 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1614 | nfs4_put_open_state(state); |
| 1615 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1616 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1619 | static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1620 | { |
| 1621 | struct file *filp; |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1622 | int ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1623 | |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1624 | /* If the open_intent is for execute, we have an extra check to make */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1625 | if (fmode & FMODE_EXEC) { |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1626 | ret = nfs_may_open(state->inode, |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1627 | state->owner->so_cred, |
| 1628 | nd->intent.open.flags); |
| 1629 | if (ret < 0) |
| 1630 | goto out_close; |
| 1631 | } |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1632 | filp = lookup_instantiate_filp(nd, path->dentry, NULL); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1633 | if (!IS_ERR(filp)) { |
| 1634 | struct nfs_open_context *ctx; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 1635 | ctx = nfs_file_open_context(filp); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1636 | ctx->state = state; |
Trond Myklebust | 95cf959 | 2006-04-18 13:14:06 -0400 | [diff] [blame] | 1637 | return 0; |
| 1638 | } |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1639 | ret = PTR_ERR(filp); |
| 1640 | out_close: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1641 | nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE)); |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1642 | return ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | struct dentry * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
| 1647 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1648 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1649 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1650 | .dentry = dentry, |
| 1651 | }; |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1652 | struct dentry *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | struct iattr attr; |
| 1654 | struct rpc_cred *cred; |
| 1655 | struct nfs4_state *state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1656 | struct dentry *res; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1657 | fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
| 1659 | if (nd->flags & LOOKUP_CREATE) { |
| 1660 | attr.ia_mode = nd->intent.open.create_mode; |
| 1661 | attr.ia_valid = ATTR_MODE; |
| 1662 | if (!IS_POSIXACL(dir)) |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 1663 | attr.ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | } else { |
| 1665 | attr.ia_valid = 0; |
| 1666 | BUG_ON(nd->intent.open.flags & O_CREAT); |
| 1667 | } |
| 1668 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 1669 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | if (IS_ERR(cred)) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1671 | return (struct dentry *)cred; |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 1672 | parent = dentry->d_parent; |
| 1673 | /* Protect against concurrent sillydeletes */ |
| 1674 | nfs_block_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1675 | state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1677 | if (IS_ERR(state)) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1678 | if (PTR_ERR(state) == -ENOENT) { |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1679 | d_add(dentry, NULL); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1680 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
| 1681 | } |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 1682 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1683 | return (struct dentry *)state; |
| 1684 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1685 | res = d_add_unique(dentry, igrab(state->inode)); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1686 | if (res != NULL) |
Trond Myklebust | deee936 | 2007-08-27 11:33:00 -0400 | [diff] [blame] | 1687 | path.dentry = res; |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1688 | nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 1689 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1690 | nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1691 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | int |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1695 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1697 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 1698 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1699 | .dentry = dentry, |
| 1700 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | struct rpc_cred *cred; |
| 1702 | struct nfs4_state *state; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1703 | fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 1705 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | if (IS_ERR(cred)) |
| 1707 | return PTR_ERR(cred); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1708 | state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1710 | if (IS_ERR(state)) { |
| 1711 | switch (PTR_ERR(state)) { |
| 1712 | case -EPERM: |
| 1713 | case -EACCES: |
| 1714 | case -EDQUOT: |
| 1715 | case -ENOSPC: |
| 1716 | case -EROFS: |
| 1717 | lookup_instantiate_filp(nd, (struct dentry *)state, NULL); |
| 1718 | return 1; |
Chuck Lever | b87c0ad | 2006-10-19 23:28:42 -0700 | [diff] [blame] | 1719 | default: |
| 1720 | goto out_drop; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1721 | } |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1722 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1723 | if (state->inode == dentry->d_inode) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 1724 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1725 | nfs4_intent_set_file(nd, &path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | return 1; |
| 1727 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1728 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1729 | out_drop: |
| 1730 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | return 0; |
| 1732 | } |
| 1733 | |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 1734 | void nfs4_close_context(struct nfs_open_context *ctx, int is_sync) |
| 1735 | { |
| 1736 | if (ctx->state == NULL) |
| 1737 | return; |
| 1738 | if (is_sync) |
| 1739 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 1740 | else |
| 1741 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 1742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | |
| 1744 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 1745 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 1746 | struct nfs4_server_caps_arg args = { |
| 1747 | .fhandle = fhandle, |
| 1748 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | struct nfs4_server_caps_res res = {}; |
| 1750 | struct rpc_message msg = { |
| 1751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 1752 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | .rpc_resp = &res, |
| 1754 | }; |
| 1755 | int status; |
| 1756 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1757 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | if (status == 0) { |
| 1759 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
| 1760 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 1761 | server->caps |= NFS_CAP_ACLS; |
| 1762 | if (res.has_links != 0) |
| 1763 | server->caps |= NFS_CAP_HARDLINKS; |
| 1764 | if (res.has_symlinks != 0) |
| 1765 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 1766 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 1767 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 1768 | 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] | 1769 | server->acl_bitmask = res.acl_bitmask; |
| 1770 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | return status; |
| 1773 | } |
| 1774 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 1775 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | { |
| 1777 | struct nfs4_exception exception = { }; |
| 1778 | int err; |
| 1779 | do { |
| 1780 | err = nfs4_handle_exception(server, |
| 1781 | _nfs4_server_capabilities(server, fhandle), |
| 1782 | &exception); |
| 1783 | } while (exception.retry); |
| 1784 | return err; |
| 1785 | } |
| 1786 | |
| 1787 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 1788 | struct nfs_fsinfo *info) |
| 1789 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | struct nfs4_lookup_root_arg args = { |
| 1791 | .bitmask = nfs4_fattr_bitmap, |
| 1792 | }; |
| 1793 | struct nfs4_lookup_res res = { |
| 1794 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1795 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | .fh = fhandle, |
| 1797 | }; |
| 1798 | struct rpc_message msg = { |
| 1799 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 1800 | .rpc_argp = &args, |
| 1801 | .rpc_resp = &res, |
| 1802 | }; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1803 | nfs_fattr_init(info->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1804 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 1808 | struct nfs_fsinfo *info) |
| 1809 | { |
| 1810 | struct nfs4_exception exception = { }; |
| 1811 | int err; |
| 1812 | do { |
| 1813 | err = nfs4_handle_exception(server, |
| 1814 | _nfs4_lookup_root(server, fhandle, info), |
| 1815 | &exception); |
| 1816 | } while (exception.retry); |
| 1817 | return err; |
| 1818 | } |
| 1819 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1820 | /* |
| 1821 | * get the file handle for the "/" directory on the server |
| 1822 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1824 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | int status; |
| 1827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | if (status == 0) |
| 1830 | status = nfs4_server_capabilities(server, fhandle); |
| 1831 | if (status == 0) |
| 1832 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 1833 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 1836 | /* |
| 1837 | * Get locations and (maybe) other attributes of a referral. |
| 1838 | * Note that we'll actually follow the referral later when |
| 1839 | * we detect fsid mismatch in inode revalidation |
| 1840 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 1841 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 1842 | { |
| 1843 | int status = -ENOMEM; |
| 1844 | struct page *page = NULL; |
| 1845 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 1846 | |
| 1847 | page = alloc_page(GFP_KERNEL); |
| 1848 | if (page == NULL) |
| 1849 | goto out; |
| 1850 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 1851 | if (locations == NULL) |
| 1852 | goto out; |
| 1853 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 1854 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 1855 | if (status != 0) |
| 1856 | goto out; |
| 1857 | /* Make sure server returned a different fsid for the referral */ |
| 1858 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 1859 | dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 1860 | status = -EIO; |
| 1861 | goto out; |
| 1862 | } |
| 1863 | |
| 1864 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 1865 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 1866 | if (!fattr->mode) |
| 1867 | fattr->mode = S_IFDIR; |
| 1868 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 1869 | out: |
| 1870 | if (page) |
| 1871 | __free_page(page); |
| 1872 | if (locations) |
| 1873 | kfree(locations); |
| 1874 | return status; |
| 1875 | } |
| 1876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 1878 | { |
| 1879 | struct nfs4_getattr_arg args = { |
| 1880 | .fh = fhandle, |
| 1881 | .bitmask = server->attr_bitmask, |
| 1882 | }; |
| 1883 | struct nfs4_getattr_res res = { |
| 1884 | .fattr = fattr, |
| 1885 | .server = server, |
| 1886 | }; |
| 1887 | struct rpc_message msg = { |
| 1888 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 1889 | .rpc_argp = &args, |
| 1890 | .rpc_resp = &res, |
| 1891 | }; |
| 1892 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1893 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1894 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 1898 | { |
| 1899 | struct nfs4_exception exception = { }; |
| 1900 | int err; |
| 1901 | do { |
| 1902 | err = nfs4_handle_exception(server, |
| 1903 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 1904 | &exception); |
| 1905 | } while (exception.retry); |
| 1906 | return err; |
| 1907 | } |
| 1908 | |
| 1909 | /* |
| 1910 | * The file is not closed if it is opened due to the a request to change |
| 1911 | * the size of the file. The open call will not be needed once the |
| 1912 | * VFS layer lookup-intents are implemented. |
| 1913 | * |
| 1914 | * Close is called when the inode is destroyed. |
| 1915 | * If we haven't opened the file for O_WRONLY, we |
| 1916 | * need to in the size_change case to obtain a stateid. |
| 1917 | * |
| 1918 | * Got race? |
| 1919 | * Because OPEN is always done by name in nfsv4, it is |
| 1920 | * possible that we opened a different file by the same |
| 1921 | * name. We can recognize this race condition, but we |
| 1922 | * can't do anything about it besides returning an error. |
| 1923 | * |
| 1924 | * This will be fixed with VFS changes (lookup-intent). |
| 1925 | */ |
| 1926 | static int |
| 1927 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 1928 | struct iattr *sattr) |
| 1929 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1930 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1931 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 1932 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | int status; |
| 1934 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1935 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 1937 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1938 | if (sattr->ia_valid & ATTR_FILE) { |
| 1939 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1940 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1941 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 1942 | if (ctx) { |
| 1943 | cred = ctx->cred; |
| 1944 | state = ctx->state; |
| 1945 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1949 | if (status == 0) |
| 1950 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | return status; |
| 1952 | } |
| 1953 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 1954 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 1955 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1956 | struct nfs_fattr *fattr) |
| 1957 | { |
| 1958 | int status; |
| 1959 | struct nfs4_lookup_arg args = { |
| 1960 | .bitmask = server->attr_bitmask, |
| 1961 | .dir_fh = dirfh, |
| 1962 | .name = name, |
| 1963 | }; |
| 1964 | struct nfs4_lookup_res res = { |
| 1965 | .server = server, |
| 1966 | .fattr = fattr, |
| 1967 | .fh = fhandle, |
| 1968 | }; |
| 1969 | struct rpc_message msg = { |
| 1970 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 1971 | .rpc_argp = &args, |
| 1972 | .rpc_resp = &res, |
| 1973 | }; |
| 1974 | |
| 1975 | nfs_fattr_init(fattr); |
| 1976 | |
| 1977 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1978 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1979 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1980 | return status; |
| 1981 | } |
| 1982 | |
| 1983 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 1984 | struct qstr *name, struct nfs_fh *fhandle, |
| 1985 | struct nfs_fattr *fattr) |
| 1986 | { |
| 1987 | struct nfs4_exception exception = { }; |
| 1988 | int err; |
| 1989 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 1990 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 1991 | /* FIXME: !!!! */ |
| 1992 | if (err == -NFS4ERR_MOVED) { |
| 1993 | err = -EREMOTE; |
| 1994 | break; |
| 1995 | } |
| 1996 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1997 | } while (exception.retry); |
| 1998 | return err; |
| 1999 | } |
| 2000 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2001 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2003 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2004 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
| 2006 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2007 | status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2008 | if (status == -NFS4ERR_MOVED) |
| 2009 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | dprintk("NFS reply lookup: %d\n", status); |
| 2011 | return status; |
| 2012 | } |
| 2013 | |
| 2014 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2015 | { |
| 2016 | struct nfs4_exception exception = { }; |
| 2017 | int err; |
| 2018 | do { |
| 2019 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2020 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2021 | &exception); |
| 2022 | } while (exception.retry); |
| 2023 | return err; |
| 2024 | } |
| 2025 | |
| 2026 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2027 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2028 | struct nfs_server *server = NFS_SERVER(inode); |
| 2029 | struct nfs_fattr fattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | struct nfs4_accessargs args = { |
| 2031 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2032 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2034 | struct nfs4_accessres res = { |
| 2035 | .server = server, |
| 2036 | .fattr = &fattr, |
| 2037 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | struct rpc_message msg = { |
| 2039 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2040 | .rpc_argp = &args, |
| 2041 | .rpc_resp = &res, |
| 2042 | .rpc_cred = entry->cred, |
| 2043 | }; |
| 2044 | int mode = entry->mask; |
| 2045 | int status; |
| 2046 | |
| 2047 | /* |
| 2048 | * Determine which access bits we want to ask for... |
| 2049 | */ |
| 2050 | if (mode & MAY_READ) |
| 2051 | args.access |= NFS4_ACCESS_READ; |
| 2052 | if (S_ISDIR(inode->i_mode)) { |
| 2053 | if (mode & MAY_WRITE) |
| 2054 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2055 | if (mode & MAY_EXEC) |
| 2056 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2057 | } else { |
| 2058 | if (mode & MAY_WRITE) |
| 2059 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2060 | if (mode & MAY_EXEC) |
| 2061 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2062 | } |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2063 | nfs_fattr_init(&fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2064 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | if (!status) { |
| 2066 | entry->mask = 0; |
| 2067 | if (res.access & NFS4_ACCESS_READ) |
| 2068 | entry->mask |= MAY_READ; |
| 2069 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2070 | entry->mask |= MAY_WRITE; |
| 2071 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2072 | entry->mask |= MAY_EXEC; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2073 | nfs_refresh_inode(inode, &fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | } |
| 2075 | return status; |
| 2076 | } |
| 2077 | |
| 2078 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2079 | { |
| 2080 | struct nfs4_exception exception = { }; |
| 2081 | int err; |
| 2082 | do { |
| 2083 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2084 | _nfs4_proc_access(inode, entry), |
| 2085 | &exception); |
| 2086 | } while (exception.retry); |
| 2087 | return err; |
| 2088 | } |
| 2089 | |
| 2090 | /* |
| 2091 | * TODO: For the time being, we don't try to get any attributes |
| 2092 | * along with any of the zero-copy operations READ, READDIR, |
| 2093 | * READLINK, WRITE. |
| 2094 | * |
| 2095 | * In the case of the first three, we want to put the GETATTR |
| 2096 | * after the read-type operation -- this is because it is hard |
| 2097 | * to predict the length of a GETATTR response in v4, and thus |
| 2098 | * align the READ data correctly. This means that the GETATTR |
| 2099 | * may end up partially falling into the page cache, and we should |
| 2100 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2101 | * To do this efficiently, we need to know the total length |
| 2102 | * of data received, which doesn't seem to be available outside |
| 2103 | * of the RPC layer. |
| 2104 | * |
| 2105 | * In the case of WRITE, we also want to put the GETATTR after |
| 2106 | * the operation -- in this case because we want to make sure |
| 2107 | * we get the post-operation mtime and size. This means that |
| 2108 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2109 | * of it which would leave room in the 'tail' iovec. |
| 2110 | * |
| 2111 | * Both of these changes to the XDR layer would in fact be quite |
| 2112 | * minor, but I decided to leave them for a subsequent patch. |
| 2113 | */ |
| 2114 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2115 | unsigned int pgbase, unsigned int pglen) |
| 2116 | { |
| 2117 | struct nfs4_readlink args = { |
| 2118 | .fh = NFS_FH(inode), |
| 2119 | .pgbase = pgbase, |
| 2120 | .pglen = pglen, |
| 2121 | .pages = &page, |
| 2122 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2123 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | struct rpc_message msg = { |
| 2125 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2126 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2127 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | }; |
| 2129 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2130 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2134 | unsigned int pgbase, unsigned int pglen) |
| 2135 | { |
| 2136 | struct nfs4_exception exception = { }; |
| 2137 | int err; |
| 2138 | do { |
| 2139 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2140 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2141 | &exception); |
| 2142 | } while (exception.retry); |
| 2143 | return err; |
| 2144 | } |
| 2145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | /* |
| 2147 | * Got race? |
| 2148 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2149 | * Until then, this create/open method is prone to inefficiency and race |
| 2150 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2151 | * placed on the wire. |
| 2152 | * |
| 2153 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2154 | * The file will be opened again in the subsequent VFS open call |
| 2155 | * (nfs4_proc_file_open). |
| 2156 | * |
| 2157 | * The open for read will just hang around to be used by any process that |
| 2158 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2159 | */ |
| 2160 | |
| 2161 | static int |
| 2162 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2163 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2165 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2166 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2167 | .dentry = dentry, |
| 2168 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | struct nfs4_state *state; |
| 2170 | struct rpc_cred *cred; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2171 | fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | int status = 0; |
| 2173 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2174 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | if (IS_ERR(cred)) { |
| 2176 | status = PTR_ERR(cred); |
| 2177 | goto out; |
| 2178 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2179 | state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2180 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | if (IS_ERR(state)) { |
| 2182 | status = PTR_ERR(state); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2183 | goto out_putcred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2185 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2186 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | if (flags & O_EXCL) { |
| 2188 | struct nfs_fattr fattr; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2189 | status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2190 | if (status == 0) |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2191 | nfs_setattr_update_inode(state->inode, sattr); |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2192 | nfs_post_op_update_inode(state->inode, &fattr); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2193 | } |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2194 | if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2195 | status = nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2196 | else |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2197 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2198 | out_putcred: |
| 2199 | put_rpccred(cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | out: |
| 2201 | return status; |
| 2202 | } |
| 2203 | |
| 2204 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2205 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2206 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2207 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2209 | .name.len = name->len, |
| 2210 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2211 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2213 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2214 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2215 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2217 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2218 | .rpc_argp = &args, |
| 2219 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | }; |
| 2221 | int status; |
| 2222 | |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2223 | nfs_fattr_init(&res.dir_attr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2224 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2225 | if (status == 0) { |
| 2226 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2227 | nfs_post_op_update_inode(dir, &res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | return status; |
| 2230 | } |
| 2231 | |
| 2232 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2233 | { |
| 2234 | struct nfs4_exception exception = { }; |
| 2235 | int err; |
| 2236 | do { |
| 2237 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2238 | _nfs4_proc_remove(dir, name), |
| 2239 | &exception); |
| 2240 | } while (exception.retry); |
| 2241 | return err; |
| 2242 | } |
| 2243 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2244 | 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] | 2245 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2246 | struct nfs_server *server = NFS_SERVER(dir); |
| 2247 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2248 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2250 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2251 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2255 | 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] | 2256 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2257 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2258 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2259 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2260 | return 0; |
| 2261 | update_changeattr(dir, &res->cinfo); |
| 2262 | nfs_post_op_update_inode(dir, &res->dir_attr); |
| 2263 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2267 | struct inode *new_dir, struct qstr *new_name) |
| 2268 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2269 | struct nfs_server *server = NFS_SERVER(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | struct nfs4_rename_arg arg = { |
| 2271 | .old_dir = NFS_FH(old_dir), |
| 2272 | .new_dir = NFS_FH(new_dir), |
| 2273 | .old_name = old_name, |
| 2274 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2275 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | }; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2277 | struct nfs_fattr old_fattr, new_fattr; |
| 2278 | struct nfs4_rename_res res = { |
| 2279 | .server = server, |
| 2280 | .old_fattr = &old_fattr, |
| 2281 | .new_fattr = &new_fattr, |
| 2282 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | struct rpc_message msg = { |
| 2284 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2285 | .rpc_argp = &arg, |
| 2286 | .rpc_resp = &res, |
| 2287 | }; |
| 2288 | int status; |
| 2289 | |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2290 | nfs_fattr_init(res.old_fattr); |
| 2291 | nfs_fattr_init(res.new_fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2292 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
| 2294 | if (!status) { |
| 2295 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2296 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2298 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | } |
| 2300 | return status; |
| 2301 | } |
| 2302 | |
| 2303 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2304 | struct inode *new_dir, struct qstr *new_name) |
| 2305 | { |
| 2306 | struct nfs4_exception exception = { }; |
| 2307 | int err; |
| 2308 | do { |
| 2309 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2310 | _nfs4_proc_rename(old_dir, old_name, |
| 2311 | new_dir, new_name), |
| 2312 | &exception); |
| 2313 | } while (exception.retry); |
| 2314 | return err; |
| 2315 | } |
| 2316 | |
| 2317 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2318 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2319 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | struct nfs4_link_arg arg = { |
| 2321 | .fh = NFS_FH(inode), |
| 2322 | .dir_fh = NFS_FH(dir), |
| 2323 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2324 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2326 | struct nfs_fattr fattr, dir_attr; |
| 2327 | struct nfs4_link_res res = { |
| 2328 | .server = server, |
| 2329 | .fattr = &fattr, |
| 2330 | .dir_attr = &dir_attr, |
| 2331 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | struct rpc_message msg = { |
| 2333 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2334 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2335 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | }; |
| 2337 | int status; |
| 2338 | |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2339 | nfs_fattr_init(res.fattr); |
| 2340 | nfs_fattr_init(res.dir_attr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2341 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2342 | if (!status) { |
| 2343 | update_changeattr(dir, &res.cinfo); |
| 2344 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2345 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | |
| 2348 | return status; |
| 2349 | } |
| 2350 | |
| 2351 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2352 | { |
| 2353 | struct nfs4_exception exception = { }; |
| 2354 | int err; |
| 2355 | do { |
| 2356 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2357 | _nfs4_proc_link(inode, dir, name), |
| 2358 | &exception); |
| 2359 | } while (exception.retry); |
| 2360 | return err; |
| 2361 | } |
| 2362 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2363 | struct nfs4_createdata { |
| 2364 | struct rpc_message msg; |
| 2365 | struct nfs4_create_arg arg; |
| 2366 | struct nfs4_create_res res; |
| 2367 | struct nfs_fh fh; |
| 2368 | struct nfs_fattr fattr; |
| 2369 | struct nfs_fattr dir_fattr; |
| 2370 | }; |
| 2371 | |
| 2372 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2373 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2374 | { |
| 2375 | struct nfs4_createdata *data; |
| 2376 | |
| 2377 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2378 | if (data != NULL) { |
| 2379 | struct nfs_server *server = NFS_SERVER(dir); |
| 2380 | |
| 2381 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2382 | data->msg.rpc_argp = &data->arg; |
| 2383 | data->msg.rpc_resp = &data->res; |
| 2384 | data->arg.dir_fh = NFS_FH(dir); |
| 2385 | data->arg.server = server; |
| 2386 | data->arg.name = name; |
| 2387 | data->arg.attrs = sattr; |
| 2388 | data->arg.ftype = ftype; |
| 2389 | data->arg.bitmask = server->attr_bitmask; |
| 2390 | data->res.server = server; |
| 2391 | data->res.fh = &data->fh; |
| 2392 | data->res.fattr = &data->fattr; |
| 2393 | data->res.dir_fattr = &data->dir_fattr; |
| 2394 | nfs_fattr_init(data->res.fattr); |
| 2395 | nfs_fattr_init(data->res.dir_fattr); |
| 2396 | } |
| 2397 | return data; |
| 2398 | } |
| 2399 | |
| 2400 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2401 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2402 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2403 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2404 | if (status == 0) { |
| 2405 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2406 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2407 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2408 | } |
| 2409 | return status; |
| 2410 | } |
| 2411 | |
| 2412 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2413 | { |
| 2414 | kfree(data); |
| 2415 | } |
| 2416 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2417 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2418 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2420 | struct nfs4_createdata *data; |
| 2421 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2423 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2424 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2425 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2426 | status = -ENOMEM; |
| 2427 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2428 | if (data == NULL) |
| 2429 | goto out; |
| 2430 | |
| 2431 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2432 | data->arg.u.symlink.pages = &page; |
| 2433 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2435 | status = nfs4_do_create(dir, dentry, data); |
| 2436 | |
| 2437 | nfs4_free_createdata(data); |
| 2438 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | return status; |
| 2440 | } |
| 2441 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2442 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2443 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | { |
| 2445 | struct nfs4_exception exception = { }; |
| 2446 | int err; |
| 2447 | do { |
| 2448 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2449 | _nfs4_proc_symlink(dir, dentry, page, |
| 2450 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | &exception); |
| 2452 | } while (exception.retry); |
| 2453 | return err; |
| 2454 | } |
| 2455 | |
| 2456 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2457 | struct iattr *sattr) |
| 2458 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2459 | struct nfs4_createdata *data; |
| 2460 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2462 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2463 | if (data == NULL) |
| 2464 | goto out; |
| 2465 | |
| 2466 | status = nfs4_do_create(dir, dentry, data); |
| 2467 | |
| 2468 | nfs4_free_createdata(data); |
| 2469 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | return status; |
| 2471 | } |
| 2472 | |
| 2473 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2474 | struct iattr *sattr) |
| 2475 | { |
| 2476 | struct nfs4_exception exception = { }; |
| 2477 | int err; |
| 2478 | do { |
| 2479 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2480 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2481 | &exception); |
| 2482 | } while (exception.retry); |
| 2483 | return err; |
| 2484 | } |
| 2485 | |
| 2486 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2487 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2488 | { |
| 2489 | struct inode *dir = dentry->d_inode; |
| 2490 | struct nfs4_readdir_arg args = { |
| 2491 | .fh = NFS_FH(dir), |
| 2492 | .pages = &page, |
| 2493 | .pgbase = 0, |
| 2494 | .count = count, |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2495 | .bitmask = NFS_SERVER(dentry->d_inode)->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | }; |
| 2497 | struct nfs4_readdir_res res; |
| 2498 | struct rpc_message msg = { |
| 2499 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2500 | .rpc_argp = &args, |
| 2501 | .rpc_resp = &res, |
| 2502 | .rpc_cred = cred, |
| 2503 | }; |
| 2504 | int status; |
| 2505 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2506 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2507 | dentry->d_parent->d_name.name, |
| 2508 | dentry->d_name.name, |
| 2509 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2511 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2512 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | if (status == 0) |
| 2514 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2515 | |
| 2516 | nfs_invalidate_atime(dir); |
| 2517 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2518 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | return status; |
| 2520 | } |
| 2521 | |
| 2522 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2523 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2524 | { |
| 2525 | struct nfs4_exception exception = { }; |
| 2526 | int err; |
| 2527 | do { |
| 2528 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2529 | _nfs4_proc_readdir(dentry, cred, cookie, |
| 2530 | page, count, plus), |
| 2531 | &exception); |
| 2532 | } while (exception.retry); |
| 2533 | return err; |
| 2534 | } |
| 2535 | |
| 2536 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2537 | struct iattr *sattr, dev_t rdev) |
| 2538 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2539 | struct nfs4_createdata *data; |
| 2540 | int mode = sattr->ia_mode; |
| 2541 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
| 2543 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2544 | 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] | 2545 | |
| 2546 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2547 | if (data == NULL) |
| 2548 | goto out; |
| 2549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2551 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2553 | data->arg.ftype = NF4BLK; |
| 2554 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2555 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | } |
| 2557 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2558 | data->arg.ftype = NF4CHR; |
| 2559 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2560 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2563 | status = nfs4_do_create(dir, dentry, data); |
| 2564 | |
| 2565 | nfs4_free_createdata(data); |
| 2566 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | return status; |
| 2568 | } |
| 2569 | |
| 2570 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2571 | struct iattr *sattr, dev_t rdev) |
| 2572 | { |
| 2573 | struct nfs4_exception exception = { }; |
| 2574 | int err; |
| 2575 | do { |
| 2576 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2577 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2578 | &exception); |
| 2579 | } while (exception.retry); |
| 2580 | return err; |
| 2581 | } |
| 2582 | |
| 2583 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2584 | struct nfs_fsstat *fsstat) |
| 2585 | { |
| 2586 | struct nfs4_statfs_arg args = { |
| 2587 | .fh = fhandle, |
| 2588 | .bitmask = server->attr_bitmask, |
| 2589 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2590 | struct nfs4_statfs_res res = { |
| 2591 | .fsstat = fsstat, |
| 2592 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | struct rpc_message msg = { |
| 2594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2595 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2596 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | }; |
| 2598 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2599 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2600 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2604 | { |
| 2605 | struct nfs4_exception exception = { }; |
| 2606 | int err; |
| 2607 | do { |
| 2608 | err = nfs4_handle_exception(server, |
| 2609 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2610 | &exception); |
| 2611 | } while (exception.retry); |
| 2612 | return err; |
| 2613 | } |
| 2614 | |
| 2615 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2616 | struct nfs_fsinfo *fsinfo) |
| 2617 | { |
| 2618 | struct nfs4_fsinfo_arg args = { |
| 2619 | .fh = fhandle, |
| 2620 | .bitmask = server->attr_bitmask, |
| 2621 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2622 | struct nfs4_fsinfo_res res = { |
| 2623 | .fsinfo = fsinfo, |
| 2624 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | struct rpc_message msg = { |
| 2626 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 2627 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2628 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | }; |
| 2630 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2631 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 2635 | { |
| 2636 | struct nfs4_exception exception = { }; |
| 2637 | int err; |
| 2638 | |
| 2639 | do { |
| 2640 | err = nfs4_handle_exception(server, |
| 2641 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 2642 | &exception); |
| 2643 | } while (exception.retry); |
| 2644 | return err; |
| 2645 | } |
| 2646 | |
| 2647 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 2648 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2649 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 2651 | } |
| 2652 | |
| 2653 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2654 | struct nfs_pathconf *pathconf) |
| 2655 | { |
| 2656 | struct nfs4_pathconf_arg args = { |
| 2657 | .fh = fhandle, |
| 2658 | .bitmask = server->attr_bitmask, |
| 2659 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 2660 | struct nfs4_pathconf_res res = { |
| 2661 | .pathconf = pathconf, |
| 2662 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | struct rpc_message msg = { |
| 2664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 2665 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 2666 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | }; |
| 2668 | |
| 2669 | /* None of the pathconf attributes are mandatory to implement */ |
| 2670 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 2671 | memset(pathconf, 0, sizeof(*pathconf)); |
| 2672 | return 0; |
| 2673 | } |
| 2674 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2675 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2676 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2680 | struct nfs_pathconf *pathconf) |
| 2681 | { |
| 2682 | struct nfs4_exception exception = { }; |
| 2683 | int err; |
| 2684 | |
| 2685 | do { |
| 2686 | err = nfs4_handle_exception(server, |
| 2687 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 2688 | &exception); |
| 2689 | } while (exception.retry); |
| 2690 | return err; |
| 2691 | } |
| 2692 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2693 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2695 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2697 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | rpc_restart_call(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2699 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 2701 | |
| 2702 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2704 | renew_lease(server, data->timestamp); |
| 2705 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2708 | 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] | 2709 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2711 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2714 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | struct inode *inode = data->inode; |
| 2717 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2718 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | rpc_restart_call(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2720 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2722 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 2724 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2725 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2726 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2729 | 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] | 2730 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2731 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 2732 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2733 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2734 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | data->timestamp = jiffies; |
| 2736 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2737 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2740 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | struct inode *inode = data->inode; |
| 2743 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2744 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | rpc_restart_call(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2746 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 2748 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2749 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2752 | 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] | 2753 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 2754 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2756 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2757 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 2758 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | /* |
| 2762 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 2763 | * standalone procedure for queueing an asynchronous RENEW. |
| 2764 | */ |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2765 | static void nfs4_renew_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | { |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 2767 | struct nfs_client *clp = (struct nfs_client *)task->tk_msg.rpc_argp; |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2768 | unsigned long timestamp = (unsigned long)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
| 2770 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 2771 | /* Unless we're shutting down, schedule state recovery! */ |
| 2772 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 2773 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | return; |
| 2775 | } |
| 2776 | spin_lock(&clp->cl_lock); |
| 2777 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 2778 | clp->cl_last_renewal = timestamp; |
| 2779 | spin_unlock(&clp->cl_lock); |
| 2780 | } |
| 2781 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2782 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 2783 | .rpc_call_done = nfs4_renew_done, |
| 2784 | }; |
| 2785 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 2786 | int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | { |
| 2788 | struct rpc_message msg = { |
| 2789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 2790 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2791 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | }; |
| 2793 | |
| 2794 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2795 | &nfs4_renew_ops, (void *)jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 2798 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | { |
| 2800 | struct rpc_message msg = { |
| 2801 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 2802 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2803 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | }; |
| 2805 | unsigned long now = jiffies; |
| 2806 | int status; |
| 2807 | |
| 2808 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 2809 | if (status < 0) |
| 2810 | return status; |
| 2811 | spin_lock(&clp->cl_lock); |
| 2812 | if (time_before(clp->cl_last_renewal,now)) |
| 2813 | clp->cl_last_renewal = now; |
| 2814 | spin_unlock(&clp->cl_lock); |
| 2815 | return 0; |
| 2816 | } |
| 2817 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2818 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 2819 | { |
| 2820 | return (server->caps & NFS_CAP_ACLS) |
| 2821 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 2822 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 2823 | } |
| 2824 | |
| 2825 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 2826 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 2827 | * the stack. |
| 2828 | */ |
| 2829 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 2830 | |
| 2831 | static void buf_to_pages(const void *buf, size_t buflen, |
| 2832 | struct page **pages, unsigned int *pgbase) |
| 2833 | { |
| 2834 | const void *p = buf; |
| 2835 | |
| 2836 | *pgbase = offset_in_page(buf); |
| 2837 | p -= *pgbase; |
| 2838 | while (p < buf + buflen) { |
| 2839 | *(pages++) = virt_to_page(p); |
| 2840 | p += PAGE_CACHE_SIZE; |
| 2841 | } |
| 2842 | } |
| 2843 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2844 | struct nfs4_cached_acl { |
| 2845 | int cached; |
| 2846 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 2847 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2848 | }; |
| 2849 | |
| 2850 | 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] | 2851 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2852 | struct nfs_inode *nfsi = NFS_I(inode); |
| 2853 | |
| 2854 | spin_lock(&inode->i_lock); |
| 2855 | kfree(nfsi->nfs4_acl); |
| 2856 | nfsi->nfs4_acl = acl; |
| 2857 | spin_unlock(&inode->i_lock); |
| 2858 | } |
| 2859 | |
| 2860 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 2861 | { |
| 2862 | nfs4_set_cached_acl(inode, NULL); |
| 2863 | } |
| 2864 | |
| 2865 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 2866 | { |
| 2867 | struct nfs_inode *nfsi = NFS_I(inode); |
| 2868 | struct nfs4_cached_acl *acl; |
| 2869 | int ret = -ENOENT; |
| 2870 | |
| 2871 | spin_lock(&inode->i_lock); |
| 2872 | acl = nfsi->nfs4_acl; |
| 2873 | if (acl == NULL) |
| 2874 | goto out; |
| 2875 | if (buf == NULL) /* user is just asking for length */ |
| 2876 | goto out_len; |
| 2877 | if (acl->cached == 0) |
| 2878 | goto out; |
| 2879 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 2880 | if (acl->len > buflen) |
| 2881 | goto out; |
| 2882 | memcpy(buf, acl->data, acl->len); |
| 2883 | out_len: |
| 2884 | ret = acl->len; |
| 2885 | out: |
| 2886 | spin_unlock(&inode->i_lock); |
| 2887 | return ret; |
| 2888 | } |
| 2889 | |
| 2890 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 2891 | { |
| 2892 | struct nfs4_cached_acl *acl; |
| 2893 | |
| 2894 | if (buf && acl_len <= PAGE_SIZE) { |
| 2895 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 2896 | if (acl == NULL) |
| 2897 | goto out; |
| 2898 | acl->cached = 1; |
| 2899 | memcpy(acl->data, buf, acl_len); |
| 2900 | } else { |
| 2901 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 2902 | if (acl == NULL) |
| 2903 | goto out; |
| 2904 | acl->cached = 0; |
| 2905 | } |
| 2906 | acl->len = acl_len; |
| 2907 | out: |
| 2908 | nfs4_set_cached_acl(inode, acl); |
| 2909 | } |
| 2910 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 2911 | 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] | 2912 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2913 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 2914 | struct nfs_getaclargs args = { |
| 2915 | .fh = NFS_FH(inode), |
| 2916 | .acl_pages = pages, |
| 2917 | .acl_len = buflen, |
| 2918 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2919 | struct nfs_getaclres res = { |
| 2920 | .acl_len = buflen, |
| 2921 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2922 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2923 | struct rpc_message msg = { |
| 2924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 2925 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2926 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2927 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2928 | struct page *localpage = NULL; |
| 2929 | int ret; |
| 2930 | |
| 2931 | if (buflen < PAGE_SIZE) { |
| 2932 | /* As long as we're doing a round trip to the server anyway, |
| 2933 | * let's be prepared for a page of acl data. */ |
| 2934 | localpage = alloc_page(GFP_KERNEL); |
| 2935 | resp_buf = page_address(localpage); |
| 2936 | if (localpage == NULL) |
| 2937 | return -ENOMEM; |
| 2938 | args.acl_pages[0] = localpage; |
| 2939 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2940 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2941 | } else { |
| 2942 | resp_buf = buf; |
| 2943 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 2944 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2945 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2946 | if (ret) |
| 2947 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2948 | if (res.acl_len > args.acl_len) |
| 2949 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2950 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2951 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2952 | if (buf) { |
| 2953 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2954 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2955 | goto out_free; |
| 2956 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2957 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2958 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 2959 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2960 | out_free: |
| 2961 | if (localpage) |
| 2962 | __free_page(localpage); |
| 2963 | return ret; |
| 2964 | } |
| 2965 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 2966 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 2967 | { |
| 2968 | struct nfs4_exception exception = { }; |
| 2969 | ssize_t ret; |
| 2970 | do { |
| 2971 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 2972 | if (ret >= 0) |
| 2973 | break; |
| 2974 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 2975 | } while (exception.retry); |
| 2976 | return ret; |
| 2977 | } |
| 2978 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2979 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 2980 | { |
| 2981 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2982 | int ret; |
| 2983 | |
| 2984 | if (!nfs4_server_supports_acls(server)) |
| 2985 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2986 | ret = nfs_revalidate_inode(server, inode); |
| 2987 | if (ret < 0) |
| 2988 | return ret; |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 2989 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 2990 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 2991 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 2992 | if (ret != -ENOENT) |
| 2993 | return ret; |
| 2994 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 2995 | } |
| 2996 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 2997 | 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] | 2998 | { |
| 2999 | struct nfs_server *server = NFS_SERVER(inode); |
| 3000 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3001 | struct nfs_setaclargs arg = { |
| 3002 | .fh = NFS_FH(inode), |
| 3003 | .acl_pages = pages, |
| 3004 | .acl_len = buflen, |
| 3005 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3006 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3007 | struct rpc_message msg = { |
| 3008 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3009 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3010 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3011 | }; |
| 3012 | int ret; |
| 3013 | |
| 3014 | if (!nfs4_server_supports_acls(server)) |
| 3015 | return -EOPNOTSUPP; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3016 | nfs_inode_return_delegation(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3017 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3018 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3019 | nfs_access_zap_cache(inode); |
| 3020 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3021 | return ret; |
| 3022 | } |
| 3023 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3024 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3025 | { |
| 3026 | struct nfs4_exception exception = { }; |
| 3027 | int err; |
| 3028 | do { |
| 3029 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3030 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3031 | &exception); |
| 3032 | } while (exception.retry); |
| 3033 | return err; |
| 3034 | } |
| 3035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | static int |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3037 | 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] | 3038 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3039 | struct nfs_client *clp = server->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | |
| 3041 | if (!clp || task->tk_status >= 0) |
| 3042 | return 0; |
| 3043 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3044 | case -NFS4ERR_ADMIN_REVOKED: |
| 3045 | case -NFS4ERR_BAD_STATEID: |
| 3046 | case -NFS4ERR_OPENMODE: |
| 3047 | if (state == NULL) |
| 3048 | break; |
| 3049 | nfs4_state_mark_reclaim_nograce(clp, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | case -NFS4ERR_STALE_CLIENTID: |
| 3051 | case -NFS4ERR_STALE_STATEID: |
| 3052 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 3053 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 3055 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 3056 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | task->tk_status = 0; |
| 3058 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2e96d28 | 2008-06-11 16:42:05 -0400 | [diff] [blame] | 3060 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3061 | case -NFS4ERR_GRACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3063 | task->tk_status = 0; |
| 3064 | return -EAGAIN; |
| 3065 | case -NFS4ERR_OLD_STATEID: |
| 3066 | task->tk_status = 0; |
| 3067 | return -EAGAIN; |
| 3068 | } |
| 3069 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3070 | return 0; |
| 3071 | } |
| 3072 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3073 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | { |
| 3075 | nfs4_verifier sc_verifier; |
| 3076 | struct nfs4_setclientid setclientid = { |
| 3077 | .sc_verifier = &sc_verifier, |
| 3078 | .sc_prog = program, |
| 3079 | }; |
| 3080 | struct rpc_message msg = { |
| 3081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3082 | .rpc_argp = &setclientid, |
| 3083 | .rpc_resp = clp, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3084 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3086 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | int loop = 0; |
| 3088 | int status; |
| 3089 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3090 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3092 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3093 | |
| 3094 | for(;;) { |
| 3095 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3096 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3097 | clp->cl_ipaddr, |
| 3098 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3099 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3100 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3101 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3102 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | clp->cl_id_uniquifier); |
| 3104 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3105 | sizeof(setclientid.sc_netid), |
| 3106 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3107 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3109 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3111 | |
| 3112 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3113 | if (status != -NFS4ERR_CLID_INUSE) |
| 3114 | break; |
| 3115 | if (signalled()) |
| 3116 | break; |
| 3117 | if (loop++ & 1) |
| 3118 | ssleep(clp->cl_lease_time + 1); |
| 3119 | else |
| 3120 | if (++clp->cl_id_uniquifier == 0) |
| 3121 | break; |
| 3122 | } |
| 3123 | return status; |
| 3124 | } |
| 3125 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3126 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | { |
| 3128 | struct nfs_fsinfo fsinfo; |
| 3129 | struct rpc_message msg = { |
| 3130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
| 3131 | .rpc_argp = clp, |
| 3132 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3133 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | }; |
| 3135 | unsigned long now; |
| 3136 | int status; |
| 3137 | |
| 3138 | now = jiffies; |
| 3139 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3140 | if (status == 0) { |
| 3141 | spin_lock(&clp->cl_lock); |
| 3142 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3143 | clp->cl_last_renewal = now; |
| 3144 | spin_unlock(&clp->cl_lock); |
| 3145 | } |
| 3146 | return status; |
| 3147 | } |
| 3148 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3149 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3150 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3151 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3152 | int err; |
| 3153 | do { |
| 3154 | err = _nfs4_proc_setclientid_confirm(clp, cred); |
| 3155 | switch (err) { |
| 3156 | case 0: |
| 3157 | return err; |
| 3158 | case -NFS4ERR_RESOURCE: |
| 3159 | /* The IBM lawyers misread another document! */ |
| 3160 | case -NFS4ERR_DELAY: |
| 3161 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3162 | } |
| 3163 | } while (err == 0); |
| 3164 | return err; |
| 3165 | } |
| 3166 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3167 | struct nfs4_delegreturndata { |
| 3168 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3169 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3170 | struct nfs_fh fh; |
| 3171 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3172 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3173 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3174 | int rpc_status; |
| 3175 | }; |
| 3176 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3177 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3178 | { |
| 3179 | struct nfs4_delegreturndata *data = calldata; |
| 3180 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3181 | if (data->rpc_status == 0) |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3182 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | static void nfs4_delegreturn_release(void *calldata) |
| 3186 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3187 | kfree(calldata); |
| 3188 | } |
| 3189 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3190 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3191 | .rpc_call_done = nfs4_delegreturn_done, |
| 3192 | .rpc_release = nfs4_delegreturn_release, |
| 3193 | }; |
| 3194 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3195 | 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] | 3196 | { |
| 3197 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3198 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3199 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3200 | struct rpc_message msg = { |
| 3201 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3202 | .rpc_cred = cred, |
| 3203 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3204 | struct rpc_task_setup task_setup_data = { |
| 3205 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3206 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3207 | .callback_ops = &nfs4_delegreturn_ops, |
| 3208 | .flags = RPC_TASK_ASYNC, |
| 3209 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3210 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3211 | |
| 3212 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3213 | if (data == NULL) |
| 3214 | return -ENOMEM; |
| 3215 | data->args.fhandle = &data->fh; |
| 3216 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3217 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3218 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3219 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3220 | data->res.fattr = &data->fattr; |
| 3221 | data->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3222 | data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3223 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3224 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3225 | data->rpc_status = 0; |
| 3226 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3227 | task_setup_data.callback_data = data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3228 | msg.rpc_argp = &data->args, |
| 3229 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3230 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3231 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3232 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3233 | if (!issync) |
| 3234 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3235 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3236 | if (status != 0) |
| 3237 | goto out; |
| 3238 | status = data->rpc_status; |
| 3239 | if (status != 0) |
| 3240 | goto out; |
| 3241 | nfs_refresh_inode(inode, &data->fattr); |
| 3242 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3243 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3244 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3247 | 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] | 3248 | { |
| 3249 | struct nfs_server *server = NFS_SERVER(inode); |
| 3250 | struct nfs4_exception exception = { }; |
| 3251 | int err; |
| 3252 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3253 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | switch (err) { |
| 3255 | case -NFS4ERR_STALE_STATEID: |
| 3256 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | case 0: |
| 3258 | return 0; |
| 3259 | } |
| 3260 | err = nfs4_handle_exception(server, err, &exception); |
| 3261 | } while (exception.retry); |
| 3262 | return err; |
| 3263 | } |
| 3264 | |
| 3265 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3266 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3267 | |
| 3268 | /* |
| 3269 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3270 | */ |
| 3271 | static unsigned long |
| 3272 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3273 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3274 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | timeout <<= 1; |
| 3276 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3277 | return NFS4_LOCK_MAXTIMEOUT; |
| 3278 | return timeout; |
| 3279 | } |
| 3280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3282 | { |
| 3283 | struct inode *inode = state->inode; |
| 3284 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3285 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3286 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3288 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3290 | struct nfs_lockt_res res = { |
| 3291 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | }; |
| 3293 | struct rpc_message msg = { |
| 3294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3295 | .rpc_argp = &arg, |
| 3296 | .rpc_resp = &res, |
| 3297 | .rpc_cred = state->owner->so_cred, |
| 3298 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | struct nfs4_lock_state *lsp; |
| 3300 | int status; |
| 3301 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3302 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3303 | status = nfs4_set_lock_state(state, request); |
| 3304 | if (status != 0) |
| 3305 | goto out; |
| 3306 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3307 | arg.lock_owner.id = lsp->ls_id.id; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3308 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3309 | switch (status) { |
| 3310 | case 0: |
| 3311 | request->fl_type = F_UNLCK; |
| 3312 | break; |
| 3313 | case -NFS4ERR_DENIED: |
| 3314 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3316 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3317 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | return status; |
| 3319 | } |
| 3320 | |
| 3321 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3322 | { |
| 3323 | struct nfs4_exception exception = { }; |
| 3324 | int err; |
| 3325 | |
| 3326 | do { |
| 3327 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3328 | _nfs4_proc_getlk(state, cmd, request), |
| 3329 | &exception); |
| 3330 | } while (exception.retry); |
| 3331 | return err; |
| 3332 | } |
| 3333 | |
| 3334 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3335 | { |
| 3336 | int res = 0; |
| 3337 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3338 | case FL_POSIX: |
| 3339 | res = posix_lock_file_wait(file, fl); |
| 3340 | break; |
| 3341 | case FL_FLOCK: |
| 3342 | res = flock_lock_file_wait(file, fl); |
| 3343 | break; |
| 3344 | default: |
| 3345 | BUG(); |
| 3346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | return res; |
| 3348 | } |
| 3349 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3350 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3351 | struct nfs_locku_args arg; |
| 3352 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3353 | struct nfs4_lock_state *lsp; |
| 3354 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3355 | struct file_lock fl; |
| 3356 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3357 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3358 | }; |
| 3359 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3360 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3361 | struct nfs_open_context *ctx, |
| 3362 | struct nfs4_lock_state *lsp, |
| 3363 | struct nfs_seqid *seqid) |
| 3364 | { |
| 3365 | struct nfs4_unlockdata *p; |
| 3366 | struct inode *inode = lsp->ls_state->inode; |
| 3367 | |
| 3368 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
| 3369 | if (p == NULL) |
| 3370 | return NULL; |
| 3371 | p->arg.fh = NFS_FH(inode); |
| 3372 | p->arg.fl = &p->fl; |
| 3373 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3374 | p->res.seqid = seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3375 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3376 | p->arg.stateid = &lsp->ls_stateid; |
| 3377 | p->lsp = lsp; |
| 3378 | atomic_inc(&lsp->ls_count); |
| 3379 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3380 | p->ctx = get_nfs_open_context(ctx); |
| 3381 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3382 | p->server = NFS_SERVER(inode); |
| 3383 | return p; |
| 3384 | } |
| 3385 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3386 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3387 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3388 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3389 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3390 | nfs4_put_lock_state(calldata->lsp); |
| 3391 | put_nfs_open_context(calldata->ctx); |
| 3392 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3395 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3396 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3397 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3398 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3399 | if (RPC_ASSASSINATED(task)) |
| 3400 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3401 | switch (task->tk_status) { |
| 3402 | case 0: |
| 3403 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3404 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3405 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3406 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3407 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3408 | case -NFS4ERR_BAD_STATEID: |
| 3409 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3410 | case -NFS4ERR_STALE_STATEID: |
| 3411 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3412 | break; |
| 3413 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3414 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3415 | rpc_restart_call(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3416 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3419 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3420 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3421 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3423 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3424 | return; |
| 3425 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3426 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3427 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3428 | return; |
| 3429 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3430 | calldata->timestamp = jiffies; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3431 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3434 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3435 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3436 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3437 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3438 | }; |
| 3439 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3440 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3441 | struct nfs_open_context *ctx, |
| 3442 | struct nfs4_lock_state *lsp, |
| 3443 | struct nfs_seqid *seqid) |
| 3444 | { |
| 3445 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3446 | struct rpc_message msg = { |
| 3447 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3448 | .rpc_cred = ctx->cred, |
| 3449 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3450 | struct rpc_task_setup task_setup_data = { |
| 3451 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3452 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3453 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3454 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3455 | .flags = RPC_TASK_ASYNC, |
| 3456 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3457 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3458 | /* Ensure this is an unlock - when canceling a lock, the |
| 3459 | * canceled lock is passed in, and it won't be an unlock. |
| 3460 | */ |
| 3461 | fl->fl_type = F_UNLCK; |
| 3462 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3463 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3464 | if (data == NULL) { |
| 3465 | nfs_free_seqid(seqid); |
| 3466 | return ERR_PTR(-ENOMEM); |
| 3467 | } |
| 3468 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3469 | msg.rpc_argp = &data->arg, |
| 3470 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3471 | task_setup_data.callback_data = data; |
| 3472 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3473 | } |
| 3474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3476 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3477 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3478 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3479 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3480 | struct rpc_task *task; |
| 3481 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3482 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3484 | status = nfs4_set_lock_state(state, request); |
| 3485 | /* Unlock _before_ we do the RPC call */ |
| 3486 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3487 | down_read(&nfsi->rwsem); |
| 3488 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 3489 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3490 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3491 | } |
| 3492 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3493 | if (status != 0) |
| 3494 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3495 | /* Is this a delegated lock? */ |
| 3496 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3497 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3498 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3499 | seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3500 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3501 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3502 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3503 | 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] | 3504 | status = PTR_ERR(task); |
| 3505 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3506 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3507 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3508 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3509 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3510 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3511 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3514 | struct nfs4_lockdata { |
| 3515 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3516 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3517 | struct nfs4_lock_state *lsp; |
| 3518 | struct nfs_open_context *ctx; |
| 3519 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3520 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3521 | int rpc_status; |
| 3522 | int cancelled; |
| 3523 | }; |
| 3524 | |
| 3525 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
| 3526 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp) |
| 3527 | { |
| 3528 | struct nfs4_lockdata *p; |
| 3529 | struct inode *inode = lsp->ls_state->inode; |
| 3530 | struct nfs_server *server = NFS_SERVER(inode); |
| 3531 | |
| 3532 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 3533 | if (p == NULL) |
| 3534 | return NULL; |
| 3535 | |
| 3536 | p->arg.fh = NFS_FH(inode); |
| 3537 | p->arg.fl = &p->fl; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3538 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid); |
| 3539 | if (p->arg.open_seqid == NULL) |
| 3540 | goto out_free; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3541 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
| 3542 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3543 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3544 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3545 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3546 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3547 | p->res.lock_seqid = p->arg.lock_seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3548 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3549 | p->lsp = lsp; |
| 3550 | atomic_inc(&lsp->ls_count); |
| 3551 | p->ctx = get_nfs_open_context(ctx); |
| 3552 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3553 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3554 | out_free_seqid: |
| 3555 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3556 | out_free: |
| 3557 | kfree(p); |
| 3558 | return NULL; |
| 3559 | } |
| 3560 | |
| 3561 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 3562 | { |
| 3563 | struct nfs4_lockdata *data = calldata; |
| 3564 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3566 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3567 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 3568 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3569 | /* Do we need to do an open_to_lock_owner? */ |
| 3570 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 3571 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 3572 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3573 | data->arg.open_stateid = &state->stateid; |
| 3574 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3575 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3576 | } else |
| 3577 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3578 | data->timestamp = jiffies; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3579 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3580 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 3584 | { |
| 3585 | struct nfs4_lockdata *data = calldata; |
| 3586 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3587 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3588 | |
| 3589 | data->rpc_status = task->tk_status; |
| 3590 | if (RPC_ASSASSINATED(task)) |
| 3591 | goto out; |
| 3592 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3593 | if (data->rpc_status == 0) |
| 3594 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 3595 | else |
| 3596 | goto out; |
| 3597 | } |
| 3598 | if (data->rpc_status == 0) { |
| 3599 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 3600 | sizeof(data->lsp->ls_stateid.data)); |
| 3601 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 3602 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3603 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3604 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3605 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | static void nfs4_lock_release(void *calldata) |
| 3609 | { |
| 3610 | struct nfs4_lockdata *data = calldata; |
| 3611 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3612 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3613 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3614 | if (data->cancelled != 0) { |
| 3615 | struct rpc_task *task; |
| 3616 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 3617 | data->arg.lock_seqid); |
| 3618 | if (!IS_ERR(task)) |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3619 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3620 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3621 | } else |
| 3622 | nfs_free_seqid(data->arg.lock_seqid); |
| 3623 | nfs4_put_lock_state(data->lsp); |
| 3624 | put_nfs_open_context(data->ctx); |
| 3625 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3626 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 3630 | .rpc_call_prepare = nfs4_lock_prepare, |
| 3631 | .rpc_call_done = nfs4_lock_done, |
| 3632 | .rpc_release = nfs4_lock_release, |
| 3633 | }; |
| 3634 | |
| 3635 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int reclaim) |
| 3636 | { |
| 3637 | struct nfs4_lockdata *data; |
| 3638 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3639 | struct rpc_message msg = { |
| 3640 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 3641 | .rpc_cred = state->owner->so_cred, |
| 3642 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3643 | struct rpc_task_setup task_setup_data = { |
| 3644 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3645 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3646 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3647 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3648 | .flags = RPC_TASK_ASYNC, |
| 3649 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3650 | int ret; |
| 3651 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3652 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3653 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3654 | fl->fl_u.nfs4_fl.owner); |
| 3655 | if (data == NULL) |
| 3656 | return -ENOMEM; |
| 3657 | if (IS_SETLKW(cmd)) |
| 3658 | data->arg.block = 1; |
| 3659 | if (reclaim != 0) |
| 3660 | data->arg.reclaim = 1; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3661 | msg.rpc_argp = &data->arg, |
| 3662 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3663 | task_setup_data.callback_data = data; |
| 3664 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3665 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3666 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3667 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 3668 | if (ret == 0) { |
| 3669 | ret = data->rpc_status; |
| 3670 | if (ret == -NFS4ERR_DENIED) |
| 3671 | ret = -EAGAIN; |
| 3672 | } else |
| 3673 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3674 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3675 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3676 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 3680 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3681 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 3682 | struct nfs4_exception exception = { }; |
| 3683 | int err; |
| 3684 | |
| 3685 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 3686 | /* Cache the lock if possible... */ |
| 3687 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 3688 | return 0; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3689 | err = _nfs4_do_setlk(state, F_SETLK, request, 1); |
| 3690 | if (err != -NFS4ERR_DELAY) |
| 3691 | break; |
| 3692 | nfs4_handle_exception(server, err, &exception); |
| 3693 | } while (exception.retry); |
| 3694 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 3698 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3699 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 3700 | struct nfs4_exception exception = { }; |
| 3701 | int err; |
| 3702 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3703 | err = nfs4_set_lock_state(state, request); |
| 3704 | if (err != 0) |
| 3705 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3706 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 3707 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 3708 | return 0; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3709 | err = _nfs4_do_setlk(state, F_SETLK, request, 0); |
| 3710 | if (err != -NFS4ERR_DELAY) |
| 3711 | break; |
| 3712 | nfs4_handle_exception(server, err, &exception); |
| 3713 | } while (exception.retry); |
| 3714 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3718 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3719 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3720 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | int status; |
| 3722 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3723 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3724 | status = nfs4_set_lock_state(state, request); |
| 3725 | if (status != 0) |
| 3726 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3727 | request->fl_flags |= FL_ACCESS; |
| 3728 | status = do_vfs_lock(request->fl_file, request); |
| 3729 | if (status < 0) |
| 3730 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3731 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3732 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3733 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3734 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3735 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 3736 | status = do_vfs_lock(request->fl_file, request); |
| 3737 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3738 | } |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3739 | status = _nfs4_do_setlk(state, cmd, request, 0); |
| 3740 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3741 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3742 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3743 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3744 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3745 | printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3746 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3747 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 3748 | out: |
| 3749 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | return status; |
| 3751 | } |
| 3752 | |
| 3753 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3754 | { |
| 3755 | struct nfs4_exception exception = { }; |
| 3756 | int err; |
| 3757 | |
| 3758 | do { |
| 3759 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3760 | _nfs4_proc_setlk(state, cmd, request), |
| 3761 | &exception); |
| 3762 | } while (exception.retry); |
| 3763 | return err; |
| 3764 | } |
| 3765 | |
| 3766 | static int |
| 3767 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 3768 | { |
| 3769 | struct nfs_open_context *ctx; |
| 3770 | struct nfs4_state *state; |
| 3771 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 3772 | int status; |
| 3773 | |
| 3774 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3775 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | state = ctx->state; |
| 3777 | |
| 3778 | if (request->fl_start < 0 || request->fl_end < 0) |
| 3779 | return -EINVAL; |
| 3780 | |
| 3781 | if (IS_GETLK(cmd)) |
| 3782 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 3783 | |
| 3784 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 3785 | return -EINVAL; |
| 3786 | |
| 3787 | if (request->fl_type == F_UNLCK) |
| 3788 | return nfs4_proc_unlck(state, cmd, request); |
| 3789 | |
| 3790 | do { |
| 3791 | status = nfs4_proc_setlk(state, cmd, request); |
| 3792 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 3793 | break; |
| 3794 | timeout = nfs4_set_lock_task_retry(timeout); |
| 3795 | status = -ERESTARTSYS; |
| 3796 | if (signalled()) |
| 3797 | break; |
| 3798 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | return status; |
| 3800 | } |
| 3801 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 3802 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 3803 | { |
| 3804 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 3805 | struct nfs4_exception exception = { }; |
| 3806 | int err; |
| 3807 | |
| 3808 | err = nfs4_set_lock_state(state, fl); |
| 3809 | if (err != 0) |
| 3810 | goto out; |
| 3811 | do { |
| 3812 | err = _nfs4_do_setlk(state, F_SETLK, fl, 0); |
| 3813 | if (err != -NFS4ERR_DELAY) |
| 3814 | break; |
| 3815 | err = nfs4_handle_exception(server, err, &exception); |
| 3816 | } while (exception.retry); |
| 3817 | out: |
| 3818 | return err; |
| 3819 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3820 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3821 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 3822 | |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3823 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, |
| 3824 | size_t buflen, int flags) |
| 3825 | { |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3826 | struct inode *inode = dentry->d_inode; |
| 3827 | |
| 3828 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 3829 | return -EOPNOTSUPP; |
| 3830 | |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3831 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, |
| 3835 | * and that's what we'll do for e.g. user attributes that haven't been set. |
| 3836 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported |
| 3837 | * attributes in kernel-managed attribute namespaces. */ |
| 3838 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, |
| 3839 | size_t buflen) |
| 3840 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3841 | struct inode *inode = dentry->d_inode; |
| 3842 | |
| 3843 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 3844 | return -EOPNOTSUPP; |
| 3845 | |
| 3846 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) |
| 3850 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3851 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3852 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 3853 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 3854 | return 0; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3855 | if (buf && buflen < len) |
| 3856 | return -ERANGE; |
| 3857 | if (buf) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3858 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); |
| 3859 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3862 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 3863 | { |
| 3864 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 3865 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 3866 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 3867 | return; |
| 3868 | |
| 3869 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 3870 | NFS_ATTR_FATTR_NLINK; |
| 3871 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3872 | fattr->nlink = 2; |
| 3873 | } |
| 3874 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 3875 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 3876 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3877 | { |
| 3878 | struct nfs_server *server = NFS_SERVER(dir); |
| 3879 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 3880 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 3881 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3882 | }; |
| 3883 | struct nfs4_fs_locations_arg args = { |
| 3884 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 3885 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3886 | .page = page, |
| 3887 | .bitmask = bitmask, |
| 3888 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 3889 | struct nfs4_fs_locations_res res = { |
| 3890 | .fs_locations = fs_locations, |
| 3891 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3892 | struct rpc_message msg = { |
| 3893 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 3894 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 3895 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3896 | }; |
| 3897 | int status; |
| 3898 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3899 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 3900 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3901 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 3902 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3903 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3904 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3905 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 3906 | return status; |
| 3907 | } |
| 3908 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 3909 | #ifdef CONFIG_NFS_V4_1 |
| 3910 | /* Destroy the slot table */ |
| 3911 | static void nfs4_destroy_slot_table(struct nfs4_session *session) |
| 3912 | { |
| 3913 | if (session->fc_slot_table.slots == NULL) |
| 3914 | return; |
| 3915 | kfree(session->fc_slot_table.slots); |
| 3916 | session->fc_slot_table.slots = NULL; |
| 3917 | return; |
| 3918 | } |
| 3919 | |
| 3920 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 3921 | { |
| 3922 | struct nfs4_session *session; |
| 3923 | struct nfs4_slot_table *tbl; |
| 3924 | |
| 3925 | session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL); |
| 3926 | if (!session) |
| 3927 | return NULL; |
| 3928 | tbl = &session->fc_slot_table; |
| 3929 | spin_lock_init(&tbl->slot_tbl_lock); |
| 3930 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "Slot table"); |
| 3931 | session->clp = clp; |
| 3932 | return session; |
| 3933 | } |
| 3934 | |
| 3935 | void nfs4_destroy_session(struct nfs4_session *session) |
| 3936 | { |
| 3937 | nfs4_destroy_slot_table(session); |
| 3938 | kfree(session); |
| 3939 | } |
| 3940 | |
| 3941 | #endif /* CONFIG_NFS_V4_1 */ |
| 3942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 3944 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 3945 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | .recover_open = nfs4_open_reclaim, |
| 3947 | .recover_lock = nfs4_lock_reclaim, |
| 3948 | }; |
| 3949 | |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 3950 | struct nfs4_state_recovery_ops nfs4_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 3951 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 3952 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | .recover_open = nfs4_open_expired, |
| 3954 | .recover_lock = nfs4_lock_expired, |
| 3955 | }; |
| 3956 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 3957 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3958 | .permission = nfs_permission, |
| 3959 | .getattr = nfs_getattr, |
| 3960 | .setattr = nfs_setattr, |
| 3961 | .getxattr = nfs4_getxattr, |
| 3962 | .setxattr = nfs4_setxattr, |
| 3963 | .listxattr = nfs4_listxattr, |
| 3964 | }; |
| 3965 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 3966 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | .version = 4, /* protocol version */ |
| 3968 | .dentry_ops = &nfs4_dentry_operations, |
| 3969 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3970 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | .getroot = nfs4_proc_get_root, |
| 3972 | .getattr = nfs4_proc_getattr, |
| 3973 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3974 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | .lookup = nfs4_proc_lookup, |
| 3976 | .access = nfs4_proc_access, |
| 3977 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | .create = nfs4_proc_create, |
| 3979 | .remove = nfs4_proc_remove, |
| 3980 | .unlink_setup = nfs4_proc_unlink_setup, |
| 3981 | .unlink_done = nfs4_proc_unlink_done, |
| 3982 | .rename = nfs4_proc_rename, |
| 3983 | .link = nfs4_proc_link, |
| 3984 | .symlink = nfs4_proc_symlink, |
| 3985 | .mkdir = nfs4_proc_mkdir, |
| 3986 | .rmdir = nfs4_proc_remove, |
| 3987 | .readdir = nfs4_proc_readdir, |
| 3988 | .mknod = nfs4_proc_mknod, |
| 3989 | .statfs = nfs4_proc_statfs, |
| 3990 | .fsinfo = nfs4_proc_fsinfo, |
| 3991 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 3992 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | .decode_dirent = nfs4_decode_dirent, |
| 3994 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3995 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3997 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3999 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4001 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 4002 | .close_context = nfs4_close_context, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | }; |
| 4004 | |
| 4005 | /* |
| 4006 | * Local variables: |
| 4007 | * c-basic-offset: 8 |
| 4008 | * End: |
| 4009 | */ |