xfrm: Assign the inner mode output function to the dst entry
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / nfs / nfs4proc.c
blob9bf41eab3e4646eb1256c1192c4482fc89c4c61d
1 /*
2 * fs/nfs/nfs4proc.c
4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
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.
38 #include <linux/mm.h>
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/slab.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/sunrpc/gss_api.h>
45 #include <linux/nfs.h>
46 #include <linux/nfs4.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/nfs_page.h>
49 #include <linux/namei.h>
50 #include <linux/mount.h>
51 #include <linux/module.h>
52 #include <linux/sunrpc/bc_xprt.h>
53 #include <linux/xattr.h>
54 #include <linux/utsname.h>
56 #include "nfs4_fs.h"
57 #include "delegation.h"
58 #include "internal.h"
59 #include "iostat.h"
60 #include "callback.h"
61 #include "pnfs.h"
63 #define NFSDBG_FACILITY NFSDBG_PROC
65 #define NFS4_POLL_RETRY_MIN (HZ/10)
66 #define NFS4_POLL_RETRY_MAX (15*HZ)
68 #define NFS4_MAX_LOOP_ON_RECOVER (10)
70 struct nfs4_opendata;
71 static int _nfs4_proc_open(struct nfs4_opendata *data);
72 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
73 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
74 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
75 static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir,
76 const struct qstr *name, struct nfs_fh *fhandle,
77 struct nfs_fattr *fattr);
78 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
79 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
80 struct nfs_fattr *fattr, struct iattr *sattr,
81 struct nfs4_state *state);
83 /* Prevent leaks of NFSv4 errors into userland */
84 static int nfs4_map_errors(int err)
86 if (err >= -1000)
87 return err;
88 switch (err) {
89 case -NFS4ERR_RESOURCE:
90 return -EREMOTEIO;
91 case -NFS4ERR_WRONGSEC:
92 return -EPERM;
93 case -NFS4ERR_BADOWNER:
94 case -NFS4ERR_BADNAME:
95 return -EINVAL;
96 default:
97 dprintk("%s could not handle NFSv4 error %d\n",
98 __func__, -err);
99 break;
101 return -EIO;
105 * This is our standard bitmap for GETATTR requests.
107 const u32 nfs4_fattr_bitmap[2] = {
108 FATTR4_WORD0_TYPE
109 | FATTR4_WORD0_CHANGE
110 | FATTR4_WORD0_SIZE
111 | FATTR4_WORD0_FSID
112 | FATTR4_WORD0_FILEID,
113 FATTR4_WORD1_MODE
114 | FATTR4_WORD1_NUMLINKS
115 | FATTR4_WORD1_OWNER
116 | FATTR4_WORD1_OWNER_GROUP
117 | FATTR4_WORD1_RAWDEV
118 | FATTR4_WORD1_SPACE_USED
119 | FATTR4_WORD1_TIME_ACCESS
120 | FATTR4_WORD1_TIME_METADATA
121 | FATTR4_WORD1_TIME_MODIFY
124 const u32 nfs4_statfs_bitmap[2] = {
125 FATTR4_WORD0_FILES_AVAIL
126 | FATTR4_WORD0_FILES_FREE
127 | FATTR4_WORD0_FILES_TOTAL,
128 FATTR4_WORD1_SPACE_AVAIL
129 | FATTR4_WORD1_SPACE_FREE
130 | FATTR4_WORD1_SPACE_TOTAL
133 const u32 nfs4_pathconf_bitmap[2] = {
134 FATTR4_WORD0_MAXLINK
135 | FATTR4_WORD0_MAXNAME,
139 const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
140 | FATTR4_WORD0_MAXREAD
141 | FATTR4_WORD0_MAXWRITE
142 | FATTR4_WORD0_LEASE_TIME,
143 FATTR4_WORD1_TIME_DELTA
144 | FATTR4_WORD1_FS_LAYOUT_TYPES
147 const u32 nfs4_fs_locations_bitmap[2] = {
148 FATTR4_WORD0_TYPE
149 | FATTR4_WORD0_CHANGE
150 | FATTR4_WORD0_SIZE
151 | FATTR4_WORD0_FSID
152 | FATTR4_WORD0_FILEID
153 | FATTR4_WORD0_FS_LOCATIONS,
154 FATTR4_WORD1_MODE
155 | FATTR4_WORD1_NUMLINKS
156 | FATTR4_WORD1_OWNER
157 | FATTR4_WORD1_OWNER_GROUP
158 | FATTR4_WORD1_RAWDEV
159 | FATTR4_WORD1_SPACE_USED
160 | FATTR4_WORD1_TIME_ACCESS
161 | FATTR4_WORD1_TIME_METADATA
162 | FATTR4_WORD1_TIME_MODIFY
163 | FATTR4_WORD1_MOUNTED_ON_FILEID
166 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
167 struct nfs4_readdir_arg *readdir)
169 __be32 *start, *p;
171 BUG_ON(readdir->count < 80);
172 if (cookie > 2) {
173 readdir->cookie = cookie;
174 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
175 return;
178 readdir->cookie = 0;
179 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
180 if (cookie == 2)
181 return;
184 * NFSv4 servers do not return entries for '.' and '..'
185 * Therefore, we fake these entries here. We let '.'
186 * have cookie 0 and '..' have cookie 1. Note that
187 * when talking to the server, we always send cookie 0
188 * instead of 1 or 2.
190 start = p = kmap_atomic(*readdir->pages, KM_USER0);
192 if (cookie == 0) {
193 *p++ = xdr_one; /* next */
194 *p++ = xdr_zero; /* cookie, first word */
195 *p++ = xdr_one; /* cookie, second word */
196 *p++ = xdr_one; /* entry len */
197 memcpy(p, ".\0\0\0", 4); /* entry */
198 p++;
199 *p++ = xdr_one; /* bitmap length */
200 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
201 *p++ = htonl(8); /* attribute buffer length */
202 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
205 *p++ = xdr_one; /* next */
206 *p++ = xdr_zero; /* cookie, first word */
207 *p++ = xdr_two; /* cookie, second word */
208 *p++ = xdr_two; /* entry len */
209 memcpy(p, "..\0\0", 4); /* entry */
210 p++;
211 *p++ = xdr_one; /* bitmap length */
212 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
213 *p++ = htonl(8); /* attribute buffer length */
214 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
216 readdir->pgbase = (char *)p - (char *)start;
217 readdir->count -= readdir->pgbase;
218 kunmap_atomic(start, KM_USER0);
221 static int nfs4_wait_clnt_recover(struct nfs_client *clp)
223 int res;
225 might_sleep();
227 res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING,
228 nfs_wait_bit_killable, TASK_KILLABLE);
229 return res;
232 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
234 int res = 0;
236 might_sleep();
238 if (*timeout <= 0)
239 *timeout = NFS4_POLL_RETRY_MIN;
240 if (*timeout > NFS4_POLL_RETRY_MAX)
241 *timeout = NFS4_POLL_RETRY_MAX;
242 schedule_timeout_killable(*timeout);
243 if (fatal_signal_pending(current))
244 res = -ERESTARTSYS;
245 *timeout <<= 1;
246 return res;
249 /* This is the error handling routine for processes that are allowed
250 * to sleep.
252 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
254 struct nfs_client *clp = server->nfs_client;
255 struct nfs4_state *state = exception->state;
256 int ret = errorcode;
258 exception->retry = 0;
259 switch(errorcode) {
260 case 0:
261 return 0;
262 case -NFS4ERR_ADMIN_REVOKED:
263 case -NFS4ERR_BAD_STATEID:
264 case -NFS4ERR_OPENMODE:
265 if (state == NULL)
266 break;
267 nfs4_schedule_stateid_recovery(server, state);
268 goto wait_on_recovery;
269 case -NFS4ERR_STALE_STATEID:
270 case -NFS4ERR_STALE_CLIENTID:
271 case -NFS4ERR_EXPIRED:
272 nfs4_schedule_lease_recovery(clp);
273 goto wait_on_recovery;
274 #if defined(CONFIG_NFS_V4_1)
275 case -NFS4ERR_BADSESSION:
276 case -NFS4ERR_BADSLOT:
277 case -NFS4ERR_BAD_HIGH_SLOT:
278 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
279 case -NFS4ERR_DEADSESSION:
280 case -NFS4ERR_SEQ_FALSE_RETRY:
281 case -NFS4ERR_SEQ_MISORDERED:
282 dprintk("%s ERROR: %d Reset session\n", __func__,
283 errorcode);
284 nfs4_schedule_session_recovery(clp->cl_session);
285 exception->retry = 1;
286 break;
287 #endif /* defined(CONFIG_NFS_V4_1) */
288 case -NFS4ERR_FILE_OPEN:
289 if (exception->timeout > HZ) {
290 /* We have retried a decent amount, time to
291 * fail
293 ret = -EBUSY;
294 break;
296 case -NFS4ERR_GRACE:
297 case -NFS4ERR_DELAY:
298 case -EKEYEXPIRED:
299 ret = nfs4_delay(server->client, &exception->timeout);
300 if (ret != 0)
301 break;
302 case -NFS4ERR_OLD_STATEID:
303 exception->retry = 1;
304 break;
305 case -NFS4ERR_BADOWNER:
306 /* The following works around a Linux server bug! */
307 case -NFS4ERR_BADNAME:
308 if (server->caps & NFS_CAP_UIDGID_NOMAP) {
309 server->caps &= ~NFS_CAP_UIDGID_NOMAP;
310 exception->retry = 1;
311 printk(KERN_WARNING "NFS: v4 server %s "
312 "does not accept raw "
313 "uid/gids. "
314 "Reenabling the idmapper.\n",
315 server->nfs_client->cl_hostname);
318 /* We failed to handle the error */
319 return nfs4_map_errors(ret);
320 wait_on_recovery:
321 ret = nfs4_wait_clnt_recover(clp);
322 if (ret == 0)
323 exception->retry = 1;
324 return ret;
328 static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
330 spin_lock(&clp->cl_lock);
331 if (time_before(clp->cl_last_renewal,timestamp))
332 clp->cl_last_renewal = timestamp;
333 spin_unlock(&clp->cl_lock);
336 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
338 do_renew_lease(server->nfs_client, timestamp);
341 #if defined(CONFIG_NFS_V4_1)
344 * nfs4_free_slot - free a slot and efficiently update slot table.
346 * freeing a slot is trivially done by clearing its respective bit
347 * in the bitmap.
348 * If the freed slotid equals highest_used_slotid we want to update it
349 * so that the server would be able to size down the slot table if needed,
350 * otherwise we know that the highest_used_slotid is still in use.
351 * When updating highest_used_slotid there may be "holes" in the bitmap
352 * so we need to scan down from highest_used_slotid to 0 looking for the now
353 * highest slotid in use.
354 * If none found, highest_used_slotid is set to -1.
356 * Must be called while holding tbl->slot_tbl_lock
358 static void
359 nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot)
361 int free_slotid = free_slot - tbl->slots;
362 int slotid = free_slotid;
364 BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE);
365 /* clear used bit in bitmap */
366 __clear_bit(slotid, tbl->used_slots);
368 /* update highest_used_slotid when it is freed */
369 if (slotid == tbl->highest_used_slotid) {
370 slotid = find_last_bit(tbl->used_slots, tbl->max_slots);
371 if (slotid < tbl->max_slots)
372 tbl->highest_used_slotid = slotid;
373 else
374 tbl->highest_used_slotid = -1;
376 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__,
377 free_slotid, tbl->highest_used_slotid);
381 * Signal state manager thread if session fore channel is drained
383 static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
385 struct rpc_task *task;
387 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
388 task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq);
389 if (task)
390 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
391 return;
394 if (ses->fc_slot_table.highest_used_slotid != -1)
395 return;
397 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__);
398 complete(&ses->fc_slot_table.complete);
402 * Signal state manager thread if session back channel is drained
404 void nfs4_check_drain_bc_complete(struct nfs4_session *ses)
406 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) ||
407 ses->bc_slot_table.highest_used_slotid != -1)
408 return;
409 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__);
410 complete(&ses->bc_slot_table.complete);
413 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
415 struct nfs4_slot_table *tbl;
417 tbl = &res->sr_session->fc_slot_table;
418 if (!res->sr_slot) {
419 /* just wake up the next guy waiting since
420 * we may have not consumed a slot after all */
421 dprintk("%s: No slot\n", __func__);
422 return;
425 spin_lock(&tbl->slot_tbl_lock);
426 nfs4_free_slot(tbl, res->sr_slot);
427 nfs4_check_drain_fc_complete(res->sr_session);
428 spin_unlock(&tbl->slot_tbl_lock);
429 res->sr_slot = NULL;
432 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
434 unsigned long timestamp;
435 struct nfs_client *clp;
438 * sr_status remains 1 if an RPC level error occurred. The server
439 * may or may not have processed the sequence operation..
440 * Proceed as if the server received and processed the sequence
441 * operation.
443 if (res->sr_status == 1)
444 res->sr_status = NFS_OK;
446 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
447 if (!res->sr_slot)
448 goto out;
450 /* Check the SEQUENCE operation status */
451 switch (res->sr_status) {
452 case 0:
453 /* Update the slot's sequence and clientid lease timer */
454 ++res->sr_slot->seq_nr;
455 timestamp = res->sr_renewal_time;
456 clp = res->sr_session->clp;
457 do_renew_lease(clp, timestamp);
458 /* Check sequence flags */
459 if (res->sr_status_flags != 0)
460 nfs4_schedule_lease_recovery(clp);
461 break;
462 case -NFS4ERR_DELAY:
463 /* The server detected a resend of the RPC call and
464 * returned NFS4ERR_DELAY as per Section 2.10.6.2
465 * of RFC5661.
467 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
468 __func__,
469 res->sr_slot - res->sr_session->fc_slot_table.slots,
470 res->sr_slot->seq_nr);
471 goto out_retry;
472 default:
473 /* Just update the slot sequence no. */
474 ++res->sr_slot->seq_nr;
476 out:
477 /* The session may be reset by one of the error handlers. */
478 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
479 nfs41_sequence_free_slot(res);
480 return 1;
481 out_retry:
482 if (!rpc_restart_call(task))
483 goto out;
484 rpc_delay(task, NFS4_POLL_RETRY_MAX);
485 return 0;
488 static int nfs4_sequence_done(struct rpc_task *task,
489 struct nfs4_sequence_res *res)
491 if (res->sr_session == NULL)
492 return 1;
493 return nfs41_sequence_done(task, res);
497 * nfs4_find_slot - efficiently look for a free slot
499 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
500 * If found, we mark the slot as used, update the highest_used_slotid,
501 * and respectively set up the sequence operation args.
502 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
504 * Note: must be called with under the slot_tbl_lock.
506 static u8
507 nfs4_find_slot(struct nfs4_slot_table *tbl)
509 int slotid;
510 u8 ret_id = NFS4_MAX_SLOT_TABLE;
511 BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
513 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
514 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
515 tbl->max_slots);
516 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
517 if (slotid >= tbl->max_slots)
518 goto out;
519 __set_bit(slotid, tbl->used_slots);
520 if (slotid > tbl->highest_used_slotid)
521 tbl->highest_used_slotid = slotid;
522 ret_id = slotid;
523 out:
524 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
525 __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
526 return ret_id;
529 int nfs41_setup_sequence(struct nfs4_session *session,
530 struct nfs4_sequence_args *args,
531 struct nfs4_sequence_res *res,
532 int cache_reply,
533 struct rpc_task *task)
535 struct nfs4_slot *slot;
536 struct nfs4_slot_table *tbl;
537 u8 slotid;
539 dprintk("--> %s\n", __func__);
540 /* slot already allocated? */
541 if (res->sr_slot != NULL)
542 return 0;
544 tbl = &session->fc_slot_table;
546 spin_lock(&tbl->slot_tbl_lock);
547 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
548 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
550 * The state manager will wait until the slot table is empty.
551 * Schedule the reset thread
553 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
554 spin_unlock(&tbl->slot_tbl_lock);
555 dprintk("%s Schedule Session Reset\n", __func__);
556 return -EAGAIN;
559 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
560 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
561 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
562 spin_unlock(&tbl->slot_tbl_lock);
563 dprintk("%s enforce FIFO order\n", __func__);
564 return -EAGAIN;
567 slotid = nfs4_find_slot(tbl);
568 if (slotid == NFS4_MAX_SLOT_TABLE) {
569 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
570 spin_unlock(&tbl->slot_tbl_lock);
571 dprintk("<-- %s: no free slots\n", __func__);
572 return -EAGAIN;
574 spin_unlock(&tbl->slot_tbl_lock);
576 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
577 slot = tbl->slots + slotid;
578 args->sa_session = session;
579 args->sa_slotid = slotid;
580 args->sa_cache_this = cache_reply;
582 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
584 res->sr_session = session;
585 res->sr_slot = slot;
586 res->sr_renewal_time = jiffies;
587 res->sr_status_flags = 0;
589 * sr_status is only set in decode_sequence, and so will remain
590 * set to 1 if an rpc level failure occurs.
592 res->sr_status = 1;
593 return 0;
595 EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
597 int nfs4_setup_sequence(const struct nfs_server *server,
598 struct nfs4_sequence_args *args,
599 struct nfs4_sequence_res *res,
600 int cache_reply,
601 struct rpc_task *task)
603 struct nfs4_session *session = nfs4_get_session(server);
604 int ret = 0;
606 if (session == NULL) {
607 args->sa_session = NULL;
608 res->sr_session = NULL;
609 goto out;
612 dprintk("--> %s clp %p session %p sr_slot %td\n",
613 __func__, session->clp, session, res->sr_slot ?
614 res->sr_slot - session->fc_slot_table.slots : -1);
616 ret = nfs41_setup_sequence(session, args, res, cache_reply,
617 task);
618 out:
619 dprintk("<-- %s status=%d\n", __func__, ret);
620 return ret;
623 struct nfs41_call_sync_data {
624 const struct nfs_server *seq_server;
625 struct nfs4_sequence_args *seq_args;
626 struct nfs4_sequence_res *seq_res;
627 int cache_reply;
630 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
632 struct nfs41_call_sync_data *data = calldata;
634 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
636 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
637 data->seq_res, data->cache_reply, task))
638 return;
639 rpc_call_start(task);
642 static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
644 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
645 nfs41_call_sync_prepare(task, calldata);
648 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
650 struct nfs41_call_sync_data *data = calldata;
652 nfs41_sequence_done(task, data->seq_res);
655 struct rpc_call_ops nfs41_call_sync_ops = {
656 .rpc_call_prepare = nfs41_call_sync_prepare,
657 .rpc_call_done = nfs41_call_sync_done,
660 struct rpc_call_ops nfs41_call_priv_sync_ops = {
661 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
662 .rpc_call_done = nfs41_call_sync_done,
665 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
666 struct nfs_server *server,
667 struct rpc_message *msg,
668 struct nfs4_sequence_args *args,
669 struct nfs4_sequence_res *res,
670 int cache_reply,
671 int privileged)
673 int ret;
674 struct rpc_task *task;
675 struct nfs41_call_sync_data data = {
676 .seq_server = server,
677 .seq_args = args,
678 .seq_res = res,
679 .cache_reply = cache_reply,
681 struct rpc_task_setup task_setup = {
682 .rpc_client = clnt,
683 .rpc_message = msg,
684 .callback_ops = &nfs41_call_sync_ops,
685 .callback_data = &data
688 res->sr_slot = NULL;
689 if (privileged)
690 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
691 task = rpc_run_task(&task_setup);
692 if (IS_ERR(task))
693 ret = PTR_ERR(task);
694 else {
695 ret = task->tk_status;
696 rpc_put_task(task);
698 return ret;
701 int _nfs4_call_sync_session(struct rpc_clnt *clnt,
702 struct nfs_server *server,
703 struct rpc_message *msg,
704 struct nfs4_sequence_args *args,
705 struct nfs4_sequence_res *res,
706 int cache_reply)
708 return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0);
711 #else
712 static int nfs4_sequence_done(struct rpc_task *task,
713 struct nfs4_sequence_res *res)
715 return 1;
717 #endif /* CONFIG_NFS_V4_1 */
719 int _nfs4_call_sync(struct rpc_clnt *clnt,
720 struct nfs_server *server,
721 struct rpc_message *msg,
722 struct nfs4_sequence_args *args,
723 struct nfs4_sequence_res *res,
724 int cache_reply)
726 args->sa_session = res->sr_session = NULL;
727 return rpc_call_sync(clnt, msg, 0);
730 static inline
731 int nfs4_call_sync(struct rpc_clnt *clnt,
732 struct nfs_server *server,
733 struct rpc_message *msg,
734 struct nfs4_sequence_args *args,
735 struct nfs4_sequence_res *res,
736 int cache_reply)
738 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg,
739 args, res, cache_reply);
742 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
744 struct nfs_inode *nfsi = NFS_I(dir);
746 spin_lock(&dir->i_lock);
747 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
748 if (!cinfo->atomic || cinfo->before != nfsi->change_attr)
749 nfs_force_lookup_revalidate(dir);
750 nfsi->change_attr = cinfo->after;
751 spin_unlock(&dir->i_lock);
754 struct nfs4_opendata {
755 struct kref kref;
756 struct nfs_openargs o_arg;
757 struct nfs_openres o_res;
758 struct nfs_open_confirmargs c_arg;
759 struct nfs_open_confirmres c_res;
760 struct nfs_fattr f_attr;
761 struct nfs_fattr dir_attr;
762 struct path path;
763 struct dentry *dir;
764 struct nfs4_state_owner *owner;
765 struct nfs4_state *state;
766 struct iattr attrs;
767 unsigned long timestamp;
768 unsigned int rpc_done : 1;
769 int rpc_status;
770 int cancelled;
774 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
776 p->o_res.f_attr = &p->f_attr;
777 p->o_res.dir_attr = &p->dir_attr;
778 p->o_res.seqid = p->o_arg.seqid;
779 p->c_res.seqid = p->c_arg.seqid;
780 p->o_res.server = p->o_arg.server;
781 nfs_fattr_init(&p->f_attr);
782 nfs_fattr_init(&p->dir_attr);
785 static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
786 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
787 const struct iattr *attrs,
788 gfp_t gfp_mask)
790 struct dentry *parent = dget_parent(path->dentry);
791 struct inode *dir = parent->d_inode;
792 struct nfs_server *server = NFS_SERVER(dir);
793 struct nfs4_opendata *p;
795 p = kzalloc(sizeof(*p), gfp_mask);
796 if (p == NULL)
797 goto err;
798 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
799 if (p->o_arg.seqid == NULL)
800 goto err_free;
801 path_get(path);
802 p->path = *path;
803 p->dir = parent;
804 p->owner = sp;
805 atomic_inc(&sp->so_count);
806 p->o_arg.fh = NFS_FH(dir);
807 p->o_arg.open_flags = flags;
808 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
809 p->o_arg.clientid = server->nfs_client->cl_clientid;
810 p->o_arg.id = sp->so_owner_id.id;
811 p->o_arg.name = &p->path.dentry->d_name;
812 p->o_arg.server = server;
813 p->o_arg.bitmask = server->attr_bitmask;
814 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
815 if (flags & O_CREAT) {
816 u32 *s;
818 p->o_arg.u.attrs = &p->attrs;
819 memcpy(&p->attrs, attrs, sizeof(p->attrs));
820 s = (u32 *) p->o_arg.u.verifier.data;
821 s[0] = jiffies;
822 s[1] = current->pid;
824 p->c_arg.fh = &p->o_res.fh;
825 p->c_arg.stateid = &p->o_res.stateid;
826 p->c_arg.seqid = p->o_arg.seqid;
827 nfs4_init_opendata_res(p);
828 kref_init(&p->kref);
829 return p;
830 err_free:
831 kfree(p);
832 err:
833 dput(parent);
834 return NULL;
837 static void nfs4_opendata_free(struct kref *kref)
839 struct nfs4_opendata *p = container_of(kref,
840 struct nfs4_opendata, kref);
842 nfs_free_seqid(p->o_arg.seqid);
843 if (p->state != NULL)
844 nfs4_put_open_state(p->state);
845 nfs4_put_state_owner(p->owner);
846 dput(p->dir);
847 path_put(&p->path);
848 kfree(p);
851 static void nfs4_opendata_put(struct nfs4_opendata *p)
853 if (p != NULL)
854 kref_put(&p->kref, nfs4_opendata_free);
857 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
859 int ret;
861 ret = rpc_wait_for_completion_task(task);
862 return ret;
865 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
867 int ret = 0;
869 if (open_mode & O_EXCL)
870 goto out;
871 switch (mode & (FMODE_READ|FMODE_WRITE)) {
872 case FMODE_READ:
873 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
874 && state->n_rdonly != 0;
875 break;
876 case FMODE_WRITE:
877 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
878 && state->n_wronly != 0;
879 break;
880 case FMODE_READ|FMODE_WRITE:
881 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
882 && state->n_rdwr != 0;
884 out:
885 return ret;
888 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
890 if ((delegation->type & fmode) != fmode)
891 return 0;
892 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
893 return 0;
894 nfs_mark_delegation_referenced(delegation);
895 return 1;
898 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
900 switch (fmode) {
901 case FMODE_WRITE:
902 state->n_wronly++;
903 break;
904 case FMODE_READ:
905 state->n_rdonly++;
906 break;
907 case FMODE_READ|FMODE_WRITE:
908 state->n_rdwr++;
910 nfs4_state_set_mode_locked(state, state->state | fmode);
913 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
915 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
916 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
917 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
918 switch (fmode) {
919 case FMODE_READ:
920 set_bit(NFS_O_RDONLY_STATE, &state->flags);
921 break;
922 case FMODE_WRITE:
923 set_bit(NFS_O_WRONLY_STATE, &state->flags);
924 break;
925 case FMODE_READ|FMODE_WRITE:
926 set_bit(NFS_O_RDWR_STATE, &state->flags);
930 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
932 write_seqlock(&state->seqlock);
933 nfs_set_open_stateid_locked(state, stateid, fmode);
934 write_sequnlock(&state->seqlock);
937 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
940 * Protect the call to nfs4_state_set_mode_locked and
941 * serialise the stateid update
943 write_seqlock(&state->seqlock);
944 if (deleg_stateid != NULL) {
945 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
946 set_bit(NFS_DELEGATED_STATE, &state->flags);
948 if (open_stateid != NULL)
949 nfs_set_open_stateid_locked(state, open_stateid, fmode);
950 write_sequnlock(&state->seqlock);
951 spin_lock(&state->owner->so_lock);
952 update_open_stateflags(state, fmode);
953 spin_unlock(&state->owner->so_lock);
956 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
958 struct nfs_inode *nfsi = NFS_I(state->inode);
959 struct nfs_delegation *deleg_cur;
960 int ret = 0;
962 fmode &= (FMODE_READ|FMODE_WRITE);
964 rcu_read_lock();
965 deleg_cur = rcu_dereference(nfsi->delegation);
966 if (deleg_cur == NULL)
967 goto no_delegation;
969 spin_lock(&deleg_cur->lock);
970 if (nfsi->delegation != deleg_cur ||
971 (deleg_cur->type & fmode) != fmode)
972 goto no_delegation_unlock;
974 if (delegation == NULL)
975 delegation = &deleg_cur->stateid;
976 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
977 goto no_delegation_unlock;
979 nfs_mark_delegation_referenced(deleg_cur);
980 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
981 ret = 1;
982 no_delegation_unlock:
983 spin_unlock(&deleg_cur->lock);
984 no_delegation:
985 rcu_read_unlock();
987 if (!ret && open_stateid != NULL) {
988 __update_open_stateid(state, open_stateid, NULL, fmode);
989 ret = 1;
992 return ret;
996 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
998 struct nfs_delegation *delegation;
1000 rcu_read_lock();
1001 delegation = rcu_dereference(NFS_I(inode)->delegation);
1002 if (delegation == NULL || (delegation->type & fmode) == fmode) {
1003 rcu_read_unlock();
1004 return;
1006 rcu_read_unlock();
1007 nfs_inode_return_delegation(inode);
1010 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1012 struct nfs4_state *state = opendata->state;
1013 struct nfs_inode *nfsi = NFS_I(state->inode);
1014 struct nfs_delegation *delegation;
1015 int open_mode = opendata->o_arg.open_flags & O_EXCL;
1016 fmode_t fmode = opendata->o_arg.fmode;
1017 nfs4_stateid stateid;
1018 int ret = -EAGAIN;
1020 for (;;) {
1021 if (can_open_cached(state, fmode, open_mode)) {
1022 spin_lock(&state->owner->so_lock);
1023 if (can_open_cached(state, fmode, open_mode)) {
1024 update_open_stateflags(state, fmode);
1025 spin_unlock(&state->owner->so_lock);
1026 goto out_return_state;
1028 spin_unlock(&state->owner->so_lock);
1030 rcu_read_lock();
1031 delegation = rcu_dereference(nfsi->delegation);
1032 if (delegation == NULL ||
1033 !can_open_delegated(delegation, fmode)) {
1034 rcu_read_unlock();
1035 break;
1037 /* Save the delegation */
1038 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
1039 rcu_read_unlock();
1040 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1041 if (ret != 0)
1042 goto out;
1043 ret = -EAGAIN;
1045 /* Try to update the stateid using the delegation */
1046 if (update_open_stateid(state, NULL, &stateid, fmode))
1047 goto out_return_state;
1049 out:
1050 return ERR_PTR(ret);
1051 out_return_state:
1052 atomic_inc(&state->count);
1053 return state;
1056 static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1058 struct inode *inode;
1059 struct nfs4_state *state = NULL;
1060 struct nfs_delegation *delegation;
1061 int ret;
1063 if (!data->rpc_done) {
1064 state = nfs4_try_open_cached(data);
1065 goto out;
1068 ret = -EAGAIN;
1069 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1070 goto err;
1071 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1072 ret = PTR_ERR(inode);
1073 if (IS_ERR(inode))
1074 goto err;
1075 ret = -ENOMEM;
1076 state = nfs4_get_open_state(inode, data->owner);
1077 if (state == NULL)
1078 goto err_put_inode;
1079 if (data->o_res.delegation_type != 0) {
1080 int delegation_flags = 0;
1082 rcu_read_lock();
1083 delegation = rcu_dereference(NFS_I(inode)->delegation);
1084 if (delegation)
1085 delegation_flags = delegation->flags;
1086 rcu_read_unlock();
1087 if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1088 nfs_inode_set_delegation(state->inode,
1089 data->owner->so_cred,
1090 &data->o_res);
1091 else
1092 nfs_inode_reclaim_delegation(state->inode,
1093 data->owner->so_cred,
1094 &data->o_res);
1097 update_open_stateid(state, &data->o_res.stateid, NULL,
1098 data->o_arg.fmode);
1099 iput(inode);
1100 out:
1101 return state;
1102 err_put_inode:
1103 iput(inode);
1104 err:
1105 return ERR_PTR(ret);
1108 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1110 struct nfs_inode *nfsi = NFS_I(state->inode);
1111 struct nfs_open_context *ctx;
1113 spin_lock(&state->inode->i_lock);
1114 list_for_each_entry(ctx, &nfsi->open_files, list) {
1115 if (ctx->state != state)
1116 continue;
1117 get_nfs_open_context(ctx);
1118 spin_unlock(&state->inode->i_lock);
1119 return ctx;
1121 spin_unlock(&state->inode->i_lock);
1122 return ERR_PTR(-ENOENT);
1125 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
1127 struct nfs4_opendata *opendata;
1129 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS);
1130 if (opendata == NULL)
1131 return ERR_PTR(-ENOMEM);
1132 opendata->state = state;
1133 atomic_inc(&state->count);
1134 return opendata;
1137 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1139 struct nfs4_state *newstate;
1140 int ret;
1142 opendata->o_arg.open_flags = 0;
1143 opendata->o_arg.fmode = fmode;
1144 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1145 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1146 nfs4_init_opendata_res(opendata);
1147 ret = _nfs4_recover_proc_open(opendata);
1148 if (ret != 0)
1149 return ret;
1150 newstate = nfs4_opendata_to_nfs4_state(opendata);
1151 if (IS_ERR(newstate))
1152 return PTR_ERR(newstate);
1153 nfs4_close_state(&opendata->path, newstate, fmode);
1154 *res = newstate;
1155 return 0;
1158 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1160 struct nfs4_state *newstate;
1161 int ret;
1163 /* memory barrier prior to reading state->n_* */
1164 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1165 smp_rmb();
1166 if (state->n_rdwr != 0) {
1167 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1168 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1169 if (ret != 0)
1170 return ret;
1171 if (newstate != state)
1172 return -ESTALE;
1174 if (state->n_wronly != 0) {
1175 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1176 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1177 if (ret != 0)
1178 return ret;
1179 if (newstate != state)
1180 return -ESTALE;
1182 if (state->n_rdonly != 0) {
1183 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1184 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1185 if (ret != 0)
1186 return ret;
1187 if (newstate != state)
1188 return -ESTALE;
1191 * We may have performed cached opens for all three recoveries.
1192 * Check if we need to update the current stateid.
1194 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1195 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
1196 write_seqlock(&state->seqlock);
1197 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1198 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
1199 write_sequnlock(&state->seqlock);
1201 return 0;
1205 * OPEN_RECLAIM:
1206 * reclaim state on the server after a reboot.
1208 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1210 struct nfs_delegation *delegation;
1211 struct nfs4_opendata *opendata;
1212 fmode_t delegation_type = 0;
1213 int status;
1215 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1216 if (IS_ERR(opendata))
1217 return PTR_ERR(opendata);
1218 opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
1219 opendata->o_arg.fh = NFS_FH(state->inode);
1220 rcu_read_lock();
1221 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1222 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1223 delegation_type = delegation->type;
1224 rcu_read_unlock();
1225 opendata->o_arg.u.delegation_type = delegation_type;
1226 status = nfs4_open_recover(opendata, state);
1227 nfs4_opendata_put(opendata);
1228 return status;
1231 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1233 struct nfs_server *server = NFS_SERVER(state->inode);
1234 struct nfs4_exception exception = { };
1235 int err;
1236 do {
1237 err = _nfs4_do_open_reclaim(ctx, state);
1238 if (err != -NFS4ERR_DELAY)
1239 break;
1240 nfs4_handle_exception(server, err, &exception);
1241 } while (exception.retry);
1242 return err;
1245 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1247 struct nfs_open_context *ctx;
1248 int ret;
1250 ctx = nfs4_state_find_open_context(state);
1251 if (IS_ERR(ctx))
1252 return PTR_ERR(ctx);
1253 ret = nfs4_do_open_reclaim(ctx, state);
1254 put_nfs_open_context(ctx);
1255 return ret;
1258 static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1260 struct nfs4_opendata *opendata;
1261 int ret;
1263 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1264 if (IS_ERR(opendata))
1265 return PTR_ERR(opendata);
1266 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1267 memcpy(opendata->o_arg.u.delegation.data, stateid->data,
1268 sizeof(opendata->o_arg.u.delegation.data));
1269 ret = nfs4_open_recover(opendata, state);
1270 nfs4_opendata_put(opendata);
1271 return ret;
1274 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1276 struct nfs4_exception exception = { };
1277 struct nfs_server *server = NFS_SERVER(state->inode);
1278 int err;
1279 do {
1280 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1281 switch (err) {
1282 case 0:
1283 case -ENOENT:
1284 case -ESTALE:
1285 goto out;
1286 case -NFS4ERR_BADSESSION:
1287 case -NFS4ERR_BADSLOT:
1288 case -NFS4ERR_BAD_HIGH_SLOT:
1289 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1290 case -NFS4ERR_DEADSESSION:
1291 nfs4_schedule_session_recovery(server->nfs_client->cl_session);
1292 goto out;
1293 case -NFS4ERR_STALE_CLIENTID:
1294 case -NFS4ERR_STALE_STATEID:
1295 case -NFS4ERR_EXPIRED:
1296 /* Don't recall a delegation if it was lost */
1297 nfs4_schedule_lease_recovery(server->nfs_client);
1298 goto out;
1299 case -ERESTARTSYS:
1301 * The show must go on: exit, but mark the
1302 * stateid as needing recovery.
1304 case -NFS4ERR_ADMIN_REVOKED:
1305 case -NFS4ERR_BAD_STATEID:
1306 nfs4_schedule_stateid_recovery(server, state);
1307 case -EKEYEXPIRED:
1309 * User RPCSEC_GSS context has expired.
1310 * We cannot recover this stateid now, so
1311 * skip it and allow recovery thread to
1312 * proceed.
1314 case -ENOMEM:
1315 err = 0;
1316 goto out;
1318 err = nfs4_handle_exception(server, err, &exception);
1319 } while (exception.retry);
1320 out:
1321 return err;
1324 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1326 struct nfs4_opendata *data = calldata;
1328 data->rpc_status = task->tk_status;
1329 if (data->rpc_status == 0) {
1330 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
1331 sizeof(data->o_res.stateid.data));
1332 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1333 renew_lease(data->o_res.server, data->timestamp);
1334 data->rpc_done = 1;
1338 static void nfs4_open_confirm_release(void *calldata)
1340 struct nfs4_opendata *data = calldata;
1341 struct nfs4_state *state = NULL;
1343 /* If this request hasn't been cancelled, do nothing */
1344 if (data->cancelled == 0)
1345 goto out_free;
1346 /* In case of error, no cleanup! */
1347 if (!data->rpc_done)
1348 goto out_free;
1349 state = nfs4_opendata_to_nfs4_state(data);
1350 if (!IS_ERR(state))
1351 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1352 out_free:
1353 nfs4_opendata_put(data);
1356 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1357 .rpc_call_done = nfs4_open_confirm_done,
1358 .rpc_release = nfs4_open_confirm_release,
1362 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1364 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1366 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1367 struct rpc_task *task;
1368 struct rpc_message msg = {
1369 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1370 .rpc_argp = &data->c_arg,
1371 .rpc_resp = &data->c_res,
1372 .rpc_cred = data->owner->so_cred,
1374 struct rpc_task_setup task_setup_data = {
1375 .rpc_client = server->client,
1376 .rpc_message = &msg,
1377 .callback_ops = &nfs4_open_confirm_ops,
1378 .callback_data = data,
1379 .workqueue = nfsiod_workqueue,
1380 .flags = RPC_TASK_ASYNC,
1382 int status;
1384 kref_get(&data->kref);
1385 data->rpc_done = 0;
1386 data->rpc_status = 0;
1387 data->timestamp = jiffies;
1388 task = rpc_run_task(&task_setup_data);
1389 if (IS_ERR(task))
1390 return PTR_ERR(task);
1391 status = nfs4_wait_for_completion_rpc_task(task);
1392 if (status != 0) {
1393 data->cancelled = 1;
1394 smp_wmb();
1395 } else
1396 status = data->rpc_status;
1397 rpc_put_task(task);
1398 return status;
1401 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1403 struct nfs4_opendata *data = calldata;
1404 struct nfs4_state_owner *sp = data->owner;
1406 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1407 return;
1409 * Check if we still need to send an OPEN call, or if we can use
1410 * a delegation instead.
1412 if (data->state != NULL) {
1413 struct nfs_delegation *delegation;
1415 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1416 goto out_no_action;
1417 rcu_read_lock();
1418 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1419 if (delegation != NULL &&
1420 test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) {
1421 rcu_read_unlock();
1422 goto out_no_action;
1424 rcu_read_unlock();
1426 /* Update sequence id. */
1427 data->o_arg.id = sp->so_owner_id.id;
1428 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1429 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1430 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1431 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1433 data->timestamp = jiffies;
1434 if (nfs4_setup_sequence(data->o_arg.server,
1435 &data->o_arg.seq_args,
1436 &data->o_res.seq_res, 1, task))
1437 return;
1438 rpc_call_start(task);
1439 return;
1440 out_no_action:
1441 task->tk_action = NULL;
1445 static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1447 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1448 nfs4_open_prepare(task, calldata);
1451 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1453 struct nfs4_opendata *data = calldata;
1455 data->rpc_status = task->tk_status;
1457 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1458 return;
1460 if (task->tk_status == 0) {
1461 switch (data->o_res.f_attr->mode & S_IFMT) {
1462 case S_IFREG:
1463 break;
1464 case S_IFLNK:
1465 data->rpc_status = -ELOOP;
1466 break;
1467 case S_IFDIR:
1468 data->rpc_status = -EISDIR;
1469 break;
1470 default:
1471 data->rpc_status = -ENOTDIR;
1473 renew_lease(data->o_res.server, data->timestamp);
1474 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1475 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1477 data->rpc_done = 1;
1480 static void nfs4_open_release(void *calldata)
1482 struct nfs4_opendata *data = calldata;
1483 struct nfs4_state *state = NULL;
1485 /* If this request hasn't been cancelled, do nothing */
1486 if (data->cancelled == 0)
1487 goto out_free;
1488 /* In case of error, no cleanup! */
1489 if (data->rpc_status != 0 || !data->rpc_done)
1490 goto out_free;
1491 /* In case we need an open_confirm, no cleanup! */
1492 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1493 goto out_free;
1494 state = nfs4_opendata_to_nfs4_state(data);
1495 if (!IS_ERR(state))
1496 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1497 out_free:
1498 nfs4_opendata_put(data);
1501 static const struct rpc_call_ops nfs4_open_ops = {
1502 .rpc_call_prepare = nfs4_open_prepare,
1503 .rpc_call_done = nfs4_open_done,
1504 .rpc_release = nfs4_open_release,
1507 static const struct rpc_call_ops nfs4_recover_open_ops = {
1508 .rpc_call_prepare = nfs4_recover_open_prepare,
1509 .rpc_call_done = nfs4_open_done,
1510 .rpc_release = nfs4_open_release,
1513 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1515 struct inode *dir = data->dir->d_inode;
1516 struct nfs_server *server = NFS_SERVER(dir);
1517 struct nfs_openargs *o_arg = &data->o_arg;
1518 struct nfs_openres *o_res = &data->o_res;
1519 struct rpc_task *task;
1520 struct rpc_message msg = {
1521 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1522 .rpc_argp = o_arg,
1523 .rpc_resp = o_res,
1524 .rpc_cred = data->owner->so_cred,
1526 struct rpc_task_setup task_setup_data = {
1527 .rpc_client = server->client,
1528 .rpc_message = &msg,
1529 .callback_ops = &nfs4_open_ops,
1530 .callback_data = data,
1531 .workqueue = nfsiod_workqueue,
1532 .flags = RPC_TASK_ASYNC,
1534 int status;
1536 kref_get(&data->kref);
1537 data->rpc_done = 0;
1538 data->rpc_status = 0;
1539 data->cancelled = 0;
1540 if (isrecover)
1541 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1542 task = rpc_run_task(&task_setup_data);
1543 if (IS_ERR(task))
1544 return PTR_ERR(task);
1545 status = nfs4_wait_for_completion_rpc_task(task);
1546 if (status != 0) {
1547 data->cancelled = 1;
1548 smp_wmb();
1549 } else
1550 status = data->rpc_status;
1551 rpc_put_task(task);
1553 return status;
1556 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1558 struct inode *dir = data->dir->d_inode;
1559 struct nfs_openres *o_res = &data->o_res;
1560 int status;
1562 status = nfs4_run_open_task(data, 1);
1563 if (status != 0 || !data->rpc_done)
1564 return status;
1566 nfs_refresh_inode(dir, o_res->dir_attr);
1568 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1569 status = _nfs4_proc_open_confirm(data);
1570 if (status != 0)
1571 return status;
1574 return status;
1578 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1580 static int _nfs4_proc_open(struct nfs4_opendata *data)
1582 struct inode *dir = data->dir->d_inode;
1583 struct nfs_server *server = NFS_SERVER(dir);
1584 struct nfs_openargs *o_arg = &data->o_arg;
1585 struct nfs_openres *o_res = &data->o_res;
1586 int status;
1588 status = nfs4_run_open_task(data, 0);
1589 if (status != 0 || !data->rpc_done)
1590 return status;
1592 if (o_arg->open_flags & O_CREAT) {
1593 update_changeattr(dir, &o_res->cinfo);
1594 nfs_post_op_update_inode(dir, o_res->dir_attr);
1595 } else
1596 nfs_refresh_inode(dir, o_res->dir_attr);
1597 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1598 server->caps &= ~NFS_CAP_POSIX_LOCK;
1599 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1600 status = _nfs4_proc_open_confirm(data);
1601 if (status != 0)
1602 return status;
1604 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1605 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1606 return 0;
1609 static int nfs4_client_recover_expired_lease(struct nfs_client *clp)
1611 unsigned int loop;
1612 int ret;
1614 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1615 ret = nfs4_wait_clnt_recover(clp);
1616 if (ret != 0)
1617 break;
1618 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1619 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1620 break;
1621 nfs4_schedule_state_manager(clp);
1622 ret = -EIO;
1624 return ret;
1627 static int nfs4_recover_expired_lease(struct nfs_server *server)
1629 return nfs4_client_recover_expired_lease(server->nfs_client);
1633 * OPEN_EXPIRED:
1634 * reclaim state on the server after a network partition.
1635 * Assumes caller holds the appropriate lock
1637 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1639 struct nfs4_opendata *opendata;
1640 int ret;
1642 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1643 if (IS_ERR(opendata))
1644 return PTR_ERR(opendata);
1645 ret = nfs4_open_recover(opendata, state);
1646 if (ret == -ESTALE)
1647 d_drop(ctx->path.dentry);
1648 nfs4_opendata_put(opendata);
1649 return ret;
1652 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1654 struct nfs_server *server = NFS_SERVER(state->inode);
1655 struct nfs4_exception exception = { };
1656 int err;
1658 do {
1659 err = _nfs4_open_expired(ctx, state);
1660 switch (err) {
1661 default:
1662 goto out;
1663 case -NFS4ERR_GRACE:
1664 case -NFS4ERR_DELAY:
1665 nfs4_handle_exception(server, err, &exception);
1666 err = 0;
1668 } while (exception.retry);
1669 out:
1670 return err;
1673 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1675 struct nfs_open_context *ctx;
1676 int ret;
1678 ctx = nfs4_state_find_open_context(state);
1679 if (IS_ERR(ctx))
1680 return PTR_ERR(ctx);
1681 ret = nfs4_do_open_expired(ctx, state);
1682 put_nfs_open_context(ctx);
1683 return ret;
1687 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1688 * fields corresponding to attributes that were used to store the verifier.
1689 * Make sure we clobber those fields in the later setattr call
1691 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1693 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1694 !(sattr->ia_valid & ATTR_ATIME_SET))
1695 sattr->ia_valid |= ATTR_ATIME;
1697 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1698 !(sattr->ia_valid & ATTR_MTIME_SET))
1699 sattr->ia_valid |= ATTR_MTIME;
1703 * Returns a referenced nfs4_state
1705 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)
1707 struct nfs4_state_owner *sp;
1708 struct nfs4_state *state = NULL;
1709 struct nfs_server *server = NFS_SERVER(dir);
1710 struct nfs4_opendata *opendata;
1711 int status;
1713 /* Protect against reboot recovery conflicts */
1714 status = -ENOMEM;
1715 if (!(sp = nfs4_get_state_owner(server, cred))) {
1716 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1717 goto out_err;
1719 status = nfs4_recover_expired_lease(server);
1720 if (status != 0)
1721 goto err_put_state_owner;
1722 if (path->dentry->d_inode != NULL)
1723 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
1724 status = -ENOMEM;
1725 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL);
1726 if (opendata == NULL)
1727 goto err_put_state_owner;
1729 if (path->dentry->d_inode != NULL)
1730 opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp);
1732 status = _nfs4_proc_open(opendata);
1733 if (status != 0)
1734 goto err_opendata_put;
1736 state = nfs4_opendata_to_nfs4_state(opendata);
1737 status = PTR_ERR(state);
1738 if (IS_ERR(state))
1739 goto err_opendata_put;
1740 if (server->caps & NFS_CAP_POSIX_LOCK)
1741 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1743 if (opendata->o_arg.open_flags & O_EXCL) {
1744 nfs4_exclusive_attrset(opendata, sattr);
1746 nfs_fattr_init(opendata->o_res.f_attr);
1747 status = nfs4_do_setattr(state->inode, cred,
1748 opendata->o_res.f_attr, sattr,
1749 state);
1750 if (status == 0)
1751 nfs_setattr_update_inode(state->inode, sattr);
1752 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
1754 nfs4_opendata_put(opendata);
1755 nfs4_put_state_owner(sp);
1756 *res = state;
1757 return 0;
1758 err_opendata_put:
1759 nfs4_opendata_put(opendata);
1760 err_put_state_owner:
1761 nfs4_put_state_owner(sp);
1762 out_err:
1763 *res = NULL;
1764 return status;
1768 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)
1770 struct nfs4_exception exception = { };
1771 struct nfs4_state *res;
1772 int status;
1774 do {
1775 status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res);
1776 if (status == 0)
1777 break;
1778 /* NOTE: BAD_SEQID means the server and client disagree about the
1779 * book-keeping w.r.t. state-changing operations
1780 * (OPEN/CLOSE/LOCK/LOCKU...)
1781 * It is actually a sign of a bug on the client or on the server.
1783 * If we receive a BAD_SEQID error in the particular case of
1784 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1785 * have unhashed the old state_owner for us, and that we can
1786 * therefore safely retry using a new one. We should still warn
1787 * the user though...
1789 if (status == -NFS4ERR_BAD_SEQID) {
1790 printk(KERN_WARNING "NFS: v4 server %s "
1791 " returned a bad sequence-id error!\n",
1792 NFS_SERVER(dir)->nfs_client->cl_hostname);
1793 exception.retry = 1;
1794 continue;
1797 * BAD_STATEID on OPEN means that the server cancelled our
1798 * state before it received the OPEN_CONFIRM.
1799 * Recover by retrying the request as per the discussion
1800 * on Page 181 of RFC3530.
1802 if (status == -NFS4ERR_BAD_STATEID) {
1803 exception.retry = 1;
1804 continue;
1806 if (status == -EAGAIN) {
1807 /* We must have found a delegation */
1808 exception.retry = 1;
1809 continue;
1811 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
1812 status, &exception));
1813 } while (exception.retry);
1814 return res;
1817 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1818 struct nfs_fattr *fattr, struct iattr *sattr,
1819 struct nfs4_state *state)
1821 struct nfs_server *server = NFS_SERVER(inode);
1822 struct nfs_setattrargs arg = {
1823 .fh = NFS_FH(inode),
1824 .iap = sattr,
1825 .server = server,
1826 .bitmask = server->attr_bitmask,
1828 struct nfs_setattrres res = {
1829 .fattr = fattr,
1830 .server = server,
1832 struct rpc_message msg = {
1833 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
1834 .rpc_argp = &arg,
1835 .rpc_resp = &res,
1836 .rpc_cred = cred,
1838 unsigned long timestamp = jiffies;
1839 int status;
1841 nfs_fattr_init(fattr);
1843 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1844 /* Use that stateid */
1845 } else if (state != NULL) {
1846 nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid);
1847 } else
1848 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
1850 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
1851 if (status == 0 && state != NULL)
1852 renew_lease(server, timestamp);
1853 return status;
1856 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1857 struct nfs_fattr *fattr, struct iattr *sattr,
1858 struct nfs4_state *state)
1860 struct nfs_server *server = NFS_SERVER(inode);
1861 struct nfs4_exception exception = { };
1862 int err;
1863 do {
1864 err = nfs4_handle_exception(server,
1865 _nfs4_do_setattr(inode, cred, fattr, sattr, state),
1866 &exception);
1867 } while (exception.retry);
1868 return err;
1871 struct nfs4_closedata {
1872 struct path path;
1873 struct inode *inode;
1874 struct nfs4_state *state;
1875 struct nfs_closeargs arg;
1876 struct nfs_closeres res;
1877 struct nfs_fattr fattr;
1878 unsigned long timestamp;
1879 bool roc;
1880 u32 roc_barrier;
1883 static void nfs4_free_closedata(void *data)
1885 struct nfs4_closedata *calldata = data;
1886 struct nfs4_state_owner *sp = calldata->state->owner;
1888 if (calldata->roc)
1889 pnfs_roc_release(calldata->state->inode);
1890 nfs4_put_open_state(calldata->state);
1891 nfs_free_seqid(calldata->arg.seqid);
1892 nfs4_put_state_owner(sp);
1893 path_put(&calldata->path);
1894 kfree(calldata);
1897 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
1898 fmode_t fmode)
1900 spin_lock(&state->owner->so_lock);
1901 if (!(fmode & FMODE_READ))
1902 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1903 if (!(fmode & FMODE_WRITE))
1904 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1905 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1906 spin_unlock(&state->owner->so_lock);
1909 static void nfs4_close_done(struct rpc_task *task, void *data)
1911 struct nfs4_closedata *calldata = data;
1912 struct nfs4_state *state = calldata->state;
1913 struct nfs_server *server = NFS_SERVER(calldata->inode);
1915 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
1916 return;
1917 /* hmm. we are done with the inode, and in the process of freeing
1918 * the state_owner. we keep this around to process errors
1920 switch (task->tk_status) {
1921 case 0:
1922 if (calldata->roc)
1923 pnfs_roc_set_barrier(state->inode,
1924 calldata->roc_barrier);
1925 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
1926 renew_lease(server, calldata->timestamp);
1927 nfs4_close_clear_stateid_flags(state,
1928 calldata->arg.fmode);
1929 break;
1930 case -NFS4ERR_STALE_STATEID:
1931 case -NFS4ERR_OLD_STATEID:
1932 case -NFS4ERR_BAD_STATEID:
1933 case -NFS4ERR_EXPIRED:
1934 if (calldata->arg.fmode == 0)
1935 break;
1936 default:
1937 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
1938 rpc_restart_call_prepare(task);
1940 nfs_release_seqid(calldata->arg.seqid);
1941 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
1944 static void nfs4_close_prepare(struct rpc_task *task, void *data)
1946 struct nfs4_closedata *calldata = data;
1947 struct nfs4_state *state = calldata->state;
1948 int call_close = 0;
1950 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1951 return;
1953 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
1954 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
1955 spin_lock(&state->owner->so_lock);
1956 /* Calculate the change in open mode */
1957 if (state->n_rdwr == 0) {
1958 if (state->n_rdonly == 0) {
1959 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
1960 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1961 calldata->arg.fmode &= ~FMODE_READ;
1963 if (state->n_wronly == 0) {
1964 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
1965 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1966 calldata->arg.fmode &= ~FMODE_WRITE;
1969 spin_unlock(&state->owner->so_lock);
1971 if (!call_close) {
1972 /* Note: exit _without_ calling nfs4_close_done */
1973 task->tk_action = NULL;
1974 return;
1977 if (calldata->arg.fmode == 0) {
1978 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
1979 if (calldata->roc &&
1980 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) {
1981 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq,
1982 task, NULL);
1983 return;
1987 nfs_fattr_init(calldata->res.fattr);
1988 calldata->timestamp = jiffies;
1989 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode),
1990 &calldata->arg.seq_args, &calldata->res.seq_res,
1991 1, task))
1992 return;
1993 rpc_call_start(task);
1996 static const struct rpc_call_ops nfs4_close_ops = {
1997 .rpc_call_prepare = nfs4_close_prepare,
1998 .rpc_call_done = nfs4_close_done,
1999 .rpc_release = nfs4_free_closedata,
2003 * It is possible for data to be read/written from a mem-mapped file
2004 * after the sys_close call (which hits the vfs layer as a flush).
2005 * This means that we can't safely call nfsv4 close on a file until
2006 * the inode is cleared. This in turn means that we are not good
2007 * NFSv4 citizens - we do not indicate to the server to update the file's
2008 * share state even when we are done with one of the three share
2009 * stateid's in the inode.
2011 * NOTE: Caller must be holding the sp->so_owner semaphore!
2013 int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc)
2015 struct nfs_server *server = NFS_SERVER(state->inode);
2016 struct nfs4_closedata *calldata;
2017 struct nfs4_state_owner *sp = state->owner;
2018 struct rpc_task *task;
2019 struct rpc_message msg = {
2020 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2021 .rpc_cred = state->owner->so_cred,
2023 struct rpc_task_setup task_setup_data = {
2024 .rpc_client = server->client,
2025 .rpc_message = &msg,
2026 .callback_ops = &nfs4_close_ops,
2027 .workqueue = nfsiod_workqueue,
2028 .flags = RPC_TASK_ASYNC,
2030 int status = -ENOMEM;
2032 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2033 if (calldata == NULL)
2034 goto out;
2035 calldata->inode = state->inode;
2036 calldata->state = state;
2037 calldata->arg.fh = NFS_FH(state->inode);
2038 calldata->arg.stateid = &state->open_stateid;
2039 /* Serialization for the sequence id */
2040 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2041 if (calldata->arg.seqid == NULL)
2042 goto out_free_calldata;
2043 calldata->arg.fmode = 0;
2044 calldata->arg.bitmask = server->cache_consistency_bitmask;
2045 calldata->res.fattr = &calldata->fattr;
2046 calldata->res.seqid = calldata->arg.seqid;
2047 calldata->res.server = server;
2048 calldata->roc = roc;
2049 path_get(path);
2050 calldata->path = *path;
2052 msg.rpc_argp = &calldata->arg;
2053 msg.rpc_resp = &calldata->res;
2054 task_setup_data.callback_data = calldata;
2055 task = rpc_run_task(&task_setup_data);
2056 if (IS_ERR(task))
2057 return PTR_ERR(task);
2058 status = 0;
2059 if (wait)
2060 status = rpc_wait_for_completion_task(task);
2061 rpc_put_task(task);
2062 return status;
2063 out_free_calldata:
2064 kfree(calldata);
2065 out:
2066 if (roc)
2067 pnfs_roc_release(state->inode);
2068 nfs4_put_open_state(state);
2069 nfs4_put_state_owner(sp);
2070 return status;
2073 static struct inode *
2074 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
2076 struct nfs4_state *state;
2078 /* Protect against concurrent sillydeletes */
2079 state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred);
2080 if (IS_ERR(state))
2081 return ERR_CAST(state);
2082 ctx->state = state;
2083 return igrab(state->inode);
2086 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2088 if (ctx->state == NULL)
2089 return;
2090 if (is_sync)
2091 nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
2092 else
2093 nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
2096 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2098 struct nfs4_server_caps_arg args = {
2099 .fhandle = fhandle,
2101 struct nfs4_server_caps_res res = {};
2102 struct rpc_message msg = {
2103 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2104 .rpc_argp = &args,
2105 .rpc_resp = &res,
2107 int status;
2109 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2110 if (status == 0) {
2111 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2112 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2113 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2114 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2115 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2116 NFS_CAP_CTIME|NFS_CAP_MTIME);
2117 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2118 server->caps |= NFS_CAP_ACLS;
2119 if (res.has_links != 0)
2120 server->caps |= NFS_CAP_HARDLINKS;
2121 if (res.has_symlinks != 0)
2122 server->caps |= NFS_CAP_SYMLINKS;
2123 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2124 server->caps |= NFS_CAP_FILEID;
2125 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2126 server->caps |= NFS_CAP_MODE;
2127 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2128 server->caps |= NFS_CAP_NLINK;
2129 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2130 server->caps |= NFS_CAP_OWNER;
2131 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2132 server->caps |= NFS_CAP_OWNER_GROUP;
2133 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2134 server->caps |= NFS_CAP_ATIME;
2135 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2136 server->caps |= NFS_CAP_CTIME;
2137 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2138 server->caps |= NFS_CAP_MTIME;
2140 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2141 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2142 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2143 server->acl_bitmask = res.acl_bitmask;
2146 return status;
2149 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2151 struct nfs4_exception exception = { };
2152 int err;
2153 do {
2154 err = nfs4_handle_exception(server,
2155 _nfs4_server_capabilities(server, fhandle),
2156 &exception);
2157 } while (exception.retry);
2158 return err;
2161 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2162 struct nfs_fsinfo *info)
2164 struct nfs4_lookup_root_arg args = {
2165 .bitmask = nfs4_fattr_bitmap,
2167 struct nfs4_lookup_res res = {
2168 .server = server,
2169 .fattr = info->fattr,
2170 .fh = fhandle,
2172 struct rpc_message msg = {
2173 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2174 .rpc_argp = &args,
2175 .rpc_resp = &res,
2178 nfs_fattr_init(info->fattr);
2179 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2182 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2183 struct nfs_fsinfo *info)
2185 struct nfs4_exception exception = { };
2186 int err;
2187 do {
2188 err = nfs4_handle_exception(server,
2189 _nfs4_lookup_root(server, fhandle, info),
2190 &exception);
2191 } while (exception.retry);
2192 return err;
2195 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2196 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2198 struct rpc_auth *auth;
2199 int ret;
2201 auth = rpcauth_create(flavor, server->client);
2202 if (!auth) {
2203 ret = -EIO;
2204 goto out;
2206 ret = nfs4_lookup_root(server, fhandle, info);
2207 out:
2208 return ret;
2212 * get the file handle for the "/" directory on the server
2214 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2215 struct nfs_fsinfo *info)
2217 int i, len, status = 0;
2218 rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS + 2];
2220 flav_array[0] = RPC_AUTH_UNIX;
2221 len = gss_mech_list_pseudoflavors(&flav_array[1]);
2222 flav_array[1+len] = RPC_AUTH_NULL;
2223 len += 2;
2225 for (i = 0; i < len; i++) {
2226 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2227 if (status != -EPERM)
2228 break;
2230 if (status == 0)
2231 status = nfs4_server_capabilities(server, fhandle);
2232 if (status == 0)
2233 status = nfs4_do_fsinfo(server, fhandle, info);
2234 return nfs4_map_errors(status);
2238 * Get locations and (maybe) other attributes of a referral.
2239 * Note that we'll actually follow the referral later when
2240 * we detect fsid mismatch in inode revalidation
2242 static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
2244 int status = -ENOMEM;
2245 struct page *page = NULL;
2246 struct nfs4_fs_locations *locations = NULL;
2248 page = alloc_page(GFP_KERNEL);
2249 if (page == NULL)
2250 goto out;
2251 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2252 if (locations == NULL)
2253 goto out;
2255 status = nfs4_proc_fs_locations(dir, name, locations, page);
2256 if (status != 0)
2257 goto out;
2258 /* Make sure server returned a different fsid for the referral */
2259 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2260 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
2261 status = -EIO;
2262 goto out;
2265 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2266 fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
2267 if (!fattr->mode)
2268 fattr->mode = S_IFDIR;
2269 memset(fhandle, 0, sizeof(struct nfs_fh));
2270 out:
2271 if (page)
2272 __free_page(page);
2273 kfree(locations);
2274 return status;
2277 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2279 struct nfs4_getattr_arg args = {
2280 .fh = fhandle,
2281 .bitmask = server->attr_bitmask,
2283 struct nfs4_getattr_res res = {
2284 .fattr = fattr,
2285 .server = server,
2287 struct rpc_message msg = {
2288 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2289 .rpc_argp = &args,
2290 .rpc_resp = &res,
2293 nfs_fattr_init(fattr);
2294 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2297 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2299 struct nfs4_exception exception = { };
2300 int err;
2301 do {
2302 err = nfs4_handle_exception(server,
2303 _nfs4_proc_getattr(server, fhandle, fattr),
2304 &exception);
2305 } while (exception.retry);
2306 return err;
2310 * The file is not closed if it is opened due to the a request to change
2311 * the size of the file. The open call will not be needed once the
2312 * VFS layer lookup-intents are implemented.
2314 * Close is called when the inode is destroyed.
2315 * If we haven't opened the file for O_WRONLY, we
2316 * need to in the size_change case to obtain a stateid.
2318 * Got race?
2319 * Because OPEN is always done by name in nfsv4, it is
2320 * possible that we opened a different file by the same
2321 * name. We can recognize this race condition, but we
2322 * can't do anything about it besides returning an error.
2324 * This will be fixed with VFS changes (lookup-intent).
2326 static int
2327 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2328 struct iattr *sattr)
2330 struct inode *inode = dentry->d_inode;
2331 struct rpc_cred *cred = NULL;
2332 struct nfs4_state *state = NULL;
2333 int status;
2335 nfs_fattr_init(fattr);
2337 /* Search for an existing open(O_WRITE) file */
2338 if (sattr->ia_valid & ATTR_FILE) {
2339 struct nfs_open_context *ctx;
2341 ctx = nfs_file_open_context(sattr->ia_file);
2342 if (ctx) {
2343 cred = ctx->cred;
2344 state = ctx->state;
2348 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2349 if (status == 0)
2350 nfs_setattr_update_inode(inode, sattr);
2351 return status;
2354 static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server,
2355 const struct nfs_fh *dirfh, const struct qstr *name,
2356 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2358 int status;
2359 struct nfs4_lookup_arg args = {
2360 .bitmask = server->attr_bitmask,
2361 .dir_fh = dirfh,
2362 .name = name,
2364 struct nfs4_lookup_res res = {
2365 .server = server,
2366 .fattr = fattr,
2367 .fh = fhandle,
2369 struct rpc_message msg = {
2370 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2371 .rpc_argp = &args,
2372 .rpc_resp = &res,
2375 nfs_fattr_init(fattr);
2377 dprintk("NFS call lookupfh %s\n", name->name);
2378 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
2379 dprintk("NFS reply lookupfh: %d\n", status);
2380 return status;
2383 static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh,
2384 struct qstr *name, struct nfs_fh *fhandle,
2385 struct nfs_fattr *fattr)
2387 struct nfs4_exception exception = { };
2388 int err;
2389 do {
2390 err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr);
2391 /* FIXME: !!!! */
2392 if (err == -NFS4ERR_MOVED) {
2393 err = -EREMOTE;
2394 break;
2396 err = nfs4_handle_exception(server, err, &exception);
2397 } while (exception.retry);
2398 return err;
2401 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
2402 const struct qstr *name, struct nfs_fh *fhandle,
2403 struct nfs_fattr *fattr)
2405 int status;
2407 dprintk("NFS call lookup %s\n", name->name);
2408 status = _nfs4_proc_lookupfh(clnt, NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr);
2409 if (status == -NFS4ERR_MOVED)
2410 status = nfs4_get_referral(dir, name, fattr, fhandle);
2411 dprintk("NFS reply lookup: %d\n", status);
2412 return status;
2415 void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh)
2417 memset(fh, 0, sizeof(struct nfs_fh));
2418 fattr->fsid.major = 1;
2419 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
2420 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT;
2421 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
2422 fattr->nlink = 2;
2425 static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name,
2426 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2428 struct nfs4_exception exception = { };
2429 int err;
2430 do {
2431 err = nfs4_handle_exception(NFS_SERVER(dir),
2432 _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr),
2433 &exception);
2434 if (err == -EPERM)
2435 nfs_fixup_secinfo_attributes(fattr, fhandle);
2436 } while (exception.retry);
2437 return err;
2440 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2442 struct nfs_server *server = NFS_SERVER(inode);
2443 struct nfs4_accessargs args = {
2444 .fh = NFS_FH(inode),
2445 .bitmask = server->attr_bitmask,
2447 struct nfs4_accessres res = {
2448 .server = server,
2450 struct rpc_message msg = {
2451 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2452 .rpc_argp = &args,
2453 .rpc_resp = &res,
2454 .rpc_cred = entry->cred,
2456 int mode = entry->mask;
2457 int status;
2460 * Determine which access bits we want to ask for...
2462 if (mode & MAY_READ)
2463 args.access |= NFS4_ACCESS_READ;
2464 if (S_ISDIR(inode->i_mode)) {
2465 if (mode & MAY_WRITE)
2466 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2467 if (mode & MAY_EXEC)
2468 args.access |= NFS4_ACCESS_LOOKUP;
2469 } else {
2470 if (mode & MAY_WRITE)
2471 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2472 if (mode & MAY_EXEC)
2473 args.access |= NFS4_ACCESS_EXECUTE;
2476 res.fattr = nfs_alloc_fattr();
2477 if (res.fattr == NULL)
2478 return -ENOMEM;
2480 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2481 if (!status) {
2482 entry->mask = 0;
2483 if (res.access & NFS4_ACCESS_READ)
2484 entry->mask |= MAY_READ;
2485 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
2486 entry->mask |= MAY_WRITE;
2487 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2488 entry->mask |= MAY_EXEC;
2489 nfs_refresh_inode(inode, res.fattr);
2491 nfs_free_fattr(res.fattr);
2492 return status;
2495 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2497 struct nfs4_exception exception = { };
2498 int err;
2499 do {
2500 err = nfs4_handle_exception(NFS_SERVER(inode),
2501 _nfs4_proc_access(inode, entry),
2502 &exception);
2503 } while (exception.retry);
2504 return err;
2508 * TODO: For the time being, we don't try to get any attributes
2509 * along with any of the zero-copy operations READ, READDIR,
2510 * READLINK, WRITE.
2512 * In the case of the first three, we want to put the GETATTR
2513 * after the read-type operation -- this is because it is hard
2514 * to predict the length of a GETATTR response in v4, and thus
2515 * align the READ data correctly. This means that the GETATTR
2516 * may end up partially falling into the page cache, and we should
2517 * shift it into the 'tail' of the xdr_buf before processing.
2518 * To do this efficiently, we need to know the total length
2519 * of data received, which doesn't seem to be available outside
2520 * of the RPC layer.
2522 * In the case of WRITE, we also want to put the GETATTR after
2523 * the operation -- in this case because we want to make sure
2524 * we get the post-operation mtime and size. This means that
2525 * we can't use xdr_encode_pages() as written: we need a variant
2526 * of it which would leave room in the 'tail' iovec.
2528 * Both of these changes to the XDR layer would in fact be quite
2529 * minor, but I decided to leave them for a subsequent patch.
2531 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2532 unsigned int pgbase, unsigned int pglen)
2534 struct nfs4_readlink args = {
2535 .fh = NFS_FH(inode),
2536 .pgbase = pgbase,
2537 .pglen = pglen,
2538 .pages = &page,
2540 struct nfs4_readlink_res res;
2541 struct rpc_message msg = {
2542 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2543 .rpc_argp = &args,
2544 .rpc_resp = &res,
2547 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
2550 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2551 unsigned int pgbase, unsigned int pglen)
2553 struct nfs4_exception exception = { };
2554 int err;
2555 do {
2556 err = nfs4_handle_exception(NFS_SERVER(inode),
2557 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2558 &exception);
2559 } while (exception.retry);
2560 return err;
2564 * Got race?
2565 * We will need to arrange for the VFS layer to provide an atomic open.
2566 * Until then, this create/open method is prone to inefficiency and race
2567 * conditions due to the lookup, create, and open VFS calls from sys_open()
2568 * placed on the wire.
2570 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2571 * The file will be opened again in the subsequent VFS open call
2572 * (nfs4_proc_file_open).
2574 * The open for read will just hang around to be used by any process that
2575 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2578 static int
2579 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2580 int flags, struct nfs_open_context *ctx)
2582 struct path my_path = {
2583 .dentry = dentry,
2585 struct path *path = &my_path;
2586 struct nfs4_state *state;
2587 struct rpc_cred *cred = NULL;
2588 fmode_t fmode = 0;
2589 int status = 0;
2591 if (ctx != NULL) {
2592 cred = ctx->cred;
2593 path = &ctx->path;
2594 fmode = ctx->mode;
2596 sattr->ia_mode &= ~current_umask();
2597 state = nfs4_do_open(dir, path, fmode, flags, sattr, cred);
2598 d_drop(dentry);
2599 if (IS_ERR(state)) {
2600 status = PTR_ERR(state);
2601 goto out;
2603 d_add(dentry, igrab(state->inode));
2604 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2605 if (ctx != NULL)
2606 ctx->state = state;
2607 else
2608 nfs4_close_sync(path, state, fmode);
2609 out:
2610 return status;
2613 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2615 struct nfs_server *server = NFS_SERVER(dir);
2616 struct nfs_removeargs args = {
2617 .fh = NFS_FH(dir),
2618 .name.len = name->len,
2619 .name.name = name->name,
2620 .bitmask = server->attr_bitmask,
2622 struct nfs_removeres res = {
2623 .server = server,
2625 struct rpc_message msg = {
2626 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2627 .rpc_argp = &args,
2628 .rpc_resp = &res,
2630 int status = -ENOMEM;
2632 res.dir_attr = nfs_alloc_fattr();
2633 if (res.dir_attr == NULL)
2634 goto out;
2636 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
2637 if (status == 0) {
2638 update_changeattr(dir, &res.cinfo);
2639 nfs_post_op_update_inode(dir, res.dir_attr);
2641 nfs_free_fattr(res.dir_attr);
2642 out:
2643 return status;
2646 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2648 struct nfs4_exception exception = { };
2649 int err;
2650 do {
2651 err = nfs4_handle_exception(NFS_SERVER(dir),
2652 _nfs4_proc_remove(dir, name),
2653 &exception);
2654 } while (exception.retry);
2655 return err;
2658 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2660 struct nfs_server *server = NFS_SERVER(dir);
2661 struct nfs_removeargs *args = msg->rpc_argp;
2662 struct nfs_removeres *res = msg->rpc_resp;
2664 args->bitmask = server->cache_consistency_bitmask;
2665 res->server = server;
2666 res->seq_res.sr_slot = NULL;
2667 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2670 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2672 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2674 if (!nfs4_sequence_done(task, &res->seq_res))
2675 return 0;
2676 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2677 return 0;
2678 update_changeattr(dir, &res->cinfo);
2679 nfs_post_op_update_inode(dir, res->dir_attr);
2680 return 1;
2683 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
2685 struct nfs_server *server = NFS_SERVER(dir);
2686 struct nfs_renameargs *arg = msg->rpc_argp;
2687 struct nfs_renameres *res = msg->rpc_resp;
2689 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
2690 arg->bitmask = server->attr_bitmask;
2691 res->server = server;
2694 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
2695 struct inode *new_dir)
2697 struct nfs_renameres *res = task->tk_msg.rpc_resp;
2699 if (!nfs4_sequence_done(task, &res->seq_res))
2700 return 0;
2701 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2702 return 0;
2704 update_changeattr(old_dir, &res->old_cinfo);
2705 nfs_post_op_update_inode(old_dir, res->old_fattr);
2706 update_changeattr(new_dir, &res->new_cinfo);
2707 nfs_post_op_update_inode(new_dir, res->new_fattr);
2708 return 1;
2711 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2712 struct inode *new_dir, struct qstr *new_name)
2714 struct nfs_server *server = NFS_SERVER(old_dir);
2715 struct nfs_renameargs arg = {
2716 .old_dir = NFS_FH(old_dir),
2717 .new_dir = NFS_FH(new_dir),
2718 .old_name = old_name,
2719 .new_name = new_name,
2720 .bitmask = server->attr_bitmask,
2722 struct nfs_renameres res = {
2723 .server = server,
2725 struct rpc_message msg = {
2726 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
2727 .rpc_argp = &arg,
2728 .rpc_resp = &res,
2730 int status = -ENOMEM;
2732 res.old_fattr = nfs_alloc_fattr();
2733 res.new_fattr = nfs_alloc_fattr();
2734 if (res.old_fattr == NULL || res.new_fattr == NULL)
2735 goto out;
2737 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2738 if (!status) {
2739 update_changeattr(old_dir, &res.old_cinfo);
2740 nfs_post_op_update_inode(old_dir, res.old_fattr);
2741 update_changeattr(new_dir, &res.new_cinfo);
2742 nfs_post_op_update_inode(new_dir, res.new_fattr);
2744 out:
2745 nfs_free_fattr(res.new_fattr);
2746 nfs_free_fattr(res.old_fattr);
2747 return status;
2750 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2751 struct inode *new_dir, struct qstr *new_name)
2753 struct nfs4_exception exception = { };
2754 int err;
2755 do {
2756 err = nfs4_handle_exception(NFS_SERVER(old_dir),
2757 _nfs4_proc_rename(old_dir, old_name,
2758 new_dir, new_name),
2759 &exception);
2760 } while (exception.retry);
2761 return err;
2764 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2766 struct nfs_server *server = NFS_SERVER(inode);
2767 struct nfs4_link_arg arg = {
2768 .fh = NFS_FH(inode),
2769 .dir_fh = NFS_FH(dir),
2770 .name = name,
2771 .bitmask = server->attr_bitmask,
2773 struct nfs4_link_res res = {
2774 .server = server,
2776 struct rpc_message msg = {
2777 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
2778 .rpc_argp = &arg,
2779 .rpc_resp = &res,
2781 int status = -ENOMEM;
2783 res.fattr = nfs_alloc_fattr();
2784 res.dir_attr = nfs_alloc_fattr();
2785 if (res.fattr == NULL || res.dir_attr == NULL)
2786 goto out;
2788 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2789 if (!status) {
2790 update_changeattr(dir, &res.cinfo);
2791 nfs_post_op_update_inode(dir, res.dir_attr);
2792 nfs_post_op_update_inode(inode, res.fattr);
2794 out:
2795 nfs_free_fattr(res.dir_attr);
2796 nfs_free_fattr(res.fattr);
2797 return status;
2800 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2802 struct nfs4_exception exception = { };
2803 int err;
2804 do {
2805 err = nfs4_handle_exception(NFS_SERVER(inode),
2806 _nfs4_proc_link(inode, dir, name),
2807 &exception);
2808 } while (exception.retry);
2809 return err;
2812 struct nfs4_createdata {
2813 struct rpc_message msg;
2814 struct nfs4_create_arg arg;
2815 struct nfs4_create_res res;
2816 struct nfs_fh fh;
2817 struct nfs_fattr fattr;
2818 struct nfs_fattr dir_fattr;
2821 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
2822 struct qstr *name, struct iattr *sattr, u32 ftype)
2824 struct nfs4_createdata *data;
2826 data = kzalloc(sizeof(*data), GFP_KERNEL);
2827 if (data != NULL) {
2828 struct nfs_server *server = NFS_SERVER(dir);
2830 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
2831 data->msg.rpc_argp = &data->arg;
2832 data->msg.rpc_resp = &data->res;
2833 data->arg.dir_fh = NFS_FH(dir);
2834 data->arg.server = server;
2835 data->arg.name = name;
2836 data->arg.attrs = sattr;
2837 data->arg.ftype = ftype;
2838 data->arg.bitmask = server->attr_bitmask;
2839 data->res.server = server;
2840 data->res.fh = &data->fh;
2841 data->res.fattr = &data->fattr;
2842 data->res.dir_fattr = &data->dir_fattr;
2843 nfs_fattr_init(data->res.fattr);
2844 nfs_fattr_init(data->res.dir_fattr);
2846 return data;
2849 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
2851 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
2852 &data->arg.seq_args, &data->res.seq_res, 1);
2853 if (status == 0) {
2854 update_changeattr(dir, &data->res.dir_cinfo);
2855 nfs_post_op_update_inode(dir, data->res.dir_fattr);
2856 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
2858 return status;
2861 static void nfs4_free_createdata(struct nfs4_createdata *data)
2863 kfree(data);
2866 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2867 struct page *page, unsigned int len, struct iattr *sattr)
2869 struct nfs4_createdata *data;
2870 int status = -ENAMETOOLONG;
2872 if (len > NFS4_MAXPATHLEN)
2873 goto out;
2875 status = -ENOMEM;
2876 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
2877 if (data == NULL)
2878 goto out;
2880 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
2881 data->arg.u.symlink.pages = &page;
2882 data->arg.u.symlink.len = len;
2884 status = nfs4_do_create(dir, dentry, data);
2886 nfs4_free_createdata(data);
2887 out:
2888 return status;
2891 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2892 struct page *page, unsigned int len, struct iattr *sattr)
2894 struct nfs4_exception exception = { };
2895 int err;
2896 do {
2897 err = nfs4_handle_exception(NFS_SERVER(dir),
2898 _nfs4_proc_symlink(dir, dentry, page,
2899 len, sattr),
2900 &exception);
2901 } while (exception.retry);
2902 return err;
2905 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2906 struct iattr *sattr)
2908 struct nfs4_createdata *data;
2909 int status = -ENOMEM;
2911 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
2912 if (data == NULL)
2913 goto out;
2915 status = nfs4_do_create(dir, dentry, data);
2917 nfs4_free_createdata(data);
2918 out:
2919 return status;
2922 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2923 struct iattr *sattr)
2925 struct nfs4_exception exception = { };
2926 int err;
2928 sattr->ia_mode &= ~current_umask();
2929 do {
2930 err = nfs4_handle_exception(NFS_SERVER(dir),
2931 _nfs4_proc_mkdir(dir, dentry, sattr),
2932 &exception);
2933 } while (exception.retry);
2934 return err;
2937 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2938 u64 cookie, struct page **pages, unsigned int count, int plus)
2940 struct inode *dir = dentry->d_inode;
2941 struct nfs4_readdir_arg args = {
2942 .fh = NFS_FH(dir),
2943 .pages = pages,
2944 .pgbase = 0,
2945 .count = count,
2946 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2947 .plus = plus,
2949 struct nfs4_readdir_res res;
2950 struct rpc_message msg = {
2951 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
2952 .rpc_argp = &args,
2953 .rpc_resp = &res,
2954 .rpc_cred = cred,
2956 int status;
2958 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
2959 dentry->d_parent->d_name.name,
2960 dentry->d_name.name,
2961 (unsigned long long)cookie);
2962 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2963 res.pgbase = args.pgbase;
2964 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
2965 if (status >= 0) {
2966 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2967 status += args.pgbase;
2970 nfs_invalidate_atime(dir);
2972 dprintk("%s: returns %d\n", __func__, status);
2973 return status;
2976 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2977 u64 cookie, struct page **pages, unsigned int count, int plus)
2979 struct nfs4_exception exception = { };
2980 int err;
2981 do {
2982 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2983 _nfs4_proc_readdir(dentry, cred, cookie,
2984 pages, count, plus),
2985 &exception);
2986 } while (exception.retry);
2987 return err;
2990 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2991 struct iattr *sattr, dev_t rdev)
2993 struct nfs4_createdata *data;
2994 int mode = sattr->ia_mode;
2995 int status = -ENOMEM;
2997 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2998 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
3000 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3001 if (data == NULL)
3002 goto out;
3004 if (S_ISFIFO(mode))
3005 data->arg.ftype = NF4FIFO;
3006 else if (S_ISBLK(mode)) {
3007 data->arg.ftype = NF4BLK;
3008 data->arg.u.device.specdata1 = MAJOR(rdev);
3009 data->arg.u.device.specdata2 = MINOR(rdev);
3011 else if (S_ISCHR(mode)) {
3012 data->arg.ftype = NF4CHR;
3013 data->arg.u.device.specdata1 = MAJOR(rdev);
3014 data->arg.u.device.specdata2 = MINOR(rdev);
3017 status = nfs4_do_create(dir, dentry, data);
3019 nfs4_free_createdata(data);
3020 out:
3021 return status;
3024 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3025 struct iattr *sattr, dev_t rdev)
3027 struct nfs4_exception exception = { };
3028 int err;
3030 sattr->ia_mode &= ~current_umask();
3031 do {
3032 err = nfs4_handle_exception(NFS_SERVER(dir),
3033 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
3034 &exception);
3035 } while (exception.retry);
3036 return err;
3039 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3040 struct nfs_fsstat *fsstat)
3042 struct nfs4_statfs_arg args = {
3043 .fh = fhandle,
3044 .bitmask = server->attr_bitmask,
3046 struct nfs4_statfs_res res = {
3047 .fsstat = fsstat,
3049 struct rpc_message msg = {
3050 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3051 .rpc_argp = &args,
3052 .rpc_resp = &res,
3055 nfs_fattr_init(fsstat->fattr);
3056 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3059 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3061 struct nfs4_exception exception = { };
3062 int err;
3063 do {
3064 err = nfs4_handle_exception(server,
3065 _nfs4_proc_statfs(server, fhandle, fsstat),
3066 &exception);
3067 } while (exception.retry);
3068 return err;
3071 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3072 struct nfs_fsinfo *fsinfo)
3074 struct nfs4_fsinfo_arg args = {
3075 .fh = fhandle,
3076 .bitmask = server->attr_bitmask,
3078 struct nfs4_fsinfo_res res = {
3079 .fsinfo = fsinfo,
3081 struct rpc_message msg = {
3082 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3083 .rpc_argp = &args,
3084 .rpc_resp = &res,
3087 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3090 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3092 struct nfs4_exception exception = { };
3093 int err;
3095 do {
3096 err = nfs4_handle_exception(server,
3097 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3098 &exception);
3099 } while (exception.retry);
3100 return err;
3103 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3105 nfs_fattr_init(fsinfo->fattr);
3106 return nfs4_do_fsinfo(server, fhandle, fsinfo);
3109 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3110 struct nfs_pathconf *pathconf)
3112 struct nfs4_pathconf_arg args = {
3113 .fh = fhandle,
3114 .bitmask = server->attr_bitmask,
3116 struct nfs4_pathconf_res res = {
3117 .pathconf = pathconf,
3119 struct rpc_message msg = {
3120 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3121 .rpc_argp = &args,
3122 .rpc_resp = &res,
3125 /* None of the pathconf attributes are mandatory to implement */
3126 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3127 memset(pathconf, 0, sizeof(*pathconf));
3128 return 0;
3131 nfs_fattr_init(pathconf->fattr);
3132 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3135 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3136 struct nfs_pathconf *pathconf)
3138 struct nfs4_exception exception = { };
3139 int err;
3141 do {
3142 err = nfs4_handle_exception(server,
3143 _nfs4_proc_pathconf(server, fhandle, pathconf),
3144 &exception);
3145 } while (exception.retry);
3146 return err;
3149 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
3151 struct nfs_server *server = NFS_SERVER(data->inode);
3153 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3154 nfs_restart_rpc(task, server->nfs_client);
3155 return -EAGAIN;
3158 nfs_invalidate_atime(data->inode);
3159 if (task->tk_status > 0)
3160 renew_lease(server, data->timestamp);
3161 return 0;
3164 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3167 dprintk("--> %s\n", __func__);
3169 if (!nfs4_sequence_done(task, &data->res.seq_res))
3170 return -EAGAIN;
3172 return data->read_done_cb(task, data);
3175 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3177 data->timestamp = jiffies;
3178 data->read_done_cb = nfs4_read_done_cb;
3179 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3182 /* Reset the the nfs_read_data to send the read to the MDS. */
3183 void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data)
3185 dprintk("%s Reset task for i/o through\n", __func__);
3186 put_lseg(data->lseg);
3187 data->lseg = NULL;
3188 /* offsets will differ in the dense stripe case */
3189 data->args.offset = data->mds_offset;
3190 data->ds_clp = NULL;
3191 data->args.fh = NFS_FH(data->inode);
3192 data->read_done_cb = nfs4_read_done_cb;
3193 task->tk_ops = data->mds_ops;
3194 rpc_task_reset_client(task, NFS_CLIENT(data->inode));
3196 EXPORT_SYMBOL_GPL(nfs4_reset_read);
3198 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3200 struct inode *inode = data->inode;
3202 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3203 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3204 return -EAGAIN;
3206 if (task->tk_status >= 0) {
3207 renew_lease(NFS_SERVER(inode), data->timestamp);
3208 nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
3210 return 0;
3213 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3215 if (!nfs4_sequence_done(task, &data->res.seq_res))
3216 return -EAGAIN;
3217 return data->write_done_cb(task, data);
3220 /* Reset the the nfs_write_data to send the write to the MDS. */
3221 void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data)
3223 dprintk("%s Reset task for i/o through\n", __func__);
3224 put_lseg(data->lseg);
3225 data->lseg = NULL;
3226 data->ds_clp = NULL;
3227 data->write_done_cb = nfs4_write_done_cb;
3228 data->args.fh = NFS_FH(data->inode);
3229 data->args.bitmask = data->res.server->cache_consistency_bitmask;
3230 data->args.offset = data->mds_offset;
3231 data->res.fattr = &data->fattr;
3232 task->tk_ops = data->mds_ops;
3233 rpc_task_reset_client(task, NFS_CLIENT(data->inode));
3235 EXPORT_SYMBOL_GPL(nfs4_reset_write);
3237 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3239 struct nfs_server *server = NFS_SERVER(data->inode);
3241 if (data->lseg) {
3242 data->args.bitmask = NULL;
3243 data->res.fattr = NULL;
3244 } else
3245 data->args.bitmask = server->cache_consistency_bitmask;
3246 if (!data->write_done_cb)
3247 data->write_done_cb = nfs4_write_done_cb;
3248 data->res.server = server;
3249 data->timestamp = jiffies;
3251 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3254 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3256 struct inode *inode = data->inode;
3258 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3259 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3260 return -EAGAIN;
3262 nfs_refresh_inode(inode, data->res.fattr);
3263 return 0;
3266 static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
3268 if (!nfs4_sequence_done(task, &data->res.seq_res))
3269 return -EAGAIN;
3270 return data->write_done_cb(task, data);
3273 static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
3275 struct nfs_server *server = NFS_SERVER(data->inode);
3277 if (data->lseg) {
3278 data->args.bitmask = NULL;
3279 data->res.fattr = NULL;
3280 } else
3281 data->args.bitmask = server->cache_consistency_bitmask;
3282 if (!data->write_done_cb)
3283 data->write_done_cb = nfs4_commit_done_cb;
3284 data->res.server = server;
3285 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3288 struct nfs4_renewdata {
3289 struct nfs_client *client;
3290 unsigned long timestamp;
3294 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3295 * standalone procedure for queueing an asynchronous RENEW.
3297 static void nfs4_renew_release(void *calldata)
3299 struct nfs4_renewdata *data = calldata;
3300 struct nfs_client *clp = data->client;
3302 if (atomic_read(&clp->cl_count) > 1)
3303 nfs4_schedule_state_renewal(clp);
3304 nfs_put_client(clp);
3305 kfree(data);
3308 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3310 struct nfs4_renewdata *data = calldata;
3311 struct nfs_client *clp = data->client;
3312 unsigned long timestamp = data->timestamp;
3314 if (task->tk_status < 0) {
3315 /* Unless we're shutting down, schedule state recovery! */
3316 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0)
3317 nfs4_schedule_lease_recovery(clp);
3318 return;
3320 do_renew_lease(clp, timestamp);
3323 static const struct rpc_call_ops nfs4_renew_ops = {
3324 .rpc_call_done = nfs4_renew_done,
3325 .rpc_release = nfs4_renew_release,
3328 int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
3330 struct rpc_message msg = {
3331 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3332 .rpc_argp = clp,
3333 .rpc_cred = cred,
3335 struct nfs4_renewdata *data;
3337 if (!atomic_inc_not_zero(&clp->cl_count))
3338 return -EIO;
3339 data = kmalloc(sizeof(*data), GFP_KERNEL);
3340 if (data == NULL)
3341 return -ENOMEM;
3342 data->client = clp;
3343 data->timestamp = jiffies;
3344 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3345 &nfs4_renew_ops, data);
3348 int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3350 struct rpc_message msg = {
3351 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3352 .rpc_argp = clp,
3353 .rpc_cred = cred,
3355 unsigned long now = jiffies;
3356 int status;
3358 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3359 if (status < 0)
3360 return status;
3361 do_renew_lease(clp, now);
3362 return 0;
3365 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3367 return (server->caps & NFS_CAP_ACLS)
3368 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3369 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3372 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3373 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3374 * the stack.
3376 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3378 static void buf_to_pages(const void *buf, size_t buflen,
3379 struct page **pages, unsigned int *pgbase)
3381 const void *p = buf;
3383 *pgbase = offset_in_page(buf);
3384 p -= *pgbase;
3385 while (p < buf + buflen) {
3386 *(pages++) = virt_to_page(p);
3387 p += PAGE_CACHE_SIZE;
3391 static int buf_to_pages_noslab(const void *buf, size_t buflen,
3392 struct page **pages, unsigned int *pgbase)
3394 struct page *newpage, **spages;
3395 int rc = 0;
3396 size_t len;
3397 spages = pages;
3399 do {
3400 len = min_t(size_t, PAGE_CACHE_SIZE, buflen);
3401 newpage = alloc_page(GFP_KERNEL);
3403 if (newpage == NULL)
3404 goto unwind;
3405 memcpy(page_address(newpage), buf, len);
3406 buf += len;
3407 buflen -= len;
3408 *pages++ = newpage;
3409 rc++;
3410 } while (buflen != 0);
3412 return rc;
3414 unwind:
3415 for(; rc > 0; rc--)
3416 __free_page(spages[rc-1]);
3417 return -ENOMEM;
3420 struct nfs4_cached_acl {
3421 int cached;
3422 size_t len;
3423 char data[0];
3426 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3428 struct nfs_inode *nfsi = NFS_I(inode);
3430 spin_lock(&inode->i_lock);
3431 kfree(nfsi->nfs4_acl);
3432 nfsi->nfs4_acl = acl;
3433 spin_unlock(&inode->i_lock);
3436 static void nfs4_zap_acl_attr(struct inode *inode)
3438 nfs4_set_cached_acl(inode, NULL);
3441 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3443 struct nfs_inode *nfsi = NFS_I(inode);
3444 struct nfs4_cached_acl *acl;
3445 int ret = -ENOENT;
3447 spin_lock(&inode->i_lock);
3448 acl = nfsi->nfs4_acl;
3449 if (acl == NULL)
3450 goto out;
3451 if (buf == NULL) /* user is just asking for length */
3452 goto out_len;
3453 if (acl->cached == 0)
3454 goto out;
3455 ret = -ERANGE; /* see getxattr(2) man page */
3456 if (acl->len > buflen)
3457 goto out;
3458 memcpy(buf, acl->data, acl->len);
3459 out_len:
3460 ret = acl->len;
3461 out:
3462 spin_unlock(&inode->i_lock);
3463 return ret;
3466 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
3468 struct nfs4_cached_acl *acl;
3470 if (buf && acl_len <= PAGE_SIZE) {
3471 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3472 if (acl == NULL)
3473 goto out;
3474 acl->cached = 1;
3475 memcpy(acl->data, buf, acl_len);
3476 } else {
3477 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3478 if (acl == NULL)
3479 goto out;
3480 acl->cached = 0;
3482 acl->len = acl_len;
3483 out:
3484 nfs4_set_cached_acl(inode, acl);
3487 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3489 struct page *pages[NFS4ACL_MAXPAGES];
3490 struct nfs_getaclargs args = {
3491 .fh = NFS_FH(inode),
3492 .acl_pages = pages,
3493 .acl_len = buflen,
3495 struct nfs_getaclres res = {
3496 .acl_len = buflen,
3498 void *resp_buf;
3499 struct rpc_message msg = {
3500 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3501 .rpc_argp = &args,
3502 .rpc_resp = &res,
3504 struct page *localpage = NULL;
3505 int ret;
3507 if (buflen < PAGE_SIZE) {
3508 /* As long as we're doing a round trip to the server anyway,
3509 * let's be prepared for a page of acl data. */
3510 localpage = alloc_page(GFP_KERNEL);
3511 resp_buf = page_address(localpage);
3512 if (localpage == NULL)
3513 return -ENOMEM;
3514 args.acl_pages[0] = localpage;
3515 args.acl_pgbase = 0;
3516 args.acl_len = PAGE_SIZE;
3517 } else {
3518 resp_buf = buf;
3519 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
3521 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
3522 if (ret)
3523 goto out_free;
3524 if (res.acl_len > args.acl_len)
3525 nfs4_write_cached_acl(inode, NULL, res.acl_len);
3526 else
3527 nfs4_write_cached_acl(inode, resp_buf, res.acl_len);
3528 if (buf) {
3529 ret = -ERANGE;
3530 if (res.acl_len > buflen)
3531 goto out_free;
3532 if (localpage)
3533 memcpy(buf, resp_buf, res.acl_len);
3535 ret = res.acl_len;
3536 out_free:
3537 if (localpage)
3538 __free_page(localpage);
3539 return ret;
3542 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3544 struct nfs4_exception exception = { };
3545 ssize_t ret;
3546 do {
3547 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3548 if (ret >= 0)
3549 break;
3550 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3551 } while (exception.retry);
3552 return ret;
3555 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3557 struct nfs_server *server = NFS_SERVER(inode);
3558 int ret;
3560 if (!nfs4_server_supports_acls(server))
3561 return -EOPNOTSUPP;
3562 ret = nfs_revalidate_inode(server, inode);
3563 if (ret < 0)
3564 return ret;
3565 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
3566 nfs_zap_acl_cache(inode);
3567 ret = nfs4_read_cached_acl(inode, buf, buflen);
3568 if (ret != -ENOENT)
3569 return ret;
3570 return nfs4_get_acl_uncached(inode, buf, buflen);
3573 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3575 struct nfs_server *server = NFS_SERVER(inode);
3576 struct page *pages[NFS4ACL_MAXPAGES];
3577 struct nfs_setaclargs arg = {
3578 .fh = NFS_FH(inode),
3579 .acl_pages = pages,
3580 .acl_len = buflen,
3582 struct nfs_setaclres res;
3583 struct rpc_message msg = {
3584 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
3585 .rpc_argp = &arg,
3586 .rpc_resp = &res,
3588 int ret, i;
3590 if (!nfs4_server_supports_acls(server))
3591 return -EOPNOTSUPP;
3592 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3593 if (i < 0)
3594 return i;
3595 nfs_inode_return_delegation(inode);
3596 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3599 * Free each page after tx, so the only ref left is
3600 * held by the network stack
3602 for (; i > 0; i--)
3603 put_page(pages[i-1]);
3606 * Acl update can result in inode attribute update.
3607 * so mark the attribute cache invalid.
3609 spin_lock(&inode->i_lock);
3610 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
3611 spin_unlock(&inode->i_lock);
3612 nfs_access_zap_cache(inode);
3613 nfs_zap_acl_cache(inode);
3614 return ret;
3617 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3619 struct nfs4_exception exception = { };
3620 int err;
3621 do {
3622 err = nfs4_handle_exception(NFS_SERVER(inode),
3623 __nfs4_proc_set_acl(inode, buf, buflen),
3624 &exception);
3625 } while (exception.retry);
3626 return err;
3629 static int
3630 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3632 struct nfs_client *clp = server->nfs_client;
3634 if (task->tk_status >= 0)
3635 return 0;
3636 switch(task->tk_status) {
3637 case -NFS4ERR_ADMIN_REVOKED:
3638 case -NFS4ERR_BAD_STATEID:
3639 case -NFS4ERR_OPENMODE:
3640 if (state == NULL)
3641 break;
3642 nfs4_schedule_stateid_recovery(server, state);
3643 goto wait_on_recovery;
3644 case -NFS4ERR_STALE_STATEID:
3645 case -NFS4ERR_STALE_CLIENTID:
3646 case -NFS4ERR_EXPIRED:
3647 nfs4_schedule_lease_recovery(clp);
3648 goto wait_on_recovery;
3649 #if defined(CONFIG_NFS_V4_1)
3650 case -NFS4ERR_BADSESSION:
3651 case -NFS4ERR_BADSLOT:
3652 case -NFS4ERR_BAD_HIGH_SLOT:
3653 case -NFS4ERR_DEADSESSION:
3654 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
3655 case -NFS4ERR_SEQ_FALSE_RETRY:
3656 case -NFS4ERR_SEQ_MISORDERED:
3657 dprintk("%s ERROR %d, Reset session\n", __func__,
3658 task->tk_status);
3659 nfs4_schedule_session_recovery(clp->cl_session);
3660 task->tk_status = 0;
3661 return -EAGAIN;
3662 #endif /* CONFIG_NFS_V4_1 */
3663 case -NFS4ERR_DELAY:
3664 nfs_inc_server_stats(server, NFSIOS_DELAY);
3665 case -NFS4ERR_GRACE:
3666 case -EKEYEXPIRED:
3667 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3668 task->tk_status = 0;
3669 return -EAGAIN;
3670 case -NFS4ERR_OLD_STATEID:
3671 task->tk_status = 0;
3672 return -EAGAIN;
3674 task->tk_status = nfs4_map_errors(task->tk_status);
3675 return 0;
3676 wait_on_recovery:
3677 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3678 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3679 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3680 task->tk_status = 0;
3681 return -EAGAIN;
3684 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3685 unsigned short port, struct rpc_cred *cred,
3686 struct nfs4_setclientid_res *res)
3688 nfs4_verifier sc_verifier;
3689 struct nfs4_setclientid setclientid = {
3690 .sc_verifier = &sc_verifier,
3691 .sc_prog = program,
3692 .sc_cb_ident = clp->cl_cb_ident,
3694 struct rpc_message msg = {
3695 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
3696 .rpc_argp = &setclientid,
3697 .rpc_resp = res,
3698 .rpc_cred = cred,
3700 __be32 *p;
3701 int loop = 0;
3702 int status;
3704 p = (__be32*)sc_verifier.data;
3705 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3706 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3708 for(;;) {
3709 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3710 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3711 clp->cl_ipaddr,
3712 rpc_peeraddr2str(clp->cl_rpcclient,
3713 RPC_DISPLAY_ADDR),
3714 rpc_peeraddr2str(clp->cl_rpcclient,
3715 RPC_DISPLAY_PROTO),
3716 clp->cl_rpcclient->cl_auth->au_ops->au_name,
3717 clp->cl_id_uniquifier);
3718 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
3719 sizeof(setclientid.sc_netid),
3720 rpc_peeraddr2str(clp->cl_rpcclient,
3721 RPC_DISPLAY_NETID));
3722 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3723 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3724 clp->cl_ipaddr, port >> 8, port & 255);
3726 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3727 if (status != -NFS4ERR_CLID_INUSE)
3728 break;
3729 if (signalled())
3730 break;
3731 if (loop++ & 1)
3732 ssleep(clp->cl_lease_time / HZ + 1);
3733 else
3734 if (++clp->cl_id_uniquifier == 0)
3735 break;
3737 return status;
3740 static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3741 struct nfs4_setclientid_res *arg,
3742 struct rpc_cred *cred)
3744 struct nfs_fsinfo fsinfo;
3745 struct rpc_message msg = {
3746 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
3747 .rpc_argp = arg,
3748 .rpc_resp = &fsinfo,
3749 .rpc_cred = cred,
3751 unsigned long now;
3752 int status;
3754 now = jiffies;
3755 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3756 if (status == 0) {
3757 spin_lock(&clp->cl_lock);
3758 clp->cl_lease_time = fsinfo.lease_time * HZ;
3759 clp->cl_last_renewal = now;
3760 spin_unlock(&clp->cl_lock);
3762 return status;
3765 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3766 struct nfs4_setclientid_res *arg,
3767 struct rpc_cred *cred)
3769 long timeout = 0;
3770 int err;
3771 do {
3772 err = _nfs4_proc_setclientid_confirm(clp, arg, cred);
3773 switch (err) {
3774 case 0:
3775 return err;
3776 case -NFS4ERR_RESOURCE:
3777 /* The IBM lawyers misread another document! */
3778 case -NFS4ERR_DELAY:
3779 err = nfs4_delay(clp->cl_rpcclient, &timeout);
3781 } while (err == 0);
3782 return err;
3785 struct nfs4_delegreturndata {
3786 struct nfs4_delegreturnargs args;
3787 struct nfs4_delegreturnres res;
3788 struct nfs_fh fh;
3789 nfs4_stateid stateid;
3790 unsigned long timestamp;
3791 struct nfs_fattr fattr;
3792 int rpc_status;
3795 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
3797 struct nfs4_delegreturndata *data = calldata;
3799 if (!nfs4_sequence_done(task, &data->res.seq_res))
3800 return;
3802 switch (task->tk_status) {
3803 case -NFS4ERR_STALE_STATEID:
3804 case -NFS4ERR_EXPIRED:
3805 case 0:
3806 renew_lease(data->res.server, data->timestamp);
3807 break;
3808 default:
3809 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
3810 -EAGAIN) {
3811 nfs_restart_rpc(task, data->res.server->nfs_client);
3812 return;
3815 data->rpc_status = task->tk_status;
3818 static void nfs4_delegreturn_release(void *calldata)
3820 kfree(calldata);
3823 #if defined(CONFIG_NFS_V4_1)
3824 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3826 struct nfs4_delegreturndata *d_data;
3828 d_data = (struct nfs4_delegreturndata *)data;
3830 if (nfs4_setup_sequence(d_data->res.server,
3831 &d_data->args.seq_args,
3832 &d_data->res.seq_res, 1, task))
3833 return;
3834 rpc_call_start(task);
3836 #endif /* CONFIG_NFS_V4_1 */
3838 static const struct rpc_call_ops nfs4_delegreturn_ops = {
3839 #if defined(CONFIG_NFS_V4_1)
3840 .rpc_call_prepare = nfs4_delegreturn_prepare,
3841 #endif /* CONFIG_NFS_V4_1 */
3842 .rpc_call_done = nfs4_delegreturn_done,
3843 .rpc_release = nfs4_delegreturn_release,
3846 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3848 struct nfs4_delegreturndata *data;
3849 struct nfs_server *server = NFS_SERVER(inode);
3850 struct rpc_task *task;
3851 struct rpc_message msg = {
3852 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
3853 .rpc_cred = cred,
3855 struct rpc_task_setup task_setup_data = {
3856 .rpc_client = server->client,
3857 .rpc_message = &msg,
3858 .callback_ops = &nfs4_delegreturn_ops,
3859 .flags = RPC_TASK_ASYNC,
3861 int status = 0;
3863 data = kzalloc(sizeof(*data), GFP_NOFS);
3864 if (data == NULL)
3865 return -ENOMEM;
3866 data->args.fhandle = &data->fh;
3867 data->args.stateid = &data->stateid;
3868 data->args.bitmask = server->attr_bitmask;
3869 nfs_copy_fh(&data->fh, NFS_FH(inode));
3870 memcpy(&data->stateid, stateid, sizeof(data->stateid));
3871 data->res.fattr = &data->fattr;
3872 data->res.server = server;
3873 nfs_fattr_init(data->res.fattr);
3874 data->timestamp = jiffies;
3875 data->rpc_status = 0;
3877 task_setup_data.callback_data = data;
3878 msg.rpc_argp = &data->args;
3879 msg.rpc_resp = &data->res;
3880 task = rpc_run_task(&task_setup_data);
3881 if (IS_ERR(task))
3882 return PTR_ERR(task);
3883 if (!issync)
3884 goto out;
3885 status = nfs4_wait_for_completion_rpc_task(task);
3886 if (status != 0)
3887 goto out;
3888 status = data->rpc_status;
3889 if (status != 0)
3890 goto out;
3891 nfs_refresh_inode(inode, &data->fattr);
3892 out:
3893 rpc_put_task(task);
3894 return status;
3897 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3899 struct nfs_server *server = NFS_SERVER(inode);
3900 struct nfs4_exception exception = { };
3901 int err;
3902 do {
3903 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
3904 switch (err) {
3905 case -NFS4ERR_STALE_STATEID:
3906 case -NFS4ERR_EXPIRED:
3907 case 0:
3908 return 0;
3910 err = nfs4_handle_exception(server, err, &exception);
3911 } while (exception.retry);
3912 return err;
3915 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3916 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3919 * sleep, with exponential backoff, and retry the LOCK operation.
3921 static unsigned long
3922 nfs4_set_lock_task_retry(unsigned long timeout)
3924 schedule_timeout_killable(timeout);
3925 timeout <<= 1;
3926 if (timeout > NFS4_LOCK_MAXTIMEOUT)
3927 return NFS4_LOCK_MAXTIMEOUT;
3928 return timeout;
3931 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3933 struct inode *inode = state->inode;
3934 struct nfs_server *server = NFS_SERVER(inode);
3935 struct nfs_client *clp = server->nfs_client;
3936 struct nfs_lockt_args arg = {
3937 .fh = NFS_FH(inode),
3938 .fl = request,
3940 struct nfs_lockt_res res = {
3941 .denied = request,
3943 struct rpc_message msg = {
3944 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
3945 .rpc_argp = &arg,
3946 .rpc_resp = &res,
3947 .rpc_cred = state->owner->so_cred,
3949 struct nfs4_lock_state *lsp;
3950 int status;
3952 arg.lock_owner.clientid = clp->cl_clientid;
3953 status = nfs4_set_lock_state(state, request);
3954 if (status != 0)
3955 goto out;
3956 lsp = request->fl_u.nfs4_fl.owner;
3957 arg.lock_owner.id = lsp->ls_id.id;
3958 arg.lock_owner.s_dev = server->s_dev;
3959 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3960 switch (status) {
3961 case 0:
3962 request->fl_type = F_UNLCK;
3963 break;
3964 case -NFS4ERR_DENIED:
3965 status = 0;
3967 request->fl_ops->fl_release_private(request);
3968 out:
3969 return status;
3972 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3974 struct nfs4_exception exception = { };
3975 int err;
3977 do {
3978 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3979 _nfs4_proc_getlk(state, cmd, request),
3980 &exception);
3981 } while (exception.retry);
3982 return err;
3985 static int do_vfs_lock(struct file *file, struct file_lock *fl)
3987 int res = 0;
3988 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
3989 case FL_POSIX:
3990 res = posix_lock_file_wait(file, fl);
3991 break;
3992 case FL_FLOCK:
3993 res = flock_lock_file_wait(file, fl);
3994 break;
3995 default:
3996 BUG();
3998 return res;
4001 struct nfs4_unlockdata {
4002 struct nfs_locku_args arg;
4003 struct nfs_locku_res res;
4004 struct nfs4_lock_state *lsp;
4005 struct nfs_open_context *ctx;
4006 struct file_lock fl;
4007 const struct nfs_server *server;
4008 unsigned long timestamp;
4011 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
4012 struct nfs_open_context *ctx,
4013 struct nfs4_lock_state *lsp,
4014 struct nfs_seqid *seqid)
4016 struct nfs4_unlockdata *p;
4017 struct inode *inode = lsp->ls_state->inode;
4019 p = kzalloc(sizeof(*p), GFP_NOFS);
4020 if (p == NULL)
4021 return NULL;
4022 p->arg.fh = NFS_FH(inode);
4023 p->arg.fl = &p->fl;
4024 p->arg.seqid = seqid;
4025 p->res.seqid = seqid;
4026 p->arg.stateid = &lsp->ls_stateid;
4027 p->lsp = lsp;
4028 atomic_inc(&lsp->ls_count);
4029 /* Ensure we don't close file until we're done freeing locks! */
4030 p->ctx = get_nfs_open_context(ctx);
4031 memcpy(&p->fl, fl, sizeof(p->fl));
4032 p->server = NFS_SERVER(inode);
4033 return p;
4036 static void nfs4_locku_release_calldata(void *data)
4038 struct nfs4_unlockdata *calldata = data;
4039 nfs_free_seqid(calldata->arg.seqid);
4040 nfs4_put_lock_state(calldata->lsp);
4041 put_nfs_open_context(calldata->ctx);
4042 kfree(calldata);
4045 static void nfs4_locku_done(struct rpc_task *task, void *data)
4047 struct nfs4_unlockdata *calldata = data;
4049 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
4050 return;
4051 switch (task->tk_status) {
4052 case 0:
4053 memcpy(calldata->lsp->ls_stateid.data,
4054 calldata->res.stateid.data,
4055 sizeof(calldata->lsp->ls_stateid.data));
4056 renew_lease(calldata->server, calldata->timestamp);
4057 break;
4058 case -NFS4ERR_BAD_STATEID:
4059 case -NFS4ERR_OLD_STATEID:
4060 case -NFS4ERR_STALE_STATEID:
4061 case -NFS4ERR_EXPIRED:
4062 break;
4063 default:
4064 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
4065 nfs_restart_rpc(task,
4066 calldata->server->nfs_client);
4070 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4072 struct nfs4_unlockdata *calldata = data;
4074 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
4075 return;
4076 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
4077 /* Note: exit _without_ running nfs4_locku_done */
4078 task->tk_action = NULL;
4079 return;
4081 calldata->timestamp = jiffies;
4082 if (nfs4_setup_sequence(calldata->server,
4083 &calldata->arg.seq_args,
4084 &calldata->res.seq_res, 1, task))
4085 return;
4086 rpc_call_start(task);
4089 static const struct rpc_call_ops nfs4_locku_ops = {
4090 .rpc_call_prepare = nfs4_locku_prepare,
4091 .rpc_call_done = nfs4_locku_done,
4092 .rpc_release = nfs4_locku_release_calldata,
4095 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4096 struct nfs_open_context *ctx,
4097 struct nfs4_lock_state *lsp,
4098 struct nfs_seqid *seqid)
4100 struct nfs4_unlockdata *data;
4101 struct rpc_message msg = {
4102 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
4103 .rpc_cred = ctx->cred,
4105 struct rpc_task_setup task_setup_data = {
4106 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
4107 .rpc_message = &msg,
4108 .callback_ops = &nfs4_locku_ops,
4109 .workqueue = nfsiod_workqueue,
4110 .flags = RPC_TASK_ASYNC,
4113 /* Ensure this is an unlock - when canceling a lock, the
4114 * canceled lock is passed in, and it won't be an unlock.
4116 fl->fl_type = F_UNLCK;
4118 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
4119 if (data == NULL) {
4120 nfs_free_seqid(seqid);
4121 return ERR_PTR(-ENOMEM);
4124 msg.rpc_argp = &data->arg;
4125 msg.rpc_resp = &data->res;
4126 task_setup_data.callback_data = data;
4127 return rpc_run_task(&task_setup_data);
4130 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
4132 struct nfs_inode *nfsi = NFS_I(state->inode);
4133 struct nfs_seqid *seqid;
4134 struct nfs4_lock_state *lsp;
4135 struct rpc_task *task;
4136 int status = 0;
4137 unsigned char fl_flags = request->fl_flags;
4139 status = nfs4_set_lock_state(state, request);
4140 /* Unlock _before_ we do the RPC call */
4141 request->fl_flags |= FL_EXISTS;
4142 down_read(&nfsi->rwsem);
4143 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
4144 up_read(&nfsi->rwsem);
4145 goto out;
4147 up_read(&nfsi->rwsem);
4148 if (status != 0)
4149 goto out;
4150 /* Is this a delegated lock? */
4151 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
4152 goto out;
4153 lsp = request->fl_u.nfs4_fl.owner;
4154 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
4155 status = -ENOMEM;
4156 if (seqid == NULL)
4157 goto out;
4158 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4159 status = PTR_ERR(task);
4160 if (IS_ERR(task))
4161 goto out;
4162 status = nfs4_wait_for_completion_rpc_task(task);
4163 rpc_put_task(task);
4164 out:
4165 request->fl_flags = fl_flags;
4166 return status;
4169 struct nfs4_lockdata {
4170 struct nfs_lock_args arg;
4171 struct nfs_lock_res res;
4172 struct nfs4_lock_state *lsp;
4173 struct nfs_open_context *ctx;
4174 struct file_lock fl;
4175 unsigned long timestamp;
4176 int rpc_status;
4177 int cancelled;
4178 struct nfs_server *server;
4181 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4182 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4183 gfp_t gfp_mask)
4185 struct nfs4_lockdata *p;
4186 struct inode *inode = lsp->ls_state->inode;
4187 struct nfs_server *server = NFS_SERVER(inode);
4189 p = kzalloc(sizeof(*p), gfp_mask);
4190 if (p == NULL)
4191 return NULL;
4193 p->arg.fh = NFS_FH(inode);
4194 p->arg.fl = &p->fl;
4195 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4196 if (p->arg.open_seqid == NULL)
4197 goto out_free;
4198 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4199 if (p->arg.lock_seqid == NULL)
4200 goto out_free_seqid;
4201 p->arg.lock_stateid = &lsp->ls_stateid;
4202 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4203 p->arg.lock_owner.id = lsp->ls_id.id;
4204 p->arg.lock_owner.s_dev = server->s_dev;
4205 p->res.lock_seqid = p->arg.lock_seqid;
4206 p->lsp = lsp;
4207 p->server = server;
4208 atomic_inc(&lsp->ls_count);
4209 p->ctx = get_nfs_open_context(ctx);
4210 memcpy(&p->fl, fl, sizeof(p->fl));
4211 return p;
4212 out_free_seqid:
4213 nfs_free_seqid(p->arg.open_seqid);
4214 out_free:
4215 kfree(p);
4216 return NULL;
4219 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4221 struct nfs4_lockdata *data = calldata;
4222 struct nfs4_state *state = data->lsp->ls_state;
4224 dprintk("%s: begin!\n", __func__);
4225 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4226 return;
4227 /* Do we need to do an open_to_lock_owner? */
4228 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4229 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
4230 return;
4231 data->arg.open_stateid = &state->stateid;
4232 data->arg.new_lock_owner = 1;
4233 data->res.open_seqid = data->arg.open_seqid;
4234 } else
4235 data->arg.new_lock_owner = 0;
4236 data->timestamp = jiffies;
4237 if (nfs4_setup_sequence(data->server,
4238 &data->arg.seq_args,
4239 &data->res.seq_res, 1, task))
4240 return;
4241 rpc_call_start(task);
4242 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4245 static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4247 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4248 nfs4_lock_prepare(task, calldata);
4251 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4253 struct nfs4_lockdata *data = calldata;
4255 dprintk("%s: begin!\n", __func__);
4257 if (!nfs4_sequence_done(task, &data->res.seq_res))
4258 return;
4260 data->rpc_status = task->tk_status;
4261 if (data->arg.new_lock_owner != 0) {
4262 if (data->rpc_status == 0)
4263 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4264 else
4265 goto out;
4267 if (data->rpc_status == 0) {
4268 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
4269 sizeof(data->lsp->ls_stateid.data));
4270 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4271 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
4273 out:
4274 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4277 static void nfs4_lock_release(void *calldata)
4279 struct nfs4_lockdata *data = calldata;
4281 dprintk("%s: begin!\n", __func__);
4282 nfs_free_seqid(data->arg.open_seqid);
4283 if (data->cancelled != 0) {
4284 struct rpc_task *task;
4285 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4286 data->arg.lock_seqid);
4287 if (!IS_ERR(task))
4288 rpc_put_task_async(task);
4289 dprintk("%s: cancelling lock!\n", __func__);
4290 } else
4291 nfs_free_seqid(data->arg.lock_seqid);
4292 nfs4_put_lock_state(data->lsp);
4293 put_nfs_open_context(data->ctx);
4294 kfree(data);
4295 dprintk("%s: done!\n", __func__);
4298 static const struct rpc_call_ops nfs4_lock_ops = {
4299 .rpc_call_prepare = nfs4_lock_prepare,
4300 .rpc_call_done = nfs4_lock_done,
4301 .rpc_release = nfs4_lock_release,
4304 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4305 .rpc_call_prepare = nfs4_recover_lock_prepare,
4306 .rpc_call_done = nfs4_lock_done,
4307 .rpc_release = nfs4_lock_release,
4310 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4312 switch (error) {
4313 case -NFS4ERR_ADMIN_REVOKED:
4314 case -NFS4ERR_BAD_STATEID:
4315 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4316 if (new_lock_owner != 0 ||
4317 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4318 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
4319 break;
4320 case -NFS4ERR_STALE_STATEID:
4321 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4322 case -NFS4ERR_EXPIRED:
4323 nfs4_schedule_lease_recovery(server->nfs_client);
4327 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4329 struct nfs4_lockdata *data;
4330 struct rpc_task *task;
4331 struct rpc_message msg = {
4332 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4333 .rpc_cred = state->owner->so_cred,
4335 struct rpc_task_setup task_setup_data = {
4336 .rpc_client = NFS_CLIENT(state->inode),
4337 .rpc_message = &msg,
4338 .callback_ops = &nfs4_lock_ops,
4339 .workqueue = nfsiod_workqueue,
4340 .flags = RPC_TASK_ASYNC,
4342 int ret;
4344 dprintk("%s: begin!\n", __func__);
4345 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4346 fl->fl_u.nfs4_fl.owner,
4347 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4348 if (data == NULL)
4349 return -ENOMEM;
4350 if (IS_SETLKW(cmd))
4351 data->arg.block = 1;
4352 if (recovery_type > NFS_LOCK_NEW) {
4353 if (recovery_type == NFS_LOCK_RECLAIM)
4354 data->arg.reclaim = NFS_LOCK_RECLAIM;
4355 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4357 msg.rpc_argp = &data->arg;
4358 msg.rpc_resp = &data->res;
4359 task_setup_data.callback_data = data;
4360 task = rpc_run_task(&task_setup_data);
4361 if (IS_ERR(task))
4362 return PTR_ERR(task);
4363 ret = nfs4_wait_for_completion_rpc_task(task);
4364 if (ret == 0) {
4365 ret = data->rpc_status;
4366 if (ret)
4367 nfs4_handle_setlk_error(data->server, data->lsp,
4368 data->arg.new_lock_owner, ret);
4369 } else
4370 data->cancelled = 1;
4371 rpc_put_task(task);
4372 dprintk("%s: done, ret = %d!\n", __func__, ret);
4373 return ret;
4376 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4378 struct nfs_server *server = NFS_SERVER(state->inode);
4379 struct nfs4_exception exception = { };
4380 int err;
4382 do {
4383 /* Cache the lock if possible... */
4384 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4385 return 0;
4386 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4387 if (err != -NFS4ERR_DELAY)
4388 break;
4389 nfs4_handle_exception(server, err, &exception);
4390 } while (exception.retry);
4391 return err;
4394 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4396 struct nfs_server *server = NFS_SERVER(state->inode);
4397 struct nfs4_exception exception = { };
4398 int err;
4400 err = nfs4_set_lock_state(state, request);
4401 if (err != 0)
4402 return err;
4403 do {
4404 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4405 return 0;
4406 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4407 switch (err) {
4408 default:
4409 goto out;
4410 case -NFS4ERR_GRACE:
4411 case -NFS4ERR_DELAY:
4412 nfs4_handle_exception(server, err, &exception);
4413 err = 0;
4415 } while (exception.retry);
4416 out:
4417 return err;
4420 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4422 struct nfs_inode *nfsi = NFS_I(state->inode);
4423 unsigned char fl_flags = request->fl_flags;
4424 int status = -ENOLCK;
4426 if ((fl_flags & FL_POSIX) &&
4427 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4428 goto out;
4429 /* Is this a delegated open? */
4430 status = nfs4_set_lock_state(state, request);
4431 if (status != 0)
4432 goto out;
4433 request->fl_flags |= FL_ACCESS;
4434 status = do_vfs_lock(request->fl_file, request);
4435 if (status < 0)
4436 goto out;
4437 down_read(&nfsi->rwsem);
4438 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4439 /* Yes: cache locks! */
4440 /* ...but avoid races with delegation recall... */
4441 request->fl_flags = fl_flags & ~FL_SLEEP;
4442 status = do_vfs_lock(request->fl_file, request);
4443 goto out_unlock;
4445 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4446 if (status != 0)
4447 goto out_unlock;
4448 /* Note: we always want to sleep here! */
4449 request->fl_flags = fl_flags | FL_SLEEP;
4450 if (do_vfs_lock(request->fl_file, request) < 0)
4451 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
4452 out_unlock:
4453 up_read(&nfsi->rwsem);
4454 out:
4455 request->fl_flags = fl_flags;
4456 return status;
4459 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4461 struct nfs4_exception exception = { };
4462 int err;
4464 do {
4465 err = _nfs4_proc_setlk(state, cmd, request);
4466 if (err == -NFS4ERR_DENIED)
4467 err = -EAGAIN;
4468 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4469 err, &exception);
4470 } while (exception.retry);
4471 return err;
4474 static int
4475 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4477 struct nfs_open_context *ctx;
4478 struct nfs4_state *state;
4479 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
4480 int status;
4482 /* verify open state */
4483 ctx = nfs_file_open_context(filp);
4484 state = ctx->state;
4486 if (request->fl_start < 0 || request->fl_end < 0)
4487 return -EINVAL;
4489 if (IS_GETLK(cmd)) {
4490 if (state != NULL)
4491 return nfs4_proc_getlk(state, F_GETLK, request);
4492 return 0;
4495 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4496 return -EINVAL;
4498 if (request->fl_type == F_UNLCK) {
4499 if (state != NULL)
4500 return nfs4_proc_unlck(state, cmd, request);
4501 return 0;
4504 if (state == NULL)
4505 return -ENOLCK;
4506 do {
4507 status = nfs4_proc_setlk(state, cmd, request);
4508 if ((status != -EAGAIN) || IS_SETLK(cmd))
4509 break;
4510 timeout = nfs4_set_lock_task_retry(timeout);
4511 status = -ERESTARTSYS;
4512 if (signalled())
4513 break;
4514 } while(status < 0);
4515 return status;
4518 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4520 struct nfs_server *server = NFS_SERVER(state->inode);
4521 struct nfs4_exception exception = { };
4522 int err;
4524 err = nfs4_set_lock_state(state, fl);
4525 if (err != 0)
4526 goto out;
4527 do {
4528 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4529 switch (err) {
4530 default:
4531 printk(KERN_ERR "%s: unhandled error %d.\n",
4532 __func__, err);
4533 case 0:
4534 case -ESTALE:
4535 goto out;
4536 case -NFS4ERR_EXPIRED:
4537 case -NFS4ERR_STALE_CLIENTID:
4538 case -NFS4ERR_STALE_STATEID:
4539 nfs4_schedule_lease_recovery(server->nfs_client);
4540 goto out;
4541 case -NFS4ERR_BADSESSION:
4542 case -NFS4ERR_BADSLOT:
4543 case -NFS4ERR_BAD_HIGH_SLOT:
4544 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4545 case -NFS4ERR_DEADSESSION:
4546 nfs4_schedule_session_recovery(server->nfs_client->cl_session);
4547 goto out;
4548 case -ERESTARTSYS:
4550 * The show must go on: exit, but mark the
4551 * stateid as needing recovery.
4553 case -NFS4ERR_ADMIN_REVOKED:
4554 case -NFS4ERR_BAD_STATEID:
4555 case -NFS4ERR_OPENMODE:
4556 nfs4_schedule_stateid_recovery(server, state);
4557 err = 0;
4558 goto out;
4559 case -EKEYEXPIRED:
4561 * User RPCSEC_GSS context has expired.
4562 * We cannot recover this stateid now, so
4563 * skip it and allow recovery thread to
4564 * proceed.
4566 err = 0;
4567 goto out;
4568 case -ENOMEM:
4569 case -NFS4ERR_DENIED:
4570 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4571 err = 0;
4572 goto out;
4573 case -NFS4ERR_DELAY:
4574 break;
4576 err = nfs4_handle_exception(server, err, &exception);
4577 } while (exception.retry);
4578 out:
4579 return err;
4582 static void nfs4_release_lockowner_release(void *calldata)
4584 kfree(calldata);
4587 const struct rpc_call_ops nfs4_release_lockowner_ops = {
4588 .rpc_release = nfs4_release_lockowner_release,
4591 void nfs4_release_lockowner(const struct nfs4_lock_state *lsp)
4593 struct nfs_server *server = lsp->ls_state->owner->so_server;
4594 struct nfs_release_lockowner_args *args;
4595 struct rpc_message msg = {
4596 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
4599 if (server->nfs_client->cl_mvops->minor_version != 0)
4600 return;
4601 args = kmalloc(sizeof(*args), GFP_NOFS);
4602 if (!args)
4603 return;
4604 args->lock_owner.clientid = server->nfs_client->cl_clientid;
4605 args->lock_owner.id = lsp->ls_id.id;
4606 args->lock_owner.s_dev = server->s_dev;
4607 msg.rpc_argp = args;
4608 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args);
4611 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4613 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
4614 const void *buf, size_t buflen,
4615 int flags, int type)
4617 if (strcmp(key, "") != 0)
4618 return -EINVAL;
4620 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
4623 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
4624 void *buf, size_t buflen, int type)
4626 if (strcmp(key, "") != 0)
4627 return -EINVAL;
4629 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
4632 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
4633 size_t list_len, const char *name,
4634 size_t name_len, int type)
4636 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
4638 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
4639 return 0;
4641 if (list && len <= list_len)
4642 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
4643 return len;
4646 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4648 if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
4649 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4650 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
4651 return;
4653 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4654 NFS_ATTR_FATTR_NLINK;
4655 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4656 fattr->nlink = 2;
4659 int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4660 struct nfs4_fs_locations *fs_locations, struct page *page)
4662 struct nfs_server *server = NFS_SERVER(dir);
4663 u32 bitmask[2] = {
4664 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
4665 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
4667 struct nfs4_fs_locations_arg args = {
4668 .dir_fh = NFS_FH(dir),
4669 .name = name,
4670 .page = page,
4671 .bitmask = bitmask,
4673 struct nfs4_fs_locations_res res = {
4674 .fs_locations = fs_locations,
4676 struct rpc_message msg = {
4677 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
4678 .rpc_argp = &args,
4679 .rpc_resp = &res,
4681 int status;
4683 dprintk("%s: start\n", __func__);
4684 nfs_fattr_init(&fs_locations->fattr);
4685 fs_locations->server = server;
4686 fs_locations->nlocations = 0;
4687 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
4688 nfs_fixup_referral_attributes(&fs_locations->fattr);
4689 dprintk("%s: returned status = %d\n", __func__, status);
4690 return status;
4693 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
4695 int status;
4696 struct nfs4_secinfo_arg args = {
4697 .dir_fh = NFS_FH(dir),
4698 .name = name,
4700 struct nfs4_secinfo_res res = {
4701 .flavors = flavors,
4703 struct rpc_message msg = {
4704 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
4705 .rpc_argp = &args,
4706 .rpc_resp = &res,
4709 dprintk("NFS call secinfo %s\n", name->name);
4710 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
4711 dprintk("NFS reply secinfo: %d\n", status);
4712 return status;
4715 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
4717 struct nfs4_exception exception = { };
4718 int err;
4719 do {
4720 err = nfs4_handle_exception(NFS_SERVER(dir),
4721 _nfs4_proc_secinfo(dir, name, flavors),
4722 &exception);
4723 } while (exception.retry);
4724 return err;
4727 #ifdef CONFIG_NFS_V4_1
4729 * Check the exchange flags returned by the server for invalid flags, having
4730 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4731 * DS flags set.
4733 static int nfs4_check_cl_exchange_flags(u32 flags)
4735 if (flags & ~EXCHGID4_FLAG_MASK_R)
4736 goto out_inval;
4737 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
4738 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
4739 goto out_inval;
4740 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
4741 goto out_inval;
4742 return NFS_OK;
4743 out_inval:
4744 return -NFS4ERR_INVAL;
4748 * nfs4_proc_exchange_id()
4750 * Since the clientid has expired, all compounds using sessions
4751 * associated with the stale clientid will be returning
4752 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4753 * be in some phase of session reset.
4755 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4757 nfs4_verifier verifier;
4758 struct nfs41_exchange_id_args args = {
4759 .client = clp,
4760 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
4762 struct nfs41_exchange_id_res res = {
4763 .client = clp,
4765 int status;
4766 struct rpc_message msg = {
4767 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
4768 .rpc_argp = &args,
4769 .rpc_resp = &res,
4770 .rpc_cred = cred,
4772 __be32 *p;
4774 dprintk("--> %s\n", __func__);
4775 BUG_ON(clp == NULL);
4777 p = (u32 *)verifier.data;
4778 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4779 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4780 args.verifier = &verifier;
4782 args.id_len = scnprintf(args.id, sizeof(args.id),
4783 "%s/%s.%s/%u",
4784 clp->cl_ipaddr,
4785 init_utsname()->nodename,
4786 init_utsname()->domainname,
4787 clp->cl_rpcclient->cl_auth->au_flavor);
4789 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
4790 if (!status)
4791 status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
4792 dprintk("<-- %s status= %d\n", __func__, status);
4793 return status;
4796 struct nfs4_get_lease_time_data {
4797 struct nfs4_get_lease_time_args *args;
4798 struct nfs4_get_lease_time_res *res;
4799 struct nfs_client *clp;
4802 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4803 void *calldata)
4805 int ret;
4806 struct nfs4_get_lease_time_data *data =
4807 (struct nfs4_get_lease_time_data *)calldata;
4809 dprintk("--> %s\n", __func__);
4810 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4811 /* just setup sequence, do not trigger session recovery
4812 since we're invoked within one */
4813 ret = nfs41_setup_sequence(data->clp->cl_session,
4814 &data->args->la_seq_args,
4815 &data->res->lr_seq_res, 0, task);
4817 BUG_ON(ret == -EAGAIN);
4818 rpc_call_start(task);
4819 dprintk("<-- %s\n", __func__);
4823 * Called from nfs4_state_manager thread for session setup, so don't recover
4824 * from sequence operation or clientid errors.
4826 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4828 struct nfs4_get_lease_time_data *data =
4829 (struct nfs4_get_lease_time_data *)calldata;
4831 dprintk("--> %s\n", __func__);
4832 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
4833 return;
4834 switch (task->tk_status) {
4835 case -NFS4ERR_DELAY:
4836 case -NFS4ERR_GRACE:
4837 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
4838 rpc_delay(task, NFS4_POLL_RETRY_MIN);
4839 task->tk_status = 0;
4840 nfs_restart_rpc(task, data->clp);
4841 return;
4843 dprintk("<-- %s\n", __func__);
4846 struct rpc_call_ops nfs4_get_lease_time_ops = {
4847 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4848 .rpc_call_done = nfs4_get_lease_time_done,
4851 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4853 struct rpc_task *task;
4854 struct nfs4_get_lease_time_args args;
4855 struct nfs4_get_lease_time_res res = {
4856 .lr_fsinfo = fsinfo,
4858 struct nfs4_get_lease_time_data data = {
4859 .args = &args,
4860 .res = &res,
4861 .clp = clp,
4863 struct rpc_message msg = {
4864 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
4865 .rpc_argp = &args,
4866 .rpc_resp = &res,
4868 struct rpc_task_setup task_setup = {
4869 .rpc_client = clp->cl_rpcclient,
4870 .rpc_message = &msg,
4871 .callback_ops = &nfs4_get_lease_time_ops,
4872 .callback_data = &data
4874 int status;
4876 dprintk("--> %s\n", __func__);
4877 task = rpc_run_task(&task_setup);
4879 if (IS_ERR(task))
4880 status = PTR_ERR(task);
4881 else {
4882 status = task->tk_status;
4883 rpc_put_task(task);
4885 dprintk("<-- %s return %d\n", __func__, status);
4887 return status;
4891 * Reset a slot table
4893 static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
4894 int ivalue)
4896 struct nfs4_slot *new = NULL;
4897 int i;
4898 int ret = 0;
4900 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
4901 max_reqs, tbl->max_slots);
4903 /* Does the newly negotiated max_reqs match the existing slot table? */
4904 if (max_reqs != tbl->max_slots) {
4905 ret = -ENOMEM;
4906 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
4907 GFP_NOFS);
4908 if (!new)
4909 goto out;
4910 ret = 0;
4911 kfree(tbl->slots);
4913 spin_lock(&tbl->slot_tbl_lock);
4914 if (new) {
4915 tbl->slots = new;
4916 tbl->max_slots = max_reqs;
4918 for (i = 0; i < tbl->max_slots; ++i)
4919 tbl->slots[i].seq_nr = ivalue;
4920 spin_unlock(&tbl->slot_tbl_lock);
4921 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4922 tbl, tbl->slots, tbl->max_slots);
4923 out:
4924 dprintk("<-- %s: return %d\n", __func__, ret);
4925 return ret;
4929 * Reset the forechannel and backchannel slot tables
4931 static int nfs4_reset_slot_tables(struct nfs4_session *session)
4933 int status;
4935 status = nfs4_reset_slot_table(&session->fc_slot_table,
4936 session->fc_attrs.max_reqs, 1);
4937 if (status)
4938 return status;
4940 status = nfs4_reset_slot_table(&session->bc_slot_table,
4941 session->bc_attrs.max_reqs, 0);
4942 return status;
4945 /* Destroy the slot table */
4946 static void nfs4_destroy_slot_tables(struct nfs4_session *session)
4948 if (session->fc_slot_table.slots != NULL) {
4949 kfree(session->fc_slot_table.slots);
4950 session->fc_slot_table.slots = NULL;
4952 if (session->bc_slot_table.slots != NULL) {
4953 kfree(session->bc_slot_table.slots);
4954 session->bc_slot_table.slots = NULL;
4956 return;
4960 * Initialize slot table
4962 static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4963 int max_slots, int ivalue)
4965 struct nfs4_slot *slot;
4966 int ret = -ENOMEM;
4968 BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
4970 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
4972 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS);
4973 if (!slot)
4974 goto out;
4975 ret = 0;
4977 spin_lock(&tbl->slot_tbl_lock);
4978 tbl->max_slots = max_slots;
4979 tbl->slots = slot;
4980 tbl->highest_used_slotid = -1; /* no slot is currently used */
4981 spin_unlock(&tbl->slot_tbl_lock);
4982 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4983 tbl, tbl->slots, tbl->max_slots);
4984 out:
4985 dprintk("<-- %s: return %d\n", __func__, ret);
4986 return ret;
4990 * Initialize the forechannel and backchannel tables
4992 static int nfs4_init_slot_tables(struct nfs4_session *session)
4994 struct nfs4_slot_table *tbl;
4995 int status = 0;
4997 tbl = &session->fc_slot_table;
4998 if (tbl->slots == NULL) {
4999 status = nfs4_init_slot_table(tbl,
5000 session->fc_attrs.max_reqs, 1);
5001 if (status)
5002 return status;
5005 tbl = &session->bc_slot_table;
5006 if (tbl->slots == NULL) {
5007 status = nfs4_init_slot_table(tbl,
5008 session->bc_attrs.max_reqs, 0);
5009 if (status)
5010 nfs4_destroy_slot_tables(session);
5013 return status;
5016 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
5018 struct nfs4_session *session;
5019 struct nfs4_slot_table *tbl;
5021 session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5022 if (!session)
5023 return NULL;
5025 tbl = &session->fc_slot_table;
5026 tbl->highest_used_slotid = -1;
5027 spin_lock_init(&tbl->slot_tbl_lock);
5028 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
5029 init_completion(&tbl->complete);
5031 tbl = &session->bc_slot_table;
5032 tbl->highest_used_slotid = -1;
5033 spin_lock_init(&tbl->slot_tbl_lock);
5034 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
5035 init_completion(&tbl->complete);
5037 session->session_state = 1<<NFS4_SESSION_INITING;
5039 session->clp = clp;
5040 return session;
5043 void nfs4_destroy_session(struct nfs4_session *session)
5045 nfs4_proc_destroy_session(session);
5046 dprintk("%s Destroy backchannel for xprt %p\n",
5047 __func__, session->clp->cl_rpcclient->cl_xprt);
5048 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
5049 NFS41_BC_MIN_CALLBACKS);
5050 nfs4_destroy_slot_tables(session);
5051 kfree(session);
5055 * Initialize the values to be used by the client in CREATE_SESSION
5056 * If nfs4_init_session set the fore channel request and response sizes,
5057 * use them.
5059 * Set the back channel max_resp_sz_cached to zero to force the client to
5060 * always set csa_cachethis to FALSE because the current implementation
5061 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5063 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5065 struct nfs4_session *session = args->client->cl_session;
5066 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
5067 mxresp_sz = session->fc_attrs.max_resp_sz;
5069 if (mxrqst_sz == 0)
5070 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
5071 if (mxresp_sz == 0)
5072 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
5073 /* Fore channel attributes */
5074 args->fc_attrs.headerpadsz = 0;
5075 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5076 args->fc_attrs.max_resp_sz = mxresp_sz;
5077 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5078 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
5080 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5081 "max_ops=%u max_reqs=%u\n",
5082 __func__,
5083 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
5084 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
5086 /* Back channel attributes */
5087 args->bc_attrs.headerpadsz = 0;
5088 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
5089 args->bc_attrs.max_resp_sz = PAGE_SIZE;
5090 args->bc_attrs.max_resp_sz_cached = 0;
5091 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
5092 args->bc_attrs.max_reqs = 1;
5094 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5095 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5096 __func__,
5097 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
5098 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
5099 args->bc_attrs.max_reqs);
5102 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5104 struct nfs4_channel_attrs *sent = &args->fc_attrs;
5105 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
5107 if (rcvd->headerpadsz > sent->headerpadsz)
5108 return -EINVAL;
5109 if (rcvd->max_resp_sz > sent->max_resp_sz)
5110 return -EINVAL;
5112 * Our requested max_ops is the minimum we need; we're not
5113 * prepared to break up compounds into smaller pieces than that.
5114 * So, no point even trying to continue if the server won't
5115 * cooperate:
5117 if (rcvd->max_ops < sent->max_ops)
5118 return -EINVAL;
5119 if (rcvd->max_reqs == 0)
5120 return -EINVAL;
5121 return 0;
5124 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5126 struct nfs4_channel_attrs *sent = &args->bc_attrs;
5127 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
5129 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
5130 return -EINVAL;
5131 if (rcvd->max_resp_sz < sent->max_resp_sz)
5132 return -EINVAL;
5133 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5134 return -EINVAL;
5135 /* These would render the backchannel useless: */
5136 if (rcvd->max_ops == 0)
5137 return -EINVAL;
5138 if (rcvd->max_reqs == 0)
5139 return -EINVAL;
5140 return 0;
5143 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
5144 struct nfs4_session *session)
5146 int ret;
5148 ret = nfs4_verify_fore_channel_attrs(args, session);
5149 if (ret)
5150 return ret;
5151 return nfs4_verify_back_channel_attrs(args, session);
5154 static int _nfs4_proc_create_session(struct nfs_client *clp)
5156 struct nfs4_session *session = clp->cl_session;
5157 struct nfs41_create_session_args args = {
5158 .client = clp,
5159 .cb_program = NFS4_CALLBACK,
5161 struct nfs41_create_session_res res = {
5162 .client = clp,
5164 struct rpc_message msg = {
5165 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
5166 .rpc_argp = &args,
5167 .rpc_resp = &res,
5169 int status;
5171 nfs4_init_channel_attrs(&args);
5172 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
5174 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
5176 if (!status)
5177 /* Verify the session's negotiated channel_attrs values */
5178 status = nfs4_verify_channel_attrs(&args, session);
5179 if (!status) {
5180 /* Increment the clientid slot sequence id */
5181 clp->cl_seqid++;
5184 return status;
5188 * Issues a CREATE_SESSION operation to the server.
5189 * It is the responsibility of the caller to verify the session is
5190 * expired before calling this routine.
5192 int nfs4_proc_create_session(struct nfs_client *clp)
5194 int status;
5195 unsigned *ptr;
5196 struct nfs4_session *session = clp->cl_session;
5197 long timeout = 0;
5198 int err;
5200 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
5202 do {
5203 status = _nfs4_proc_create_session(clp);
5204 if (status == -NFS4ERR_DELAY) {
5205 err = nfs4_delay(clp->cl_rpcclient, &timeout);
5206 if (err)
5207 status = err;
5209 } while (status == -NFS4ERR_DELAY);
5211 if (status)
5212 goto out;
5214 /* Init and reset the fore channel */
5215 status = nfs4_init_slot_tables(session);
5216 dprintk("slot table initialization returned %d\n", status);
5217 if (status)
5218 goto out;
5219 status = nfs4_reset_slot_tables(session);
5220 dprintk("slot table reset returned %d\n", status);
5221 if (status)
5222 goto out;
5224 ptr = (unsigned *)&session->sess_id.data[0];
5225 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5226 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5227 out:
5228 dprintk("<-- %s\n", __func__);
5229 return status;
5233 * Issue the over-the-wire RPC DESTROY_SESSION.
5234 * The caller must serialize access to this routine.
5236 int nfs4_proc_destroy_session(struct nfs4_session *session)
5238 int status = 0;
5239 struct rpc_message msg;
5241 dprintk("--> nfs4_proc_destroy_session\n");
5243 /* session is still being setup */
5244 if (session->clp->cl_cons_state != NFS_CS_READY)
5245 return status;
5247 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION];
5248 msg.rpc_argp = session;
5249 msg.rpc_resp = NULL;
5250 msg.rpc_cred = NULL;
5251 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
5253 if (status)
5254 printk(KERN_WARNING
5255 "Got error %d from the server on DESTROY_SESSION. "
5256 "Session has been destroyed regardless...\n", status);
5258 dprintk("<-- nfs4_proc_destroy_session\n");
5259 return status;
5262 int nfs4_init_session(struct nfs_server *server)
5264 struct nfs_client *clp = server->nfs_client;
5265 struct nfs4_session *session;
5266 unsigned int rsize, wsize;
5267 int ret;
5269 if (!nfs4_has_session(clp))
5270 return 0;
5272 session = clp->cl_session;
5273 if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state))
5274 return 0;
5276 rsize = server->rsize;
5277 if (rsize == 0)
5278 rsize = NFS_MAX_FILE_IO_SIZE;
5279 wsize = server->wsize;
5280 if (wsize == 0)
5281 wsize = NFS_MAX_FILE_IO_SIZE;
5283 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5284 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5286 ret = nfs4_recover_expired_lease(server);
5287 if (!ret)
5288 ret = nfs4_check_client_ready(clp);
5289 return ret;
5292 int nfs4_init_ds_session(struct nfs_client *clp)
5294 struct nfs4_session *session = clp->cl_session;
5295 int ret;
5297 if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state))
5298 return 0;
5300 ret = nfs4_client_recover_expired_lease(clp);
5301 if (!ret)
5302 /* Test for the DS role */
5303 if (!is_ds_client(clp))
5304 ret = -ENODEV;
5305 if (!ret)
5306 ret = nfs4_check_client_ready(clp);
5307 return ret;
5310 EXPORT_SYMBOL_GPL(nfs4_init_ds_session);
5314 * Renew the cl_session lease.
5316 struct nfs4_sequence_data {
5317 struct nfs_client *clp;
5318 struct nfs4_sequence_args args;
5319 struct nfs4_sequence_res res;
5322 static void nfs41_sequence_release(void *data)
5324 struct nfs4_sequence_data *calldata = data;
5325 struct nfs_client *clp = calldata->clp;
5327 if (atomic_read(&clp->cl_count) > 1)
5328 nfs4_schedule_state_renewal(clp);
5329 nfs_put_client(clp);
5330 kfree(calldata);
5333 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5335 switch(task->tk_status) {
5336 case -NFS4ERR_DELAY:
5337 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5338 return -EAGAIN;
5339 default:
5340 nfs4_schedule_lease_recovery(clp);
5342 return 0;
5345 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5347 struct nfs4_sequence_data *calldata = data;
5348 struct nfs_client *clp = calldata->clp;
5350 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
5351 return;
5353 if (task->tk_status < 0) {
5354 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5355 if (atomic_read(&clp->cl_count) == 1)
5356 goto out;
5358 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
5359 rpc_restart_call_prepare(task);
5360 return;
5363 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5364 out:
5365 dprintk("<-- %s\n", __func__);
5368 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5370 struct nfs4_sequence_data *calldata = data;
5371 struct nfs_client *clp = calldata->clp;
5372 struct nfs4_sequence_args *args;
5373 struct nfs4_sequence_res *res;
5375 args = task->tk_msg.rpc_argp;
5376 res = task->tk_msg.rpc_resp;
5378 if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task))
5379 return;
5380 rpc_call_start(task);
5383 static const struct rpc_call_ops nfs41_sequence_ops = {
5384 .rpc_call_done = nfs41_sequence_call_done,
5385 .rpc_call_prepare = nfs41_sequence_prepare,
5386 .rpc_release = nfs41_sequence_release,
5389 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5391 struct nfs4_sequence_data *calldata;
5392 struct rpc_message msg = {
5393 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5394 .rpc_cred = cred,
5396 struct rpc_task_setup task_setup_data = {
5397 .rpc_client = clp->cl_rpcclient,
5398 .rpc_message = &msg,
5399 .callback_ops = &nfs41_sequence_ops,
5400 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
5403 if (!atomic_inc_not_zero(&clp->cl_count))
5404 return ERR_PTR(-EIO);
5405 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5406 if (calldata == NULL) {
5407 nfs_put_client(clp);
5408 return ERR_PTR(-ENOMEM);
5410 msg.rpc_argp = &calldata->args;
5411 msg.rpc_resp = &calldata->res;
5412 calldata->clp = clp;
5413 task_setup_data.callback_data = calldata;
5415 return rpc_run_task(&task_setup_data);
5418 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5420 struct rpc_task *task;
5421 int ret = 0;
5423 task = _nfs41_proc_sequence(clp, cred);
5424 if (IS_ERR(task))
5425 ret = PTR_ERR(task);
5426 else
5427 rpc_put_task_async(task);
5428 dprintk("<-- %s status=%d\n", __func__, ret);
5429 return ret;
5432 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5434 struct rpc_task *task;
5435 int ret;
5437 task = _nfs41_proc_sequence(clp, cred);
5438 if (IS_ERR(task)) {
5439 ret = PTR_ERR(task);
5440 goto out;
5442 ret = rpc_wait_for_completion_task(task);
5443 if (!ret) {
5444 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
5446 if (task->tk_status == 0)
5447 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
5448 ret = task->tk_status;
5450 rpc_put_task(task);
5451 out:
5452 dprintk("<-- %s status=%d\n", __func__, ret);
5453 return ret;
5456 struct nfs4_reclaim_complete_data {
5457 struct nfs_client *clp;
5458 struct nfs41_reclaim_complete_args arg;
5459 struct nfs41_reclaim_complete_res res;
5462 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5464 struct nfs4_reclaim_complete_data *calldata = data;
5466 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5467 if (nfs41_setup_sequence(calldata->clp->cl_session,
5468 &calldata->arg.seq_args,
5469 &calldata->res.seq_res, 0, task))
5470 return;
5472 rpc_call_start(task);
5475 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5477 switch(task->tk_status) {
5478 case 0:
5479 case -NFS4ERR_COMPLETE_ALREADY:
5480 case -NFS4ERR_WRONG_CRED: /* What to do here? */
5481 break;
5482 case -NFS4ERR_DELAY:
5483 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5484 return -EAGAIN;
5485 default:
5486 nfs4_schedule_lease_recovery(clp);
5488 return 0;
5491 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
5493 struct nfs4_reclaim_complete_data *calldata = data;
5494 struct nfs_client *clp = calldata->clp;
5495 struct nfs4_sequence_res *res = &calldata->res.seq_res;
5497 dprintk("--> %s\n", __func__);
5498 if (!nfs41_sequence_done(task, res))
5499 return;
5501 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
5502 rpc_restart_call_prepare(task);
5503 return;
5505 dprintk("<-- %s\n", __func__);
5508 static void nfs4_free_reclaim_complete_data(void *data)
5510 struct nfs4_reclaim_complete_data *calldata = data;
5512 kfree(calldata);
5515 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
5516 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
5517 .rpc_call_done = nfs4_reclaim_complete_done,
5518 .rpc_release = nfs4_free_reclaim_complete_data,
5522 * Issue a global reclaim complete.
5524 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5526 struct nfs4_reclaim_complete_data *calldata;
5527 struct rpc_task *task;
5528 struct rpc_message msg = {
5529 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
5531 struct rpc_task_setup task_setup_data = {
5532 .rpc_client = clp->cl_rpcclient,
5533 .rpc_message = &msg,
5534 .callback_ops = &nfs4_reclaim_complete_call_ops,
5535 .flags = RPC_TASK_ASYNC,
5537 int status = -ENOMEM;
5539 dprintk("--> %s\n", __func__);
5540 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5541 if (calldata == NULL)
5542 goto out;
5543 calldata->clp = clp;
5544 calldata->arg.one_fs = 0;
5546 msg.rpc_argp = &calldata->arg;
5547 msg.rpc_resp = &calldata->res;
5548 task_setup_data.callback_data = calldata;
5549 task = rpc_run_task(&task_setup_data);
5550 if (IS_ERR(task)) {
5551 status = PTR_ERR(task);
5552 goto out;
5554 status = nfs4_wait_for_completion_rpc_task(task);
5555 if (status == 0)
5556 status = task->tk_status;
5557 rpc_put_task(task);
5558 return 0;
5559 out:
5560 dprintk("<-- %s status=%d\n", __func__, status);
5561 return status;
5564 static void
5565 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
5567 struct nfs4_layoutget *lgp = calldata;
5568 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
5570 dprintk("--> %s\n", __func__);
5571 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5572 * right now covering the LAYOUTGET we are about to send.
5573 * However, that is not so catastrophic, and there seems
5574 * to be no way to prevent it completely.
5576 if (nfs4_setup_sequence(server, &lgp->args.seq_args,
5577 &lgp->res.seq_res, 0, task))
5578 return;
5579 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
5580 NFS_I(lgp->args.inode)->layout,
5581 lgp->args.ctx->state)) {
5582 rpc_exit(task, NFS4_OK);
5583 return;
5585 rpc_call_start(task);
5588 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
5590 struct nfs4_layoutget *lgp = calldata;
5591 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
5593 dprintk("--> %s\n", __func__);
5595 if (!nfs4_sequence_done(task, &lgp->res.seq_res))
5596 return;
5598 switch (task->tk_status) {
5599 case 0:
5600 break;
5601 case -NFS4ERR_LAYOUTTRYLATER:
5602 case -NFS4ERR_RECALLCONFLICT:
5603 task->tk_status = -NFS4ERR_DELAY;
5604 /* Fall through */
5605 default:
5606 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
5607 rpc_restart_call_prepare(task);
5608 return;
5611 dprintk("<-- %s\n", __func__);
5614 static void nfs4_layoutget_release(void *calldata)
5616 struct nfs4_layoutget *lgp = calldata;
5618 dprintk("--> %s\n", __func__);
5619 put_nfs_open_context(lgp->args.ctx);
5620 kfree(calldata);
5621 dprintk("<-- %s\n", __func__);
5624 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
5625 .rpc_call_prepare = nfs4_layoutget_prepare,
5626 .rpc_call_done = nfs4_layoutget_done,
5627 .rpc_release = nfs4_layoutget_release,
5630 int nfs4_proc_layoutget(struct nfs4_layoutget *lgp)
5632 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
5633 struct rpc_task *task;
5634 struct rpc_message msg = {
5635 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
5636 .rpc_argp = &lgp->args,
5637 .rpc_resp = &lgp->res,
5639 struct rpc_task_setup task_setup_data = {
5640 .rpc_client = server->client,
5641 .rpc_message = &msg,
5642 .callback_ops = &nfs4_layoutget_call_ops,
5643 .callback_data = lgp,
5644 .flags = RPC_TASK_ASYNC,
5646 int status = 0;
5648 dprintk("--> %s\n", __func__);
5650 lgp->res.layoutp = &lgp->args.layout;
5651 lgp->res.seq_res.sr_slot = NULL;
5652 task = rpc_run_task(&task_setup_data);
5653 if (IS_ERR(task))
5654 return PTR_ERR(task);
5655 status = nfs4_wait_for_completion_rpc_task(task);
5656 if (status == 0)
5657 status = task->tk_status;
5658 if (status == 0)
5659 status = pnfs_layout_process(lgp);
5660 rpc_put_task(task);
5661 dprintk("<-- %s status=%d\n", __func__, status);
5662 return status;
5665 static int
5666 _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
5668 struct nfs4_getdeviceinfo_args args = {
5669 .pdev = pdev,
5671 struct nfs4_getdeviceinfo_res res = {
5672 .pdev = pdev,
5674 struct rpc_message msg = {
5675 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
5676 .rpc_argp = &args,
5677 .rpc_resp = &res,
5679 int status;
5681 dprintk("--> %s\n", __func__);
5682 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
5683 dprintk("<-- %s status=%d\n", __func__, status);
5685 return status;
5688 int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
5690 struct nfs4_exception exception = { };
5691 int err;
5693 do {
5694 err = nfs4_handle_exception(server,
5695 _nfs4_proc_getdeviceinfo(server, pdev),
5696 &exception);
5697 } while (exception.retry);
5698 return err;
5700 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
5702 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
5704 struct nfs4_layoutcommit_data *data = calldata;
5705 struct nfs_server *server = NFS_SERVER(data->args.inode);
5707 if (nfs4_setup_sequence(server, &data->args.seq_args,
5708 &data->res.seq_res, 1, task))
5709 return;
5710 rpc_call_start(task);
5713 static void
5714 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
5716 struct nfs4_layoutcommit_data *data = calldata;
5717 struct nfs_server *server = NFS_SERVER(data->args.inode);
5719 if (!nfs4_sequence_done(task, &data->res.seq_res))
5720 return;
5722 switch (task->tk_status) { /* Just ignore these failures */
5723 case NFS4ERR_DELEG_REVOKED: /* layout was recalled */
5724 case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
5725 case NFS4ERR_BADLAYOUT: /* no layout */
5726 case NFS4ERR_GRACE: /* loca_recalim always false */
5727 task->tk_status = 0;
5730 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
5731 nfs_restart_rpc(task, server->nfs_client);
5732 return;
5735 if (task->tk_status == 0)
5736 nfs_post_op_update_inode_force_wcc(data->args.inode,
5737 data->res.fattr);
5740 static void nfs4_layoutcommit_release(void *calldata)
5742 struct nfs4_layoutcommit_data *data = calldata;
5744 /* Matched by references in pnfs_set_layoutcommit */
5745 put_lseg(data->lseg);
5746 put_rpccred(data->cred);
5747 kfree(data);
5750 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
5751 .rpc_call_prepare = nfs4_layoutcommit_prepare,
5752 .rpc_call_done = nfs4_layoutcommit_done,
5753 .rpc_release = nfs4_layoutcommit_release,
5757 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
5759 struct rpc_message msg = {
5760 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
5761 .rpc_argp = &data->args,
5762 .rpc_resp = &data->res,
5763 .rpc_cred = data->cred,
5765 struct rpc_task_setup task_setup_data = {
5766 .task = &data->task,
5767 .rpc_client = NFS_CLIENT(data->args.inode),
5768 .rpc_message = &msg,
5769 .callback_ops = &nfs4_layoutcommit_ops,
5770 .callback_data = data,
5771 .flags = RPC_TASK_ASYNC,
5773 struct rpc_task *task;
5774 int status = 0;
5776 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
5777 "lbw: %llu inode %lu\n",
5778 data->task.tk_pid, sync,
5779 data->args.lastbytewritten,
5780 data->args.inode->i_ino);
5782 task = rpc_run_task(&task_setup_data);
5783 if (IS_ERR(task))
5784 return PTR_ERR(task);
5785 if (sync == false)
5786 goto out;
5787 status = nfs4_wait_for_completion_rpc_task(task);
5788 if (status != 0)
5789 goto out;
5790 status = task->tk_status;
5791 out:
5792 dprintk("%s: status %d\n", __func__, status);
5793 rpc_put_task(task);
5794 return status;
5796 #endif /* CONFIG_NFS_V4_1 */
5798 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
5799 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5800 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5801 .recover_open = nfs4_open_reclaim,
5802 .recover_lock = nfs4_lock_reclaim,
5803 .establish_clid = nfs4_init_clientid,
5804 .get_clid_cred = nfs4_get_setclientid_cred,
5807 #if defined(CONFIG_NFS_V4_1)
5808 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
5809 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5810 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5811 .recover_open = nfs4_open_reclaim,
5812 .recover_lock = nfs4_lock_reclaim,
5813 .establish_clid = nfs41_init_clientid,
5814 .get_clid_cred = nfs4_get_exchange_id_cred,
5815 .reclaim_complete = nfs41_proc_reclaim_complete,
5817 #endif /* CONFIG_NFS_V4_1 */
5819 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
5820 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5821 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5822 .recover_open = nfs4_open_expired,
5823 .recover_lock = nfs4_lock_expired,
5824 .establish_clid = nfs4_init_clientid,
5825 .get_clid_cred = nfs4_get_setclientid_cred,
5828 #if defined(CONFIG_NFS_V4_1)
5829 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
5830 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5831 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5832 .recover_open = nfs4_open_expired,
5833 .recover_lock = nfs4_lock_expired,
5834 .establish_clid = nfs41_init_clientid,
5835 .get_clid_cred = nfs4_get_exchange_id_cred,
5837 #endif /* CONFIG_NFS_V4_1 */
5839 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
5840 .sched_state_renewal = nfs4_proc_async_renew,
5841 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
5842 .renew_lease = nfs4_proc_renew,
5845 #if defined(CONFIG_NFS_V4_1)
5846 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
5847 .sched_state_renewal = nfs41_proc_async_sequence,
5848 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
5849 .renew_lease = nfs4_proc_sequence,
5851 #endif
5853 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
5854 .minor_version = 0,
5855 .call_sync = _nfs4_call_sync,
5856 .validate_stateid = nfs4_validate_delegation_stateid,
5857 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
5858 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
5859 .state_renewal_ops = &nfs40_state_renewal_ops,
5862 #if defined(CONFIG_NFS_V4_1)
5863 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
5864 .minor_version = 1,
5865 .call_sync = _nfs4_call_sync_session,
5866 .validate_stateid = nfs41_validate_delegation_stateid,
5867 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
5868 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
5869 .state_renewal_ops = &nfs41_state_renewal_ops,
5871 #endif
5873 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
5874 [0] = &nfs_v4_0_minor_ops,
5875 #if defined(CONFIG_NFS_V4_1)
5876 [1] = &nfs_v4_1_minor_ops,
5877 #endif
5880 static const struct inode_operations nfs4_file_inode_operations = {
5881 .permission = nfs_permission,
5882 .getattr = nfs_getattr,
5883 .setattr = nfs_setattr,
5884 .getxattr = generic_getxattr,
5885 .setxattr = generic_setxattr,
5886 .listxattr = generic_listxattr,
5887 .removexattr = generic_removexattr,
5890 const struct nfs_rpc_ops nfs_v4_clientops = {
5891 .version = 4, /* protocol version */
5892 .dentry_ops = &nfs4_dentry_operations,
5893 .dir_inode_ops = &nfs4_dir_inode_operations,
5894 .file_inode_ops = &nfs4_file_inode_operations,
5895 .getroot = nfs4_proc_get_root,
5896 .getattr = nfs4_proc_getattr,
5897 .setattr = nfs4_proc_setattr,
5898 .lookupfh = nfs4_proc_lookupfh,
5899 .lookup = nfs4_proc_lookup,
5900 .access = nfs4_proc_access,
5901 .readlink = nfs4_proc_readlink,
5902 .create = nfs4_proc_create,
5903 .remove = nfs4_proc_remove,
5904 .unlink_setup = nfs4_proc_unlink_setup,
5905 .unlink_done = nfs4_proc_unlink_done,
5906 .rename = nfs4_proc_rename,
5907 .rename_setup = nfs4_proc_rename_setup,
5908 .rename_done = nfs4_proc_rename_done,
5909 .link = nfs4_proc_link,
5910 .symlink = nfs4_proc_symlink,
5911 .mkdir = nfs4_proc_mkdir,
5912 .rmdir = nfs4_proc_remove,
5913 .readdir = nfs4_proc_readdir,
5914 .mknod = nfs4_proc_mknod,
5915 .statfs = nfs4_proc_statfs,
5916 .fsinfo = nfs4_proc_fsinfo,
5917 .pathconf = nfs4_proc_pathconf,
5918 .set_capabilities = nfs4_server_capabilities,
5919 .decode_dirent = nfs4_decode_dirent,
5920 .read_setup = nfs4_proc_read_setup,
5921 .read_done = nfs4_read_done,
5922 .write_setup = nfs4_proc_write_setup,
5923 .write_done = nfs4_write_done,
5924 .commit_setup = nfs4_proc_commit_setup,
5925 .commit_done = nfs4_commit_done,
5926 .lock = nfs4_proc_lock,
5927 .clear_acl_cache = nfs4_zap_acl_attr,
5928 .close_context = nfs4_close_context,
5929 .open_context = nfs4_atomic_open,
5930 .init_client = nfs4_init_client,
5931 .secinfo = nfs4_proc_secinfo,
5934 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
5935 .prefix = XATTR_NAME_NFSV4_ACL,
5936 .list = nfs4_xattr_list_nfs4_acl,
5937 .get = nfs4_xattr_get_nfs4_acl,
5938 .set = nfs4_xattr_set_nfs4_acl,
5941 const struct xattr_handler *nfs4_xattr_handlers[] = {
5942 &nfs4_xattr_nfs4_acl_handler,
5943 NULL
5947 * Local variables:
5948 * c-basic-offset: 8
5949 * End: