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