NFSv4: Eliminate nfsv4 open race...
[linux-2.6-block.git] / fs / nfs / nfs4proc.c
CommitLineData
1da177e4
LT
1/*
2 * fs/nfs/nfs4proc.c
3 *
4 * Client-side procedure declarations for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/mm.h>
39#include <linux/utsname.h>
40#include <linux/delay.h>
41#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/sunrpc/clnt.h>
44#include <linux/nfs.h>
45#include <linux/nfs4.h>
46#include <linux/nfs_fs.h>
47#include <linux/nfs_page.h>
48#include <linux/smp_lock.h>
49#include <linux/namei.h>
02a913a7 50#include <linux/mount.h>
1da177e4 51
4ce79717 52#include "nfs4_fs.h"
1da177e4
LT
53#include "delegation.h"
54
55#define NFSDBG_FACILITY NFSDBG_PROC
56
57#define NFS4_POLL_RETRY_MIN (1*HZ)
58#define NFS4_POLL_RETRY_MAX (15*HZ)
59
0a8838f9 60static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid);
1da177e4 61static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
faf5f49c 62static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *);
1da177e4 63static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
faf5f49c 64static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
1da177e4
LT
65extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
66extern struct rpc_procinfo nfs4_procedures[];
67
1da177e4
LT
68/* Prevent leaks of NFSv4 errors into userland */
69int nfs4_map_errors(int err)
70{
71 if (err < -1000) {
72 dprintk("%s could not handle NFSv4 error %d\n",
73 __FUNCTION__, -err);
74 return -EIO;
75 }
76 return err;
77}
78
79/*
80 * This is our standard bitmap for GETATTR requests.
81 */
82const u32 nfs4_fattr_bitmap[2] = {
83 FATTR4_WORD0_TYPE
84 | FATTR4_WORD0_CHANGE
85 | FATTR4_WORD0_SIZE
86 | FATTR4_WORD0_FSID
87 | FATTR4_WORD0_FILEID,
88 FATTR4_WORD1_MODE
89 | FATTR4_WORD1_NUMLINKS
90 | FATTR4_WORD1_OWNER
91 | FATTR4_WORD1_OWNER_GROUP
92 | FATTR4_WORD1_RAWDEV
93 | FATTR4_WORD1_SPACE_USED
94 | FATTR4_WORD1_TIME_ACCESS
95 | FATTR4_WORD1_TIME_METADATA
96 | FATTR4_WORD1_TIME_MODIFY
97};
98
99const u32 nfs4_statfs_bitmap[2] = {
100 FATTR4_WORD0_FILES_AVAIL
101 | FATTR4_WORD0_FILES_FREE
102 | FATTR4_WORD0_FILES_TOTAL,
103 FATTR4_WORD1_SPACE_AVAIL
104 | FATTR4_WORD1_SPACE_FREE
105 | FATTR4_WORD1_SPACE_TOTAL
106};
107
4ce79717 108const u32 nfs4_pathconf_bitmap[2] = {
1da177e4
LT
109 FATTR4_WORD0_MAXLINK
110 | FATTR4_WORD0_MAXNAME,
111 0
112};
113
114const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
115 | FATTR4_WORD0_MAXREAD
116 | FATTR4_WORD0_MAXWRITE
117 | FATTR4_WORD0_LEASE_TIME,
118 0
119};
120
121static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry,
122 struct nfs4_readdir_arg *readdir)
123{
124 u32 *start, *p;
125
126 BUG_ON(readdir->count < 80);
127 if (cookie > 2) {
b7ef1956 128 readdir->cookie = cookie;
1da177e4
LT
129 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
130 return;
131 }
132
133 readdir->cookie = 0;
134 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
135 if (cookie == 2)
136 return;
137
138 /*
139 * NFSv4 servers do not return entries for '.' and '..'
140 * Therefore, we fake these entries here. We let '.'
141 * have cookie 0 and '..' have cookie 1. Note that
142 * when talking to the server, we always send cookie 0
143 * instead of 1 or 2.
144 */
145 start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0);
146
147 if (cookie == 0) {
148 *p++ = xdr_one; /* next */
149 *p++ = xdr_zero; /* cookie, first word */
150 *p++ = xdr_one; /* cookie, second word */
151 *p++ = xdr_one; /* entry len */
152 memcpy(p, ".\0\0\0", 4); /* entry */
153 p++;
154 *p++ = xdr_one; /* bitmap length */
155 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
156 *p++ = htonl(8); /* attribute buffer length */
157 p = xdr_encode_hyper(p, dentry->d_inode->i_ino);
158 }
159
160 *p++ = xdr_one; /* next */
161 *p++ = xdr_zero; /* cookie, first word */
162 *p++ = xdr_two; /* cookie, second word */
163 *p++ = xdr_two; /* entry len */
164 memcpy(p, "..\0\0", 4); /* entry */
165 p++;
166 *p++ = xdr_one; /* bitmap length */
167 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
168 *p++ = htonl(8); /* attribute buffer length */
169 p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino);
170
171 readdir->pgbase = (char *)p - (char *)start;
172 readdir->count -= readdir->pgbase;
173 kunmap_atomic(start, KM_USER0);
174}
175
176static void
177renew_lease(struct nfs_server *server, unsigned long timestamp)
178{
179 struct nfs4_client *clp = server->nfs4_state;
180 spin_lock(&clp->cl_lock);
181 if (time_before(clp->cl_last_renewal,timestamp))
182 clp->cl_last_renewal = timestamp;
183 spin_unlock(&clp->cl_lock);
184}
185
186static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo)
187{
188 struct nfs_inode *nfsi = NFS_I(inode);
189
190 if (cinfo->before == nfsi->change_attr && cinfo->atomic)
191 nfsi->change_attr = cinfo->after;
192}
193
9512135d
TM
194/* Helper for asynchronous RPC calls */
195static int nfs4_call_async(struct rpc_clnt *clnt, rpc_action tk_begin,
196 rpc_action tk_exit, void *calldata)
197{
198 struct rpc_task *task;
199
200 if (!(task = rpc_new_task(clnt, tk_exit, RPC_TASK_ASYNC)))
201 return -ENOMEM;
202
203 task->tk_calldata = calldata;
204 task->tk_action = tk_begin;
205 rpc_execute(task);
206 return 0;
207}
208
1da177e4
LT
209static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
210{
211 struct inode *inode = state->inode;
212
213 open_flags &= (FMODE_READ|FMODE_WRITE);
214 /* Protect against nfs4_find_state() */
215 spin_lock(&inode->i_lock);
216 state->state |= open_flags;
217 /* NB! List reordering - see the reclaim code for why. */
218 if ((open_flags & FMODE_WRITE) && 0 == state->nwriters++)
219 list_move(&state->open_states, &state->owner->so_states);
220 if (open_flags & FMODE_READ)
221 state->nreaders++;
222 memcpy(&state->stateid, stateid, sizeof(state->stateid));
223 spin_unlock(&inode->i_lock);
224}
225
226/*
227 * OPEN_RECLAIM:
228 * reclaim state on the server after a reboot.
1da177e4
LT
229 */
230static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
231{
232 struct inode *inode = state->inode;
233 struct nfs_server *server = NFS_SERVER(inode);
234 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
235 struct nfs_openargs o_arg = {
236 .fh = NFS_FH(inode),
1da177e4
LT
237 .id = sp->so_id,
238 .open_flags = state->state,
239 .clientid = server->nfs4_state->cl_clientid,
240 .claim = NFS4_OPEN_CLAIM_PREVIOUS,
241 .bitmask = server->attr_bitmask,
242 };
243 struct nfs_openres o_res = {
244 .server = server, /* Grrr */
245 };
246 struct rpc_message msg = {
247 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
248 .rpc_argp = &o_arg,
249 .rpc_resp = &o_res,
250 .rpc_cred = sp->so_cred,
251 };
252 int status;
253
254 if (delegation != NULL) {
255 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
256 memcpy(&state->stateid, &delegation->stateid,
257 sizeof(state->stateid));
258 set_bit(NFS_DELEGATED_STATE, &state->flags);
259 return 0;
260 }
261 o_arg.u.delegation_type = delegation->type;
262 }
cee54fc9
TM
263 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
264 if (o_arg.seqid == NULL)
265 return -ENOMEM;
1da177e4 266 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
cee54fc9
TM
267 /* Confirm the sequence as being established */
268 nfs_confirm_seqid(&sp->so_seqid, status);
269 nfs_increment_open_seqid(status, o_arg.seqid);
1da177e4
LT
270 if (status == 0) {
271 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
272 if (o_res.delegation_type != 0) {
273 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
274 /* Did the server issue an immediate delegation recall? */
275 if (o_res.do_recall)
276 nfs_async_inode_return_delegation(inode, &o_res.stateid);
277 }
278 }
cee54fc9 279 nfs_free_seqid(o_arg.seqid);
1da177e4
LT
280 clear_bit(NFS_DELEGATED_STATE, &state->flags);
281 /* Ensure we update the inode attributes */
282 NFS_CACHEINV(inode);
283 return status;
284}
285
286static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
287{
288 struct nfs_server *server = NFS_SERVER(state->inode);
289 struct nfs4_exception exception = { };
290 int err;
291 do {
292 err = _nfs4_open_reclaim(sp, state);
202b50dc
TM
293 if (err != -NFS4ERR_DELAY)
294 break;
295 nfs4_handle_exception(server, err, &exception);
1da177e4
LT
296 } while (exception.retry);
297 return err;
298}
299
300static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
301{
302 struct nfs4_state_owner *sp = state->owner;
303 struct inode *inode = dentry->d_inode;
304 struct nfs_server *server = NFS_SERVER(inode);
305 struct dentry *parent = dget_parent(dentry);
306 struct nfs_openargs arg = {
307 .fh = NFS_FH(parent->d_inode),
308 .clientid = server->nfs4_state->cl_clientid,
309 .name = &dentry->d_name,
310 .id = sp->so_id,
311 .server = server,
312 .bitmask = server->attr_bitmask,
313 .claim = NFS4_OPEN_CLAIM_DELEGATE_CUR,
314 };
315 struct nfs_openres res = {
316 .server = server,
317 };
318 struct rpc_message msg = {
319 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
320 .rpc_argp = &arg,
321 .rpc_resp = &res,
322 .rpc_cred = sp->so_cred,
323 };
324 int status = 0;
325
1da177e4
LT
326 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
327 goto out;
328 if (state->state == 0)
329 goto out;
cee54fc9
TM
330 arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
331 status = -ENOMEM;
332 if (arg.seqid == NULL)
333 goto out;
1da177e4
LT
334 arg.open_flags = state->state;
335 memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data));
336 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
cee54fc9 337 nfs_increment_open_seqid(status, arg.seqid);
0a8838f9
TM
338 if (status != 0)
339 goto out_free;
340 if(res.rflags & NFS4_OPEN_RESULT_CONFIRM) {
341 status = _nfs4_proc_open_confirm(server->client, NFS_FH(inode),
342 sp, &res.stateid, arg.seqid);
343 if (status != 0)
344 goto out_free;
345 }
346 nfs_confirm_seqid(&sp->so_seqid, 0);
1da177e4
LT
347 if (status >= 0) {
348 memcpy(state->stateid.data, res.stateid.data,
349 sizeof(state->stateid.data));
350 clear_bit(NFS_DELEGATED_STATE, &state->flags);
351 }
0a8838f9 352out_free:
cee54fc9 353 nfs_free_seqid(arg.seqid);
1da177e4 354out:
1da177e4
LT
355 dput(parent);
356 return status;
357}
358
359int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
360{
361 struct nfs4_exception exception = { };
362 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
363 int err;
364 do {
365 err = _nfs4_open_delegation_recall(dentry, state);
366 switch (err) {
367 case 0:
368 return err;
369 case -NFS4ERR_STALE_CLIENTID:
370 case -NFS4ERR_STALE_STATEID:
371 case -NFS4ERR_EXPIRED:
372 /* Don't recall a delegation if it was lost */
373 nfs4_schedule_state_recovery(server->nfs4_state);
374 return err;
375 }
376 err = nfs4_handle_exception(server, err, &exception);
377 } while (exception.retry);
378 return err;
379}
380
0a8838f9 381static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid)
1da177e4
LT
382{
383 struct nfs_open_confirmargs arg = {
384 .fh = fh,
cee54fc9 385 .seqid = seqid,
1da177e4
LT
386 .stateid = *stateid,
387 };
388 struct nfs_open_confirmres res;
389 struct rpc_message msg = {
390 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
391 .rpc_argp = &arg,
392 .rpc_resp = &res,
393 .rpc_cred = sp->so_cred,
394 };
395 int status;
396
397 status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR);
cee54fc9
TM
398 /* Confirm the sequence as being established */
399 nfs_confirm_seqid(&sp->so_seqid, status);
400 nfs_increment_open_seqid(status, seqid);
1da177e4
LT
401 if (status >= 0)
402 memcpy(stateid, &res.stateid, sizeof(*stateid));
403 return status;
404}
405
406static int _nfs4_proc_open(struct inode *dir, struct nfs4_state_owner *sp, struct nfs_openargs *o_arg, struct nfs_openres *o_res)
407{
408 struct nfs_server *server = NFS_SERVER(dir);
409 struct rpc_message msg = {
410 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
411 .rpc_argp = o_arg,
412 .rpc_resp = o_res,
413 .rpc_cred = sp->so_cred,
414 };
415 int status;
416
417 /* Update sequence id. The caller must serialize! */
1da177e4
LT
418 o_arg->id = sp->so_id;
419 o_arg->clientid = sp->so_client->cl_clientid;
420
421 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
cee54fc9 422 nfs_increment_open_seqid(status, o_arg->seqid);
1da177e4
LT
423 if (status != 0)
424 goto out;
425 update_changeattr(dir, &o_res->cinfo);
426 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
427 status = _nfs4_proc_open_confirm(server->client, &o_res->fh,
cee54fc9 428 sp, &o_res->stateid, o_arg->seqid);
1da177e4
LT
429 if (status != 0)
430 goto out;
431 }
cee54fc9 432 nfs_confirm_seqid(&sp->so_seqid, 0);
1da177e4
LT
433 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
434 status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr);
435out:
436 return status;
437}
438
439static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags)
440{
441 struct nfs_access_entry cache;
442 int mask = 0;
443 int status;
444
445 if (openflags & FMODE_READ)
446 mask |= MAY_READ;
447 if (openflags & FMODE_WRITE)
448 mask |= MAY_WRITE;
449 status = nfs_access_get_cached(inode, cred, &cache);
450 if (status == 0)
451 goto out;
452
453 /* Be clever: ask server to check for all possible rights */
454 cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ;
455 cache.cred = cred;
456 cache.jiffies = jiffies;
457 status = _nfs4_proc_access(inode, &cache);
458 if (status != 0)
459 return status;
460 nfs_access_add_cache(inode, &cache);
461out:
462 if ((cache.mask & mask) == mask)
463 return 0;
464 return -EACCES;
465}
466
467/*
468 * OPEN_EXPIRED:
469 * reclaim state on the server after a network partition.
470 * Assumes caller holds the appropriate lock
471 */
472static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
473{
474 struct dentry *parent = dget_parent(dentry);
475 struct inode *dir = parent->d_inode;
476 struct inode *inode = state->inode;
477 struct nfs_server *server = NFS_SERVER(dir);
478 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
479 struct nfs_fattr f_attr = {
480 .valid = 0,
481 };
482 struct nfs_openargs o_arg = {
483 .fh = NFS_FH(dir),
484 .open_flags = state->state,
485 .name = &dentry->d_name,
486 .bitmask = server->attr_bitmask,
487 .claim = NFS4_OPEN_CLAIM_NULL,
488 };
489 struct nfs_openres o_res = {
490 .f_attr = &f_attr,
491 .server = server,
492 };
493 int status = 0;
494
495 if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
496 status = _nfs4_do_access(inode, sp->so_cred, state->state);
497 if (status < 0)
498 goto out;
499 memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid));
500 set_bit(NFS_DELEGATED_STATE, &state->flags);
501 goto out;
502 }
cee54fc9
TM
503 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
504 status = -ENOMEM;
505 if (o_arg.seqid == NULL)
506 goto out;
1da177e4
LT
507 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
508 if (status != 0)
509 goto out_nodeleg;
510 /* Check if files differ */
511 if ((f_attr.mode & S_IFMT) != (inode->i_mode & S_IFMT))
512 goto out_stale;
513 /* Has the file handle changed? */
514 if (nfs_compare_fh(&o_res.fh, NFS_FH(inode)) != 0) {
515 /* Verify if the change attributes are the same */
516 if (f_attr.change_attr != NFS_I(inode)->change_attr)
517 goto out_stale;
518 if (nfs_size_to_loff_t(f_attr.size) != inode->i_size)
519 goto out_stale;
520 /* Lets just pretend that this is the same file */
521 nfs_copy_fh(NFS_FH(inode), &o_res.fh);
522 NFS_I(inode)->fileid = f_attr.fileid;
523 }
524 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
525 if (o_res.delegation_type != 0) {
526 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM))
527 nfs_inode_set_delegation(inode, sp->so_cred, &o_res);
528 else
529 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
530 }
531out_nodeleg:
cee54fc9 532 nfs_free_seqid(o_arg.seqid);
1da177e4
LT
533 clear_bit(NFS_DELEGATED_STATE, &state->flags);
534out:
535 dput(parent);
536 return status;
537out_stale:
538 status = -ESTALE;
539 /* Invalidate the state owner so we don't ever use it again */
540 nfs4_drop_state_owner(sp);
541 d_drop(dentry);
542 /* Should we be trying to close that stateid? */
543 goto out_nodeleg;
544}
545
202b50dc
TM
546static inline int nfs4_do_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
547{
548 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
549 struct nfs4_exception exception = { };
550 int err;
551
552 do {
553 err = _nfs4_open_expired(sp, state, dentry);
554 if (err == -NFS4ERR_DELAY)
555 nfs4_handle_exception(server, err, &exception);
556 } while (exception.retry);
557 return err;
558}
559
1da177e4
LT
560static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
561{
562 struct nfs_inode *nfsi = NFS_I(state->inode);
563 struct nfs_open_context *ctx;
564 int status;
565
566 spin_lock(&state->inode->i_lock);
567 list_for_each_entry(ctx, &nfsi->open_files, list) {
568 if (ctx->state != state)
569 continue;
570 get_nfs_open_context(ctx);
571 spin_unlock(&state->inode->i_lock);
202b50dc 572 status = nfs4_do_open_expired(sp, state, ctx->dentry);
1da177e4
LT
573 put_nfs_open_context(ctx);
574 return status;
575 }
576 spin_unlock(&state->inode->i_lock);
577 return -ENOENT;
578}
579
580/*
581 * Returns an nfs4_state + an extra reference to the inode
582 */
583static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res)
584{
585 struct nfs_delegation *delegation;
586 struct nfs_server *server = NFS_SERVER(inode);
587 struct nfs4_client *clp = server->nfs4_state;
588 struct nfs_inode *nfsi = NFS_I(inode);
589 struct nfs4_state_owner *sp = NULL;
590 struct nfs4_state *state = NULL;
591 int open_flags = flags & (FMODE_READ|FMODE_WRITE);
592 int err;
593
594 /* Protect against reboot recovery - NOTE ORDER! */
595 down_read(&clp->cl_sem);
596 /* Protect against delegation recall */
597 down_read(&nfsi->rwsem);
598 delegation = NFS_I(inode)->delegation;
599 err = -ENOENT;
600 if (delegation == NULL || (delegation->type & open_flags) != open_flags)
601 goto out_err;
602 err = -ENOMEM;
603 if (!(sp = nfs4_get_state_owner(server, cred))) {
604 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
605 goto out_err;
606 }
1da177e4
LT
607 state = nfs4_get_open_state(inode, sp);
608 if (state == NULL)
609 goto out_err;
610
611 err = -ENOENT;
612 if ((state->state & open_flags) == open_flags) {
613 spin_lock(&inode->i_lock);
614 if (open_flags & FMODE_READ)
615 state->nreaders++;
616 if (open_flags & FMODE_WRITE)
617 state->nwriters++;
618 spin_unlock(&inode->i_lock);
619 goto out_ok;
620 } else if (state->state != 0)
621 goto out_err;
622
623 lock_kernel();
624 err = _nfs4_do_access(inode, cred, open_flags);
625 unlock_kernel();
626 if (err != 0)
627 goto out_err;
628 set_bit(NFS_DELEGATED_STATE, &state->flags);
629 update_open_stateid(state, &delegation->stateid, open_flags);
630out_ok:
1da177e4
LT
631 nfs4_put_state_owner(sp);
632 up_read(&nfsi->rwsem);
633 up_read(&clp->cl_sem);
634 igrab(inode);
635 *res = state;
636 return 0;
637out_err:
638 if (sp != NULL) {
639 if (state != NULL)
640 nfs4_put_open_state(state);
1da177e4
LT
641 nfs4_put_state_owner(sp);
642 }
643 up_read(&nfsi->rwsem);
644 up_read(&clp->cl_sem);
645 return err;
646}
647
648static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred)
649{
650 struct nfs4_exception exception = { };
651 struct nfs4_state *res;
652 int err;
653
654 do {
655 err = _nfs4_open_delegated(inode, flags, cred, &res);
656 if (err == 0)
657 break;
658 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode),
659 err, &exception));
660 } while (exception.retry);
661 return res;
662}
663
664/*
665 * Returns an nfs4_state + an referenced inode
666 */
667static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
668{
669 struct nfs4_state_owner *sp;
670 struct nfs4_state *state = NULL;
671 struct nfs_server *server = NFS_SERVER(dir);
672 struct nfs4_client *clp = server->nfs4_state;
673 struct inode *inode = NULL;
674 int status;
675 struct nfs_fattr f_attr = {
676 .valid = 0,
677 };
678 struct nfs_openargs o_arg = {
679 .fh = NFS_FH(dir),
680 .open_flags = flags,
681 .name = &dentry->d_name,
682 .server = server,
683 .bitmask = server->attr_bitmask,
684 .claim = NFS4_OPEN_CLAIM_NULL,
685 };
686 struct nfs_openres o_res = {
687 .f_attr = &f_attr,
688 .server = server,
689 };
690
691 /* Protect against reboot recovery conflicts */
692 down_read(&clp->cl_sem);
693 status = -ENOMEM;
694 if (!(sp = nfs4_get_state_owner(server, cred))) {
695 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
696 goto out_err;
697 }
698 if (flags & O_EXCL) {
699 u32 *p = (u32 *) o_arg.u.verifier.data;
700 p[0] = jiffies;
701 p[1] = current->pid;
702 } else
703 o_arg.u.attrs = sattr;
704 /* Serialization for the sequence id */
1da177e4 705
cee54fc9
TM
706 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
707 if (o_arg.seqid == NULL)
708 return -ENOMEM;
1da177e4
LT
709 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
710 if (status != 0)
711 goto out_err;
712
713 status = -ENOMEM;
714 inode = nfs_fhget(dir->i_sb, &o_res.fh, &f_attr);
715 if (!inode)
716 goto out_err;
717 state = nfs4_get_open_state(inode, sp);
718 if (!state)
719 goto out_err;
720 update_open_stateid(state, &o_res.stateid, flags);
721 if (o_res.delegation_type != 0)
722 nfs_inode_set_delegation(inode, cred, &o_res);
cee54fc9 723 nfs_free_seqid(o_arg.seqid);
1da177e4
LT
724 nfs4_put_state_owner(sp);
725 up_read(&clp->cl_sem);
726 *res = state;
727 return 0;
728out_err:
729 if (sp != NULL) {
730 if (state != NULL)
731 nfs4_put_open_state(state);
cee54fc9 732 nfs_free_seqid(o_arg.seqid);
1da177e4
LT
733 nfs4_put_state_owner(sp);
734 }
735 /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
736 up_read(&clp->cl_sem);
737 if (inode != NULL)
738 iput(inode);
739 *res = NULL;
740 return status;
741}
742
743
744static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred)
745{
746 struct nfs4_exception exception = { };
747 struct nfs4_state *res;
748 int status;
749
750 do {
751 status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res);
752 if (status == 0)
753 break;
754 /* NOTE: BAD_SEQID means the server and client disagree about the
755 * book-keeping w.r.t. state-changing operations
756 * (OPEN/CLOSE/LOCK/LOCKU...)
757 * It is actually a sign of a bug on the client or on the server.
758 *
759 * If we receive a BAD_SEQID error in the particular case of
cee54fc9 760 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1da177e4
LT
761 * have unhashed the old state_owner for us, and that we can
762 * therefore safely retry using a new one. We should still warn
763 * the user though...
764 */
765 if (status == -NFS4ERR_BAD_SEQID) {
766 printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n");
767 exception.retry = 1;
768 continue;
769 }
770 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
771 status, &exception));
772 } while (exception.retry);
773 return res;
774}
775
776static int _nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
777 struct nfs_fh *fhandle, struct iattr *sattr,
778 struct nfs4_state *state)
779{
780 struct nfs_setattrargs arg = {
781 .fh = fhandle,
782 .iap = sattr,
783 .server = server,
784 .bitmask = server->attr_bitmask,
785 };
786 struct nfs_setattrres res = {
787 .fattr = fattr,
788 .server = server,
789 };
790 struct rpc_message msg = {
791 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
792 .rpc_argp = &arg,
793 .rpc_resp = &res,
794 };
65e4308d 795 int status;
1da177e4
LT
796
797 fattr->valid = 0;
798
08e9eac4 799 if (state != NULL) {
1da177e4 800 msg.rpc_cred = state->owner->so_cred;
08e9eac4
TM
801 nfs4_copy_stateid(&arg.stateid, state, current->files);
802 } else
1da177e4
LT
803 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
804
65e4308d
TM
805 status = rpc_call_sync(server->client, &msg, 0);
806 return status;
1da177e4
LT
807}
808
809static int nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
810 struct nfs_fh *fhandle, struct iattr *sattr,
811 struct nfs4_state *state)
812{
813 struct nfs4_exception exception = { };
814 int err;
815 do {
816 err = nfs4_handle_exception(server,
817 _nfs4_do_setattr(server, fattr, fhandle, sattr,
818 state),
819 &exception);
820 } while (exception.retry);
821 return err;
822}
823
824struct nfs4_closedata {
825 struct inode *inode;
826 struct nfs4_state *state;
827 struct nfs_closeargs arg;
828 struct nfs_closeres res;
829};
830
9512135d
TM
831static void nfs4_free_closedata(struct nfs4_closedata *calldata)
832{
833 struct nfs4_state *state = calldata->state;
834 struct nfs4_state_owner *sp = state->owner;
9512135d
TM
835
836 nfs4_put_open_state(calldata->state);
837 nfs_free_seqid(calldata->arg.seqid);
9512135d 838 nfs4_put_state_owner(sp);
9512135d
TM
839 kfree(calldata);
840}
841
1da177e4
LT
842static void nfs4_close_done(struct rpc_task *task)
843{
844 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
845 struct nfs4_state *state = calldata->state;
1da177e4
LT
846 struct nfs_server *server = NFS_SERVER(calldata->inode);
847
848 /* hmm. we are done with the inode, and in the process of freeing
849 * the state_owner. we keep this around to process errors
850 */
cee54fc9 851 nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid);
1da177e4
LT
852 switch (task->tk_status) {
853 case 0:
854 memcpy(&state->stateid, &calldata->res.stateid,
855 sizeof(state->stateid));
856 break;
857 case -NFS4ERR_STALE_STATEID:
858 case -NFS4ERR_EXPIRED:
859 state->state = calldata->arg.open_flags;
860 nfs4_schedule_state_recovery(server->nfs4_state);
861 break;
862 default:
863 if (nfs4_async_handle_error(task, server) == -EAGAIN) {
864 rpc_restart_call(task);
865 return;
866 }
867 }
868 state->state = calldata->arg.open_flags;
9512135d 869 nfs4_free_closedata(calldata);
1da177e4
LT
870}
871
9512135d 872static void nfs4_close_begin(struct rpc_task *task)
1da177e4 873{
9512135d
TM
874 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
875 struct nfs4_state *state = calldata->state;
1da177e4
LT
876 struct rpc_message msg = {
877 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
878 .rpc_argp = &calldata->arg,
879 .rpc_resp = &calldata->res,
9512135d 880 .rpc_cred = state->owner->so_cred,
1da177e4 881 };
9512135d
TM
882 int mode = 0;
883 int status;
884
885 status = nfs_wait_on_sequence(calldata->arg.seqid, task);
886 if (status != 0)
887 return;
888 /* Don't reorder reads */
889 smp_rmb();
890 /* Recalculate the new open mode in case someone reopened the file
891 * while we were waiting in line to be scheduled.
892 */
893 if (state->nreaders != 0)
894 mode |= FMODE_READ;
895 if (state->nwriters != 0)
896 mode |= FMODE_WRITE;
897 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
898 state->state = mode;
899 if (mode == state->state) {
900 nfs4_free_closedata(calldata);
901 task->tk_exit = NULL;
902 rpc_exit(task, 0);
903 return;
904 }
905 if (mode != 0)
1da177e4 906 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
9512135d
TM
907 calldata->arg.open_flags = mode;
908 rpc_call_setup(task, &msg, 0);
1da177e4
LT
909}
910
911/*
912 * It is possible for data to be read/written from a mem-mapped file
913 * after the sys_close call (which hits the vfs layer as a flush).
914 * This means that we can't safely call nfsv4 close on a file until
915 * the inode is cleared. This in turn means that we are not good
916 * NFSv4 citizens - we do not indicate to the server to update the file's
917 * share state even when we are done with one of the three share
918 * stateid's in the inode.
919 *
920 * NOTE: Caller must be holding the sp->so_owner semaphore!
921 */
922int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode)
923{
924 struct nfs4_closedata *calldata;
9512135d 925 int status = -ENOMEM;
1da177e4 926
9512135d 927 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
1da177e4 928 if (calldata == NULL)
9512135d 929 goto out;
1da177e4
LT
930 calldata->inode = inode;
931 calldata->state = state;
932 calldata->arg.fh = NFS_FH(inode);
9512135d 933 calldata->arg.stateid = &state->stateid;
1da177e4 934 /* Serialization for the sequence id */
cee54fc9 935 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
9512135d
TM
936 if (calldata->arg.seqid == NULL)
937 goto out_free_calldata;
938
939 status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_close_begin,
940 nfs4_close_done, calldata);
941 if (status == 0)
942 goto out;
943
944 nfs_free_seqid(calldata->arg.seqid);
945out_free_calldata:
946 kfree(calldata);
947out:
948 return status;
1da177e4
LT
949}
950
02a913a7
TM
951static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state)
952{
953 struct file *filp;
954
955 filp = lookup_instantiate_filp(nd, dentry, NULL);
956 if (!IS_ERR(filp)) {
957 struct nfs_open_context *ctx;
958 ctx = (struct nfs_open_context *)filp->private_data;
959 ctx->state = state;
960 } else
961 nfs4_close_state(state, nd->intent.open.flags);
962}
963
964struct dentry *
1da177e4
LT
965nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
966{
967 struct iattr attr;
968 struct rpc_cred *cred;
969 struct nfs4_state *state;
02a913a7 970 struct dentry *res;
1da177e4
LT
971
972 if (nd->flags & LOOKUP_CREATE) {
973 attr.ia_mode = nd->intent.open.create_mode;
974 attr.ia_valid = ATTR_MODE;
975 if (!IS_POSIXACL(dir))
976 attr.ia_mode &= ~current->fs->umask;
977 } else {
978 attr.ia_valid = 0;
979 BUG_ON(nd->intent.open.flags & O_CREAT);
980 }
981
982 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
983 if (IS_ERR(cred))
02a913a7 984 return (struct dentry *)cred;
1da177e4
LT
985 state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
986 put_rpccred(cred);
02a913a7
TM
987 if (IS_ERR(state)) {
988 if (PTR_ERR(state) == -ENOENT)
989 d_add(dentry, NULL);
990 return (struct dentry *)state;
991 }
992 res = d_add_unique(dentry, state->inode);
993 if (res != NULL)
994 dentry = res;
995 nfs4_intent_set_file(nd, dentry, state);
996 return res;
1da177e4
LT
997}
998
999int
02a913a7 1000nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
1da177e4
LT
1001{
1002 struct rpc_cred *cred;
1003 struct nfs4_state *state;
1004 struct inode *inode;
1005
1006 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1007 if (IS_ERR(cred))
1008 return PTR_ERR(cred);
1009 state = nfs4_open_delegated(dentry->d_inode, openflags, cred);
1010 if (IS_ERR(state))
1011 state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
1012 put_rpccred(cred);
02a913a7
TM
1013 if (IS_ERR(state)) {
1014 switch (PTR_ERR(state)) {
1015 case -EPERM:
1016 case -EACCES:
1017 case -EDQUOT:
1018 case -ENOSPC:
1019 case -EROFS:
1020 lookup_instantiate_filp(nd, (struct dentry *)state, NULL);
1021 return 1;
1022 case -ENOENT:
1023 if (dentry->d_inode == NULL)
1024 return 1;
1025 }
1026 goto out_drop;
1027 }
1da177e4 1028 inode = state->inode;
02a913a7 1029 iput(inode);
1da177e4 1030 if (inode == dentry->d_inode) {
02a913a7 1031 nfs4_intent_set_file(nd, dentry, state);
1da177e4
LT
1032 return 1;
1033 }
1da177e4 1034 nfs4_close_state(state, openflags);
02a913a7
TM
1035out_drop:
1036 d_drop(dentry);
1da177e4
LT
1037 return 0;
1038}
1039
1040
1041static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1042{
1043 struct nfs4_server_caps_res res = {};
1044 struct rpc_message msg = {
1045 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
1046 .rpc_argp = fhandle,
1047 .rpc_resp = &res,
1048 };
1049 int status;
1050
1051 status = rpc_call_sync(server->client, &msg, 0);
1052 if (status == 0) {
1053 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
1054 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
1055 server->caps |= NFS_CAP_ACLS;
1056 if (res.has_links != 0)
1057 server->caps |= NFS_CAP_HARDLINKS;
1058 if (res.has_symlinks != 0)
1059 server->caps |= NFS_CAP_SYMLINKS;
1060 server->acl_bitmask = res.acl_bitmask;
1061 }
1062 return status;
1063}
1064
1065static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1066{
1067 struct nfs4_exception exception = { };
1068 int err;
1069 do {
1070 err = nfs4_handle_exception(server,
1071 _nfs4_server_capabilities(server, fhandle),
1072 &exception);
1073 } while (exception.retry);
1074 return err;
1075}
1076
1077static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1078 struct nfs_fsinfo *info)
1079{
1080 struct nfs_fattr * fattr = info->fattr;
1081 struct nfs4_lookup_root_arg args = {
1082 .bitmask = nfs4_fattr_bitmap,
1083 };
1084 struct nfs4_lookup_res res = {
1085 .server = server,
1086 .fattr = fattr,
1087 .fh = fhandle,
1088 };
1089 struct rpc_message msg = {
1090 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
1091 .rpc_argp = &args,
1092 .rpc_resp = &res,
1093 };
1094 fattr->valid = 0;
1095 return rpc_call_sync(server->client, &msg, 0);
1096}
1097
1098static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1099 struct nfs_fsinfo *info)
1100{
1101 struct nfs4_exception exception = { };
1102 int err;
1103 do {
1104 err = nfs4_handle_exception(server,
1105 _nfs4_lookup_root(server, fhandle, info),
1106 &exception);
1107 } while (exception.retry);
1108 return err;
1109}
1110
1111static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
1112 struct nfs_fsinfo *info)
1113{
1114 struct nfs_fattr * fattr = info->fattr;
1115 unsigned char * p;
1116 struct qstr q;
1117 struct nfs4_lookup_arg args = {
1118 .dir_fh = fhandle,
1119 .name = &q,
1120 .bitmask = nfs4_fattr_bitmap,
1121 };
1122 struct nfs4_lookup_res res = {
1123 .server = server,
1124 .fattr = fattr,
1125 .fh = fhandle,
1126 };
1127 struct rpc_message msg = {
1128 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1129 .rpc_argp = &args,
1130 .rpc_resp = &res,
1131 };
1132 int status;
1133
1134 /*
1135 * Now we do a separate LOOKUP for each component of the mount path.
1136 * The LOOKUPs are done separately so that we can conveniently
1137 * catch an ERR_WRONGSEC if it occurs along the way...
1138 */
1139 status = nfs4_lookup_root(server, fhandle, info);
1140 if (status)
1141 goto out;
1142
1143 p = server->mnt_path;
1144 for (;;) {
1145 struct nfs4_exception exception = { };
1146
1147 while (*p == '/')
1148 p++;
1149 if (!*p)
1150 break;
1151 q.name = p;
1152 while (*p && (*p != '/'))
1153 p++;
1154 q.len = p - q.name;
1155
1156 do {
1157 fattr->valid = 0;
1158 status = nfs4_handle_exception(server,
1159 rpc_call_sync(server->client, &msg, 0),
1160 &exception);
1161 } while (exception.retry);
1162 if (status == 0)
1163 continue;
1164 if (status == -ENOENT) {
1165 printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path);
1166 printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n");
1167 }
1168 break;
1169 }
1170 if (status == 0)
1171 status = nfs4_server_capabilities(server, fhandle);
1172 if (status == 0)
1173 status = nfs4_do_fsinfo(server, fhandle, info);
1174out:
1175 return status;
1176}
1177
1178static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1179{
1180 struct nfs4_getattr_arg args = {
1181 .fh = fhandle,
1182 .bitmask = server->attr_bitmask,
1183 };
1184 struct nfs4_getattr_res res = {
1185 .fattr = fattr,
1186 .server = server,
1187 };
1188 struct rpc_message msg = {
1189 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
1190 .rpc_argp = &args,
1191 .rpc_resp = &res,
1192 };
1193
1194 fattr->valid = 0;
1195 return rpc_call_sync(server->client, &msg, 0);
1196}
1197
1198static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1199{
1200 struct nfs4_exception exception = { };
1201 int err;
1202 do {
1203 err = nfs4_handle_exception(server,
1204 _nfs4_proc_getattr(server, fhandle, fattr),
1205 &exception);
1206 } while (exception.retry);
1207 return err;
1208}
1209
1210/*
1211 * The file is not closed if it is opened due to the a request to change
1212 * the size of the file. The open call will not be needed once the
1213 * VFS layer lookup-intents are implemented.
1214 *
1215 * Close is called when the inode is destroyed.
1216 * If we haven't opened the file for O_WRONLY, we
1217 * need to in the size_change case to obtain a stateid.
1218 *
1219 * Got race?
1220 * Because OPEN is always done by name in nfsv4, it is
1221 * possible that we opened a different file by the same
1222 * name. We can recognize this race condition, but we
1223 * can't do anything about it besides returning an error.
1224 *
1225 * This will be fixed with VFS changes (lookup-intent).
1226 */
1227static int
1228nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1229 struct iattr *sattr)
1230{
08e9eac4
TM
1231 struct rpc_cred *cred;
1232 struct inode *inode = dentry->d_inode;
1233 struct nfs4_state *state;
1da177e4
LT
1234 int status;
1235
1236 fattr->valid = 0;
1237
08e9eac4
TM
1238 cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
1239 if (IS_ERR(cred))
1240 return PTR_ERR(cred);
1241 /* Search for an existing WRITE delegation first */
1242 state = nfs4_open_delegated(inode, FMODE_WRITE, cred);
1243 if (!IS_ERR(state)) {
1244 /* NB: nfs4_open_delegated() bumps the inode->i_count */
1245 iput(inode);
1246 } else {
1247 /* Search for an existing open(O_WRITE) stateid */
1da177e4 1248 state = nfs4_find_state(inode, cred, FMODE_WRITE);
1da177e4 1249 }
08e9eac4 1250
1da177e4
LT
1251 status = nfs4_do_setattr(NFS_SERVER(inode), fattr,
1252 NFS_FH(inode), sattr, state);
65e4308d
TM
1253 if (status == 0)
1254 nfs_setattr_update_inode(inode, sattr);
08e9eac4 1255 if (state != NULL)
1da177e4 1256 nfs4_close_state(state, FMODE_WRITE);
08e9eac4 1257 put_rpccred(cred);
1da177e4
LT
1258 return status;
1259}
1260
1261static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,
1262 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1263{
1264 int status;
1265 struct nfs_server *server = NFS_SERVER(dir);
1266 struct nfs4_lookup_arg args = {
1267 .bitmask = server->attr_bitmask,
1268 .dir_fh = NFS_FH(dir),
1269 .name = name,
1270 };
1271 struct nfs4_lookup_res res = {
1272 .server = server,
1273 .fattr = fattr,
1274 .fh = fhandle,
1275 };
1276 struct rpc_message msg = {
1277 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1278 .rpc_argp = &args,
1279 .rpc_resp = &res,
1280 };
1281
1282 fattr->valid = 0;
1283
1284 dprintk("NFS call lookup %s\n", name->name);
1285 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1286 dprintk("NFS reply lookup: %d\n", status);
1287 return status;
1288}
1289
1290static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1291{
1292 struct nfs4_exception exception = { };
1293 int err;
1294 do {
1295 err = nfs4_handle_exception(NFS_SERVER(dir),
1296 _nfs4_proc_lookup(dir, name, fhandle, fattr),
1297 &exception);
1298 } while (exception.retry);
1299 return err;
1300}
1301
1302static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1303{
1304 struct nfs4_accessargs args = {
1305 .fh = NFS_FH(inode),
1306 };
1307 struct nfs4_accessres res = { 0 };
1308 struct rpc_message msg = {
1309 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
1310 .rpc_argp = &args,
1311 .rpc_resp = &res,
1312 .rpc_cred = entry->cred,
1313 };
1314 int mode = entry->mask;
1315 int status;
1316
1317 /*
1318 * Determine which access bits we want to ask for...
1319 */
1320 if (mode & MAY_READ)
1321 args.access |= NFS4_ACCESS_READ;
1322 if (S_ISDIR(inode->i_mode)) {
1323 if (mode & MAY_WRITE)
1324 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
1325 if (mode & MAY_EXEC)
1326 args.access |= NFS4_ACCESS_LOOKUP;
1327 } else {
1328 if (mode & MAY_WRITE)
1329 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
1330 if (mode & MAY_EXEC)
1331 args.access |= NFS4_ACCESS_EXECUTE;
1332 }
1333 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1334 if (!status) {
1335 entry->mask = 0;
1336 if (res.access & NFS4_ACCESS_READ)
1337 entry->mask |= MAY_READ;
1338 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
1339 entry->mask |= MAY_WRITE;
1340 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
1341 entry->mask |= MAY_EXEC;
1342 }
1343 return status;
1344}
1345
1346static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1347{
1348 struct nfs4_exception exception = { };
1349 int err;
1350 do {
1351 err = nfs4_handle_exception(NFS_SERVER(inode),
1352 _nfs4_proc_access(inode, entry),
1353 &exception);
1354 } while (exception.retry);
1355 return err;
1356}
1357
1358/*
1359 * TODO: For the time being, we don't try to get any attributes
1360 * along with any of the zero-copy operations READ, READDIR,
1361 * READLINK, WRITE.
1362 *
1363 * In the case of the first three, we want to put the GETATTR
1364 * after the read-type operation -- this is because it is hard
1365 * to predict the length of a GETATTR response in v4, and thus
1366 * align the READ data correctly. This means that the GETATTR
1367 * may end up partially falling into the page cache, and we should
1368 * shift it into the 'tail' of the xdr_buf before processing.
1369 * To do this efficiently, we need to know the total length
1370 * of data received, which doesn't seem to be available outside
1371 * of the RPC layer.
1372 *
1373 * In the case of WRITE, we also want to put the GETATTR after
1374 * the operation -- in this case because we want to make sure
1375 * we get the post-operation mtime and size. This means that
1376 * we can't use xdr_encode_pages() as written: we need a variant
1377 * of it which would leave room in the 'tail' iovec.
1378 *
1379 * Both of these changes to the XDR layer would in fact be quite
1380 * minor, but I decided to leave them for a subsequent patch.
1381 */
1382static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
1383 unsigned int pgbase, unsigned int pglen)
1384{
1385 struct nfs4_readlink args = {
1386 .fh = NFS_FH(inode),
1387 .pgbase = pgbase,
1388 .pglen = pglen,
1389 .pages = &page,
1390 };
1391 struct rpc_message msg = {
1392 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
1393 .rpc_argp = &args,
1394 .rpc_resp = NULL,
1395 };
1396
1397 return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1398}
1399
1400static int nfs4_proc_readlink(struct inode *inode, struct page *page,
1401 unsigned int pgbase, unsigned int pglen)
1402{
1403 struct nfs4_exception exception = { };
1404 int err;
1405 do {
1406 err = nfs4_handle_exception(NFS_SERVER(inode),
1407 _nfs4_proc_readlink(inode, page, pgbase, pglen),
1408 &exception);
1409 } while (exception.retry);
1410 return err;
1411}
1412
1413static int _nfs4_proc_read(struct nfs_read_data *rdata)
1414{
1415 int flags = rdata->flags;
1416 struct inode *inode = rdata->inode;
1417 struct nfs_fattr *fattr = rdata->res.fattr;
1418 struct nfs_server *server = NFS_SERVER(inode);
1419 struct rpc_message msg = {
1420 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
1421 .rpc_argp = &rdata->args,
1422 .rpc_resp = &rdata->res,
1423 .rpc_cred = rdata->cred,
1424 };
1425 unsigned long timestamp = jiffies;
1426 int status;
1427
1428 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
1429 (long long) rdata->args.offset);
1430
1431 fattr->valid = 0;
1432 status = rpc_call_sync(server->client, &msg, flags);
1433 if (!status)
1434 renew_lease(server, timestamp);
1435 dprintk("NFS reply read: %d\n", status);
1436 return status;
1437}
1438
1439static int nfs4_proc_read(struct nfs_read_data *rdata)
1440{
1441 struct nfs4_exception exception = { };
1442 int err;
1443 do {
1444 err = nfs4_handle_exception(NFS_SERVER(rdata->inode),
1445 _nfs4_proc_read(rdata),
1446 &exception);
1447 } while (exception.retry);
1448 return err;
1449}
1450
1451static int _nfs4_proc_write(struct nfs_write_data *wdata)
1452{
1453 int rpcflags = wdata->flags;
1454 struct inode *inode = wdata->inode;
1455 struct nfs_fattr *fattr = wdata->res.fattr;
1456 struct nfs_server *server = NFS_SERVER(inode);
1457 struct rpc_message msg = {
1458 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
1459 .rpc_argp = &wdata->args,
1460 .rpc_resp = &wdata->res,
1461 .rpc_cred = wdata->cred,
1462 };
1463 int status;
1464
1465 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
1466 (long long) wdata->args.offset);
1467
1468 fattr->valid = 0;
1469 status = rpc_call_sync(server->client, &msg, rpcflags);
1470 dprintk("NFS reply write: %d\n", status);
1471 return status;
1472}
1473
1474static int nfs4_proc_write(struct nfs_write_data *wdata)
1475{
1476 struct nfs4_exception exception = { };
1477 int err;
1478 do {
1479 err = nfs4_handle_exception(NFS_SERVER(wdata->inode),
1480 _nfs4_proc_write(wdata),
1481 &exception);
1482 } while (exception.retry);
1483 return err;
1484}
1485
1486static int _nfs4_proc_commit(struct nfs_write_data *cdata)
1487{
1488 struct inode *inode = cdata->inode;
1489 struct nfs_fattr *fattr = cdata->res.fattr;
1490 struct nfs_server *server = NFS_SERVER(inode);
1491 struct rpc_message msg = {
1492 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
1493 .rpc_argp = &cdata->args,
1494 .rpc_resp = &cdata->res,
1495 .rpc_cred = cdata->cred,
1496 };
1497 int status;
1498
1499 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
1500 (long long) cdata->args.offset);
1501
1502 fattr->valid = 0;
1503 status = rpc_call_sync(server->client, &msg, 0);
1504 dprintk("NFS reply commit: %d\n", status);
1505 return status;
1506}
1507
1508static int nfs4_proc_commit(struct nfs_write_data *cdata)
1509{
1510 struct nfs4_exception exception = { };
1511 int err;
1512 do {
1513 err = nfs4_handle_exception(NFS_SERVER(cdata->inode),
1514 _nfs4_proc_commit(cdata),
1515 &exception);
1516 } while (exception.retry);
1517 return err;
1518}
1519
1520/*
1521 * Got race?
1522 * We will need to arrange for the VFS layer to provide an atomic open.
1523 * Until then, this create/open method is prone to inefficiency and race
1524 * conditions due to the lookup, create, and open VFS calls from sys_open()
1525 * placed on the wire.
1526 *
1527 * Given the above sorry state of affairs, I'm simply sending an OPEN.
1528 * The file will be opened again in the subsequent VFS open call
1529 * (nfs4_proc_file_open).
1530 *
1531 * The open for read will just hang around to be used by any process that
1532 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1533 */
1534
1535static int
1536nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
02a913a7 1537 int flags, struct nameidata *nd)
1da177e4
LT
1538{
1539 struct nfs4_state *state;
1540 struct rpc_cred *cred;
1541 int status = 0;
1542
1543 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1544 if (IS_ERR(cred)) {
1545 status = PTR_ERR(cred);
1546 goto out;
1547 }
1548 state = nfs4_do_open(dir, dentry, flags, sattr, cred);
1549 put_rpccred(cred);
1550 if (IS_ERR(state)) {
1551 status = PTR_ERR(state);
1552 goto out;
1553 }
1554 d_instantiate(dentry, state->inode);
1555 if (flags & O_EXCL) {
1556 struct nfs_fattr fattr;
1557 status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,
1558 NFS_FH(state->inode), sattr, state);
02a913a7 1559 if (status == 0)
65e4308d 1560 nfs_setattr_update_inode(state->inode, sattr);
02a913a7
TM
1561 }
1562 if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN))
1563 nfs4_intent_set_file(nd, dentry, state);
1564 else
1565 nfs4_close_state(state, flags);
1da177e4
LT
1566out:
1567 return status;
1568}
1569
1570static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
1571{
1572 struct nfs4_remove_arg args = {
1573 .fh = NFS_FH(dir),
1574 .name = name,
1575 };
1576 struct nfs4_change_info res;
1577 struct rpc_message msg = {
1578 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
1579 .rpc_argp = &args,
1580 .rpc_resp = &res,
1581 };
1582 int status;
1583
1584 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1585 if (status == 0)
1586 update_changeattr(dir, &res);
1587 return status;
1588}
1589
1590static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
1591{
1592 struct nfs4_exception exception = { };
1593 int err;
1594 do {
1595 err = nfs4_handle_exception(NFS_SERVER(dir),
1596 _nfs4_proc_remove(dir, name),
1597 &exception);
1598 } while (exception.retry);
1599 return err;
1600}
1601
1602struct unlink_desc {
1603 struct nfs4_remove_arg args;
1604 struct nfs4_change_info res;
1605};
1606
1607static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir,
1608 struct qstr *name)
1609{
1610 struct unlink_desc *up;
1611
1612 up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL);
1613 if (!up)
1614 return -ENOMEM;
1615
1616 up->args.fh = NFS_FH(dir->d_inode);
1617 up->args.name = name;
1618
1619 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
1620 msg->rpc_argp = &up->args;
1621 msg->rpc_resp = &up->res;
1622 return 0;
1623}
1624
1625static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
1626{
1627 struct rpc_message *msg = &task->tk_msg;
1628 struct unlink_desc *up;
1629
1630 if (msg->rpc_resp != NULL) {
1631 up = container_of(msg->rpc_resp, struct unlink_desc, res);
1632 update_changeattr(dir->d_inode, &up->res);
1633 kfree(up);
1634 msg->rpc_resp = NULL;
1635 msg->rpc_argp = NULL;
1636 }
1637 return 0;
1638}
1639
1640static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1641 struct inode *new_dir, struct qstr *new_name)
1642{
1643 struct nfs4_rename_arg arg = {
1644 .old_dir = NFS_FH(old_dir),
1645 .new_dir = NFS_FH(new_dir),
1646 .old_name = old_name,
1647 .new_name = new_name,
1648 };
1649 struct nfs4_rename_res res = { };
1650 struct rpc_message msg = {
1651 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
1652 .rpc_argp = &arg,
1653 .rpc_resp = &res,
1654 };
1655 int status;
1656
1657 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
1658
1659 if (!status) {
1660 update_changeattr(old_dir, &res.old_cinfo);
1661 update_changeattr(new_dir, &res.new_cinfo);
1662 }
1663 return status;
1664}
1665
1666static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1667 struct inode *new_dir, struct qstr *new_name)
1668{
1669 struct nfs4_exception exception = { };
1670 int err;
1671 do {
1672 err = nfs4_handle_exception(NFS_SERVER(old_dir),
1673 _nfs4_proc_rename(old_dir, old_name,
1674 new_dir, new_name),
1675 &exception);
1676 } while (exception.retry);
1677 return err;
1678}
1679
1680static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1681{
1682 struct nfs4_link_arg arg = {
1683 .fh = NFS_FH(inode),
1684 .dir_fh = NFS_FH(dir),
1685 .name = name,
1686 };
1687 struct nfs4_change_info cinfo = { };
1688 struct rpc_message msg = {
1689 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
1690 .rpc_argp = &arg,
1691 .rpc_resp = &cinfo,
1692 };
1693 int status;
1694
1695 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1696 if (!status)
1697 update_changeattr(dir, &cinfo);
1698
1699 return status;
1700}
1701
1702static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1703{
1704 struct nfs4_exception exception = { };
1705 int err;
1706 do {
1707 err = nfs4_handle_exception(NFS_SERVER(inode),
1708 _nfs4_proc_link(inode, dir, name),
1709 &exception);
1710 } while (exception.retry);
1711 return err;
1712}
1713
1714static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1715 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1716 struct nfs_fattr *fattr)
1717{
1718 struct nfs_server *server = NFS_SERVER(dir);
1719 struct nfs4_create_arg arg = {
1720 .dir_fh = NFS_FH(dir),
1721 .server = server,
1722 .name = name,
1723 .attrs = sattr,
1724 .ftype = NF4LNK,
1725 .bitmask = server->attr_bitmask,
1726 };
1727 struct nfs4_create_res res = {
1728 .server = server,
1729 .fh = fhandle,
1730 .fattr = fattr,
1731 };
1732 struct rpc_message msg = {
1733 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK],
1734 .rpc_argp = &arg,
1735 .rpc_resp = &res,
1736 };
1737 int status;
1738
1739 if (path->len > NFS4_MAXPATHLEN)
1740 return -ENAMETOOLONG;
1741 arg.u.symlink = path;
1742 fattr->valid = 0;
1743
1744 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1745 if (!status)
1746 update_changeattr(dir, &res.dir_cinfo);
1747 return status;
1748}
1749
1750static int nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1751 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1752 struct nfs_fattr *fattr)
1753{
1754 struct nfs4_exception exception = { };
1755 int err;
1756 do {
1757 err = nfs4_handle_exception(NFS_SERVER(dir),
1758 _nfs4_proc_symlink(dir, name, path, sattr,
1759 fhandle, fattr),
1760 &exception);
1761 } while (exception.retry);
1762 return err;
1763}
1764
1765static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
1766 struct iattr *sattr)
1767{
1768 struct nfs_server *server = NFS_SERVER(dir);
1769 struct nfs_fh fhandle;
1770 struct nfs_fattr fattr;
1771 struct nfs4_create_arg arg = {
1772 .dir_fh = NFS_FH(dir),
1773 .server = server,
1774 .name = &dentry->d_name,
1775 .attrs = sattr,
1776 .ftype = NF4DIR,
1777 .bitmask = server->attr_bitmask,
1778 };
1779 struct nfs4_create_res res = {
1780 .server = server,
1781 .fh = &fhandle,
1782 .fattr = &fattr,
1783 };
1784 struct rpc_message msg = {
1785 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
1786 .rpc_argp = &arg,
1787 .rpc_resp = &res,
1788 };
1789 int status;
1790
1791 fattr.valid = 0;
1792
1793 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1794 if (!status) {
1795 update_changeattr(dir, &res.dir_cinfo);
1796 status = nfs_instantiate(dentry, &fhandle, &fattr);
1797 }
1798 return status;
1799}
1800
1801static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
1802 struct iattr *sattr)
1803{
1804 struct nfs4_exception exception = { };
1805 int err;
1806 do {
1807 err = nfs4_handle_exception(NFS_SERVER(dir),
1808 _nfs4_proc_mkdir(dir, dentry, sattr),
1809 &exception);
1810 } while (exception.retry);
1811 return err;
1812}
1813
1814static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
1815 u64 cookie, struct page *page, unsigned int count, int plus)
1816{
1817 struct inode *dir = dentry->d_inode;
1818 struct nfs4_readdir_arg args = {
1819 .fh = NFS_FH(dir),
1820 .pages = &page,
1821 .pgbase = 0,
1822 .count = count,
1823 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
1824 };
1825 struct nfs4_readdir_res res;
1826 struct rpc_message msg = {
1827 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
1828 .rpc_argp = &args,
1829 .rpc_resp = &res,
1830 .rpc_cred = cred,
1831 };
1832 int status;
1833
eadf4598
TM
1834 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__,
1835 dentry->d_parent->d_name.name,
1836 dentry->d_name.name,
1837 (unsigned long long)cookie);
1da177e4
LT
1838 lock_kernel();
1839 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
1840 res.pgbase = args.pgbase;
1841 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1842 if (status == 0)
1843 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
1844 unlock_kernel();
eadf4598 1845 dprintk("%s: returns %d\n", __FUNCTION__, status);
1da177e4
LT
1846 return status;
1847}
1848
1849static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
1850 u64 cookie, struct page *page, unsigned int count, int plus)
1851{
1852 struct nfs4_exception exception = { };
1853 int err;
1854 do {
1855 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
1856 _nfs4_proc_readdir(dentry, cred, cookie,
1857 page, count, plus),
1858 &exception);
1859 } while (exception.retry);
1860 return err;
1861}
1862
1863static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
1864 struct iattr *sattr, dev_t rdev)
1865{
1866 struct nfs_server *server = NFS_SERVER(dir);
1867 struct nfs_fh fh;
1868 struct nfs_fattr fattr;
1869 struct nfs4_create_arg arg = {
1870 .dir_fh = NFS_FH(dir),
1871 .server = server,
1872 .name = &dentry->d_name,
1873 .attrs = sattr,
1874 .bitmask = server->attr_bitmask,
1875 };
1876 struct nfs4_create_res res = {
1877 .server = server,
1878 .fh = &fh,
1879 .fattr = &fattr,
1880 };
1881 struct rpc_message msg = {
1882 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
1883 .rpc_argp = &arg,
1884 .rpc_resp = &res,
1885 };
1886 int status;
1887 int mode = sattr->ia_mode;
1888
1889 fattr.valid = 0;
1890
1891 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
1892 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
1893 if (S_ISFIFO(mode))
1894 arg.ftype = NF4FIFO;
1895 else if (S_ISBLK(mode)) {
1896 arg.ftype = NF4BLK;
1897 arg.u.device.specdata1 = MAJOR(rdev);
1898 arg.u.device.specdata2 = MINOR(rdev);
1899 }
1900 else if (S_ISCHR(mode)) {
1901 arg.ftype = NF4CHR;
1902 arg.u.device.specdata1 = MAJOR(rdev);
1903 arg.u.device.specdata2 = MINOR(rdev);
1904 }
1905 else
1906 arg.ftype = NF4SOCK;
1907
1908 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1909 if (status == 0) {
1910 update_changeattr(dir, &res.dir_cinfo);
1911 status = nfs_instantiate(dentry, &fh, &fattr);
1912 }
1913 return status;
1914}
1915
1916static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
1917 struct iattr *sattr, dev_t rdev)
1918{
1919 struct nfs4_exception exception = { };
1920 int err;
1921 do {
1922 err = nfs4_handle_exception(NFS_SERVER(dir),
1923 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
1924 &exception);
1925 } while (exception.retry);
1926 return err;
1927}
1928
1929static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
1930 struct nfs_fsstat *fsstat)
1931{
1932 struct nfs4_statfs_arg args = {
1933 .fh = fhandle,
1934 .bitmask = server->attr_bitmask,
1935 };
1936 struct rpc_message msg = {
1937 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
1938 .rpc_argp = &args,
1939 .rpc_resp = fsstat,
1940 };
1941
1942 fsstat->fattr->valid = 0;
1943 return rpc_call_sync(server->client, &msg, 0);
1944}
1945
1946static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
1947{
1948 struct nfs4_exception exception = { };
1949 int err;
1950 do {
1951 err = nfs4_handle_exception(server,
1952 _nfs4_proc_statfs(server, fhandle, fsstat),
1953 &exception);
1954 } while (exception.retry);
1955 return err;
1956}
1957
1958static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
1959 struct nfs_fsinfo *fsinfo)
1960{
1961 struct nfs4_fsinfo_arg args = {
1962 .fh = fhandle,
1963 .bitmask = server->attr_bitmask,
1964 };
1965 struct rpc_message msg = {
1966 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
1967 .rpc_argp = &args,
1968 .rpc_resp = fsinfo,
1969 };
1970
1971 return rpc_call_sync(server->client, &msg, 0);
1972}
1973
1974static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
1975{
1976 struct nfs4_exception exception = { };
1977 int err;
1978
1979 do {
1980 err = nfs4_handle_exception(server,
1981 _nfs4_do_fsinfo(server, fhandle, fsinfo),
1982 &exception);
1983 } while (exception.retry);
1984 return err;
1985}
1986
1987static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
1988{
1989 fsinfo->fattr->valid = 0;
1990 return nfs4_do_fsinfo(server, fhandle, fsinfo);
1991}
1992
1993static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
1994 struct nfs_pathconf *pathconf)
1995{
1996 struct nfs4_pathconf_arg args = {
1997 .fh = fhandle,
1998 .bitmask = server->attr_bitmask,
1999 };
2000 struct rpc_message msg = {
2001 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
2002 .rpc_argp = &args,
2003 .rpc_resp = pathconf,
2004 };
2005
2006 /* None of the pathconf attributes are mandatory to implement */
2007 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
2008 memset(pathconf, 0, sizeof(*pathconf));
2009 return 0;
2010 }
2011
2012 pathconf->fattr->valid = 0;
2013 return rpc_call_sync(server->client, &msg, 0);
2014}
2015
2016static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
2017 struct nfs_pathconf *pathconf)
2018{
2019 struct nfs4_exception exception = { };
2020 int err;
2021
2022 do {
2023 err = nfs4_handle_exception(server,
2024 _nfs4_proc_pathconf(server, fhandle, pathconf),
2025 &exception);
2026 } while (exception.retry);
2027 return err;
2028}
2029
2030static void
2031nfs4_read_done(struct rpc_task *task)
2032{
2033 struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
2034 struct inode *inode = data->inode;
2035
2036 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2037 rpc_restart_call(task);
2038 return;
2039 }
2040 if (task->tk_status > 0)
2041 renew_lease(NFS_SERVER(inode), data->timestamp);
2042 /* Call back common NFS readpage processing */
2043 nfs_readpage_result(task);
2044}
2045
2046static void
2047nfs4_proc_read_setup(struct nfs_read_data *data)
2048{
2049 struct rpc_task *task = &data->task;
2050 struct rpc_message msg = {
2051 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
2052 .rpc_argp = &data->args,
2053 .rpc_resp = &data->res,
2054 .rpc_cred = data->cred,
2055 };
2056 struct inode *inode = data->inode;
2057 int flags;
2058
2059 data->timestamp = jiffies;
2060
2061 /* N.B. Do we need to test? Never called for swapfile inode */
2062 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
2063
2064 /* Finalize the task. */
2065 rpc_init_task(task, NFS_CLIENT(inode), nfs4_read_done, flags);
2066 rpc_call_setup(task, &msg, 0);
2067}
2068
2069static void
2070nfs4_write_done(struct rpc_task *task)
2071{
2072 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
2073 struct inode *inode = data->inode;
2074
2075 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2076 rpc_restart_call(task);
2077 return;
2078 }
2079 if (task->tk_status >= 0)
2080 renew_lease(NFS_SERVER(inode), data->timestamp);
2081 /* Call back common NFS writeback processing */
2082 nfs_writeback_done(task);
2083}
2084
2085static void
2086nfs4_proc_write_setup(struct nfs_write_data *data, int how)
2087{
2088 struct rpc_task *task = &data->task;
2089 struct rpc_message msg = {
2090 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
2091 .rpc_argp = &data->args,
2092 .rpc_resp = &data->res,
2093 .rpc_cred = data->cred,
2094 };
2095 struct inode *inode = data->inode;
2096 int stable;
2097 int flags;
2098
2099 if (how & FLUSH_STABLE) {
2100 if (!NFS_I(inode)->ncommit)
2101 stable = NFS_FILE_SYNC;
2102 else
2103 stable = NFS_DATA_SYNC;
2104 } else
2105 stable = NFS_UNSTABLE;
2106 data->args.stable = stable;
2107
2108 data->timestamp = jiffies;
2109
2110 /* Set the initial flags for the task. */
2111 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2112
2113 /* Finalize the task. */
2114 rpc_init_task(task, NFS_CLIENT(inode), nfs4_write_done, flags);
2115 rpc_call_setup(task, &msg, 0);
2116}
2117
2118static void
2119nfs4_commit_done(struct rpc_task *task)
2120{
2121 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
2122 struct inode *inode = data->inode;
2123
2124 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2125 rpc_restart_call(task);
2126 return;
2127 }
2128 /* Call back common NFS writeback processing */
2129 nfs_commit_done(task);
2130}
2131
2132static void
2133nfs4_proc_commit_setup(struct nfs_write_data *data, int how)
2134{
2135 struct rpc_task *task = &data->task;
2136 struct rpc_message msg = {
2137 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
2138 .rpc_argp = &data->args,
2139 .rpc_resp = &data->res,
2140 .rpc_cred = data->cred,
2141 };
2142 struct inode *inode = data->inode;
2143 int flags;
2144
2145 /* Set the initial flags for the task. */
2146 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2147
2148 /* Finalize the task. */
2149 rpc_init_task(task, NFS_CLIENT(inode), nfs4_commit_done, flags);
2150 rpc_call_setup(task, &msg, 0);
2151}
2152
2153/*
2154 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2155 * standalone procedure for queueing an asynchronous RENEW.
2156 */
2157static void
2158renew_done(struct rpc_task *task)
2159{
2160 struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp;
2161 unsigned long timestamp = (unsigned long)task->tk_calldata;
2162
2163 if (task->tk_status < 0) {
2164 switch (task->tk_status) {
2165 case -NFS4ERR_STALE_CLIENTID:
2166 case -NFS4ERR_EXPIRED:
2167 case -NFS4ERR_CB_PATH_DOWN:
2168 nfs4_schedule_state_recovery(clp);
2169 }
2170 return;
2171 }
2172 spin_lock(&clp->cl_lock);
2173 if (time_before(clp->cl_last_renewal,timestamp))
2174 clp->cl_last_renewal = timestamp;
2175 spin_unlock(&clp->cl_lock);
2176}
2177
2178int
2179nfs4_proc_async_renew(struct nfs4_client *clp)
2180{
2181 struct rpc_message msg = {
2182 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2183 .rpc_argp = clp,
2184 .rpc_cred = clp->cl_cred,
2185 };
2186
2187 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
2188 renew_done, (void *)jiffies);
2189}
2190
2191int
2192nfs4_proc_renew(struct nfs4_client *clp)
2193{
2194 struct rpc_message msg = {
2195 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2196 .rpc_argp = clp,
2197 .rpc_cred = clp->cl_cred,
2198 };
2199 unsigned long now = jiffies;
2200 int status;
2201
2202 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2203 if (status < 0)
2204 return status;
2205 spin_lock(&clp->cl_lock);
2206 if (time_before(clp->cl_last_renewal,now))
2207 clp->cl_last_renewal = now;
2208 spin_unlock(&clp->cl_lock);
2209 return 0;
2210}
2211
aa1870af
BF
2212static inline int nfs4_server_supports_acls(struct nfs_server *server)
2213{
2214 return (server->caps & NFS_CAP_ACLS)
2215 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
2216 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
2217}
2218
2219/* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2220 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2221 * the stack.
2222 */
2223#define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2224
2225static void buf_to_pages(const void *buf, size_t buflen,
2226 struct page **pages, unsigned int *pgbase)
2227{
2228 const void *p = buf;
2229
2230 *pgbase = offset_in_page(buf);
2231 p -= *pgbase;
2232 while (p < buf + buflen) {
2233 *(pages++) = virt_to_page(p);
2234 p += PAGE_CACHE_SIZE;
2235 }
2236}
2237
e50a1c2e
BF
2238struct nfs4_cached_acl {
2239 int cached;
2240 size_t len;
3e9d4154 2241 char data[0];
e50a1c2e
BF
2242};
2243
2244static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
2245{
2246 struct nfs_inode *nfsi = NFS_I(inode);
2247
2248 spin_lock(&inode->i_lock);
2249 kfree(nfsi->nfs4_acl);
2250 nfsi->nfs4_acl = acl;
2251 spin_unlock(&inode->i_lock);
2252}
2253
2254static void nfs4_zap_acl_attr(struct inode *inode)
2255{
2256 nfs4_set_cached_acl(inode, NULL);
2257}
2258
2259static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
2260{
2261 struct nfs_inode *nfsi = NFS_I(inode);
2262 struct nfs4_cached_acl *acl;
2263 int ret = -ENOENT;
2264
2265 spin_lock(&inode->i_lock);
2266 acl = nfsi->nfs4_acl;
2267 if (acl == NULL)
2268 goto out;
2269 if (buf == NULL) /* user is just asking for length */
2270 goto out_len;
2271 if (acl->cached == 0)
2272 goto out;
2273 ret = -ERANGE; /* see getxattr(2) man page */
2274 if (acl->len > buflen)
2275 goto out;
2276 memcpy(buf, acl->data, acl->len);
2277out_len:
2278 ret = acl->len;
2279out:
2280 spin_unlock(&inode->i_lock);
2281 return ret;
2282}
2283
2284static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
2285{
2286 struct nfs4_cached_acl *acl;
2287
2288 if (buf && acl_len <= PAGE_SIZE) {
2289 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
2290 if (acl == NULL)
2291 goto out;
2292 acl->cached = 1;
2293 memcpy(acl->data, buf, acl_len);
2294 } else {
2295 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
2296 if (acl == NULL)
2297 goto out;
2298 acl->cached = 0;
2299 }
2300 acl->len = acl_len;
2301out:
2302 nfs4_set_cached_acl(inode, acl);
2303}
2304
2305static inline ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
aa1870af 2306{
aa1870af
BF
2307 struct page *pages[NFS4ACL_MAXPAGES];
2308 struct nfs_getaclargs args = {
2309 .fh = NFS_FH(inode),
2310 .acl_pages = pages,
2311 .acl_len = buflen,
2312 };
2313 size_t resp_len = buflen;
e50a1c2e 2314 void *resp_buf;
aa1870af
BF
2315 struct rpc_message msg = {
2316 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
2317 .rpc_argp = &args,
2318 .rpc_resp = &resp_len,
2319 };
e50a1c2e 2320 struct page *localpage = NULL;
aa1870af
BF
2321 int ret;
2322
e50a1c2e
BF
2323 if (buflen < PAGE_SIZE) {
2324 /* As long as we're doing a round trip to the server anyway,
2325 * let's be prepared for a page of acl data. */
2326 localpage = alloc_page(GFP_KERNEL);
2327 resp_buf = page_address(localpage);
2328 if (localpage == NULL)
2329 return -ENOMEM;
2330 args.acl_pages[0] = localpage;
2331 args.acl_pgbase = 0;
2332 args.acl_len = PAGE_SIZE;
2333 } else {
2334 resp_buf = buf;
2335 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
2336 }
aa1870af 2337 ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
e50a1c2e
BF
2338 if (ret)
2339 goto out_free;
2340 if (resp_len > args.acl_len)
2341 nfs4_write_cached_acl(inode, NULL, resp_len);
2342 else
2343 nfs4_write_cached_acl(inode, resp_buf, resp_len);
2344 if (buf) {
2345 ret = -ERANGE;
2346 if (resp_len > buflen)
2347 goto out_free;
2348 if (localpage)
2349 memcpy(buf, resp_buf, resp_len);
2350 }
2351 ret = resp_len;
2352out_free:
2353 if (localpage)
2354 __free_page(localpage);
aa1870af
BF
2355 return ret;
2356}
2357
e50a1c2e
BF
2358static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
2359{
2360 struct nfs_server *server = NFS_SERVER(inode);
2361 int ret;
2362
2363 if (!nfs4_server_supports_acls(server))
2364 return -EOPNOTSUPP;
2365 ret = nfs_revalidate_inode(server, inode);
2366 if (ret < 0)
2367 return ret;
2368 ret = nfs4_read_cached_acl(inode, buf, buflen);
2369 if (ret != -ENOENT)
2370 return ret;
2371 return nfs4_get_acl_uncached(inode, buf, buflen);
2372}
2373
4b580ee3
BF
2374static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
2375{
2376 struct nfs_server *server = NFS_SERVER(inode);
2377 struct page *pages[NFS4ACL_MAXPAGES];
2378 struct nfs_setaclargs arg = {
2379 .fh = NFS_FH(inode),
2380 .acl_pages = pages,
2381 .acl_len = buflen,
2382 };
2383 struct rpc_message msg = {
2384 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
2385 .rpc_argp = &arg,
2386 .rpc_resp = NULL,
2387 };
2388 int ret;
2389
2390 if (!nfs4_server_supports_acls(server))
2391 return -EOPNOTSUPP;
2392 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
2393 ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0);
e50a1c2e
BF
2394 if (ret == 0)
2395 nfs4_write_cached_acl(inode, buf, buflen);
4b580ee3
BF
2396 return ret;
2397}
2398
1da177e4 2399static int
faf5f49c 2400nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
1da177e4
LT
2401{
2402 struct nfs4_client *clp = server->nfs4_state;
2403
2404 if (!clp || task->tk_status >= 0)
2405 return 0;
2406 switch(task->tk_status) {
2407 case -NFS4ERR_STALE_CLIENTID:
2408 case -NFS4ERR_STALE_STATEID:
2409 case -NFS4ERR_EXPIRED:
2410 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL);
2411 nfs4_schedule_state_recovery(clp);
2412 if (test_bit(NFS4CLNT_OK, &clp->cl_state))
2413 rpc_wake_up_task(task);
2414 task->tk_status = 0;
2415 return -EAGAIN;
2416 case -NFS4ERR_GRACE:
2417 case -NFS4ERR_DELAY:
2418 rpc_delay(task, NFS4_POLL_RETRY_MAX);
2419 task->tk_status = 0;
2420 return -EAGAIN;
2421 case -NFS4ERR_OLD_STATEID:
2422 task->tk_status = 0;
2423 return -EAGAIN;
2424 }
2425 task->tk_status = nfs4_map_errors(task->tk_status);
2426 return 0;
2427}
2428
2429static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp)
2430{
2431 DEFINE_WAIT(wait);
2432 sigset_t oldset;
2433 int interruptible, res = 0;
2434
2435 might_sleep();
2436
2437 rpc_clnt_sigmask(clnt, &oldset);
2438 interruptible = TASK_UNINTERRUPTIBLE;
2439 if (clnt->cl_intr)
2440 interruptible = TASK_INTERRUPTIBLE;
2441 prepare_to_wait(&clp->cl_waitq, &wait, interruptible);
2442 nfs4_schedule_state_recovery(clp);
2443 if (clnt->cl_intr && signalled())
2444 res = -ERESTARTSYS;
2445 else if (!test_bit(NFS4CLNT_OK, &clp->cl_state))
2446 schedule();
2447 finish_wait(&clp->cl_waitq, &wait);
2448 rpc_clnt_sigunmask(clnt, &oldset);
2449 return res;
2450}
2451
2452static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
2453{
2454 sigset_t oldset;
2455 int res = 0;
2456
2457 might_sleep();
2458
2459 if (*timeout <= 0)
2460 *timeout = NFS4_POLL_RETRY_MIN;
2461 if (*timeout > NFS4_POLL_RETRY_MAX)
2462 *timeout = NFS4_POLL_RETRY_MAX;
2463 rpc_clnt_sigmask(clnt, &oldset);
2464 if (clnt->cl_intr) {
041e0e3b 2465 schedule_timeout_interruptible(*timeout);
1da177e4
LT
2466 if (signalled())
2467 res = -ERESTARTSYS;
041e0e3b
NA
2468 } else
2469 schedule_timeout_uninterruptible(*timeout);
1da177e4
LT
2470 rpc_clnt_sigunmask(clnt, &oldset);
2471 *timeout <<= 1;
2472 return res;
2473}
2474
2475/* This is the error handling routine for processes that are allowed
2476 * to sleep.
2477 */
faf5f49c 2478int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
1da177e4
LT
2479{
2480 struct nfs4_client *clp = server->nfs4_state;
2481 int ret = errorcode;
2482
2483 exception->retry = 0;
2484 switch(errorcode) {
2485 case 0:
2486 return 0;
2487 case -NFS4ERR_STALE_CLIENTID:
2488 case -NFS4ERR_STALE_STATEID:
2489 case -NFS4ERR_EXPIRED:
2490 ret = nfs4_wait_clnt_recover(server->client, clp);
2491 if (ret == 0)
2492 exception->retry = 1;
2493 break;
2494 case -NFS4ERR_GRACE:
2495 case -NFS4ERR_DELAY:
2496 ret = nfs4_delay(server->client, &exception->timeout);
2497 if (ret == 0)
2498 exception->retry = 1;
2499 break;
2500 case -NFS4ERR_OLD_STATEID:
2501 if (ret == 0)
2502 exception->retry = 1;
2503 }
2504 /* We failed to handle the error */
2505 return nfs4_map_errors(ret);
2506}
2507
2508int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port)
2509{
2510 nfs4_verifier sc_verifier;
2511 struct nfs4_setclientid setclientid = {
2512 .sc_verifier = &sc_verifier,
2513 .sc_prog = program,
2514 };
2515 struct rpc_message msg = {
2516 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
2517 .rpc_argp = &setclientid,
2518 .rpc_resp = clp,
2519 .rpc_cred = clp->cl_cred,
2520 };
2521 u32 *p;
2522 int loop = 0;
2523 int status;
2524
2525 p = (u32*)sc_verifier.data;
2526 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
2527 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
2528
2529 for(;;) {
2530 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
2531 sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u",
2532 clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr),
2533 clp->cl_cred->cr_ops->cr_name,
2534 clp->cl_id_uniquifier);
2535 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
2536 sizeof(setclientid.sc_netid), "tcp");
2537 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
2538 sizeof(setclientid.sc_uaddr), "%s.%d.%d",
2539 clp->cl_ipaddr, port >> 8, port & 255);
2540
2541 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2542 if (status != -NFS4ERR_CLID_INUSE)
2543 break;
2544 if (signalled())
2545 break;
2546 if (loop++ & 1)
2547 ssleep(clp->cl_lease_time + 1);
2548 else
2549 if (++clp->cl_id_uniquifier == 0)
2550 break;
2551 }
2552 return status;
2553}
2554
2555int
2556nfs4_proc_setclientid_confirm(struct nfs4_client *clp)
2557{
2558 struct nfs_fsinfo fsinfo;
2559 struct rpc_message msg = {
2560 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
2561 .rpc_argp = clp,
2562 .rpc_resp = &fsinfo,
2563 .rpc_cred = clp->cl_cred,
2564 };
2565 unsigned long now;
2566 int status;
2567
2568 now = jiffies;
2569 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2570 if (status == 0) {
2571 spin_lock(&clp->cl_lock);
2572 clp->cl_lease_time = fsinfo.lease_time * HZ;
2573 clp->cl_last_renewal = now;
2574 spin_unlock(&clp->cl_lock);
2575 }
2576 return status;
2577}
2578
2579static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2580{
2581 struct nfs4_delegreturnargs args = {
2582 .fhandle = NFS_FH(inode),
2583 .stateid = stateid,
2584 };
2585 struct rpc_message msg = {
2586 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
2587 .rpc_argp = &args,
2588 .rpc_cred = cred,
2589 };
2590
2591 return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2592}
2593
2594int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2595{
2596 struct nfs_server *server = NFS_SERVER(inode);
2597 struct nfs4_exception exception = { };
2598 int err;
2599 do {
2600 err = _nfs4_proc_delegreturn(inode, cred, stateid);
2601 switch (err) {
2602 case -NFS4ERR_STALE_STATEID:
2603 case -NFS4ERR_EXPIRED:
2604 nfs4_schedule_state_recovery(server->nfs4_state);
2605 case 0:
2606 return 0;
2607 }
2608 err = nfs4_handle_exception(server, err, &exception);
2609 } while (exception.retry);
2610 return err;
2611}
2612
2613#define NFS4_LOCK_MINTIMEOUT (1 * HZ)
2614#define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
2615
2616/*
2617 * sleep, with exponential backoff, and retry the LOCK operation.
2618 */
2619static unsigned long
2620nfs4_set_lock_task_retry(unsigned long timeout)
2621{
041e0e3b 2622 schedule_timeout_interruptible(timeout);
1da177e4
LT
2623 timeout <<= 1;
2624 if (timeout > NFS4_LOCK_MAXTIMEOUT)
2625 return NFS4_LOCK_MAXTIMEOUT;
2626 return timeout;
2627}
2628
2629static inline int
2630nfs4_lck_type(int cmd, struct file_lock *request)
2631{
2632 /* set lock type */
2633 switch (request->fl_type) {
2634 case F_RDLCK:
2635 return IS_SETLKW(cmd) ? NFS4_READW_LT : NFS4_READ_LT;
2636 case F_WRLCK:
2637 return IS_SETLKW(cmd) ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
2638 case F_UNLCK:
2639 return NFS4_WRITE_LT;
2640 }
2641 BUG();
2642 return 0;
2643}
2644
2645static inline uint64_t
2646nfs4_lck_length(struct file_lock *request)
2647{
2648 if (request->fl_end == OFFSET_MAX)
2649 return ~(uint64_t)0;
2650 return request->fl_end - request->fl_start + 1;
2651}
2652
2653static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2654{
2655 struct inode *inode = state->inode;
2656 struct nfs_server *server = NFS_SERVER(inode);
2657 struct nfs4_client *clp = server->nfs4_state;
2658 struct nfs_lockargs arg = {
2659 .fh = NFS_FH(inode),
2660 .type = nfs4_lck_type(cmd, request),
2661 .offset = request->fl_start,
2662 .length = nfs4_lck_length(request),
2663 };
2664 struct nfs_lockres res = {
2665 .server = server,
2666 };
2667 struct rpc_message msg = {
2668 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
2669 .rpc_argp = &arg,
2670 .rpc_resp = &res,
2671 .rpc_cred = state->owner->so_cred,
2672 };
2673 struct nfs_lowner nlo;
2674 struct nfs4_lock_state *lsp;
2675 int status;
2676
2677 down_read(&clp->cl_sem);
2678 nlo.clientid = clp->cl_clientid;
8d0a8a9d
TM
2679 status = nfs4_set_lock_state(state, request);
2680 if (status != 0)
2681 goto out;
2682 lsp = request->fl_u.nfs4_fl.owner;
2683 nlo.id = lsp->ls_id;
1da177e4
LT
2684 arg.u.lockt = &nlo;
2685 status = rpc_call_sync(server->client, &msg, 0);
2686 if (!status) {
2687 request->fl_type = F_UNLCK;
2688 } else if (status == -NFS4ERR_DENIED) {
2689 int64_t len, start, end;
2690 start = res.u.denied.offset;
2691 len = res.u.denied.length;
2692 end = start + len - 1;
2693 if (end < 0 || len == 0)
2694 request->fl_end = OFFSET_MAX;
2695 else
2696 request->fl_end = (loff_t)end;
2697 request->fl_start = (loff_t)start;
2698 request->fl_type = F_WRLCK;
2699 if (res.u.denied.type & 1)
2700 request->fl_type = F_RDLCK;
2701 request->fl_pid = 0;
2702 status = 0;
2703 }
8d0a8a9d 2704out:
1da177e4
LT
2705 up_read(&clp->cl_sem);
2706 return status;
2707}
2708
2709static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2710{
2711 struct nfs4_exception exception = { };
2712 int err;
2713
2714 do {
2715 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2716 _nfs4_proc_getlk(state, cmd, request),
2717 &exception);
2718 } while (exception.retry);
2719 return err;
2720}
2721
2722static int do_vfs_lock(struct file *file, struct file_lock *fl)
2723{
2724 int res = 0;
2725 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
2726 case FL_POSIX:
2727 res = posix_lock_file_wait(file, fl);
2728 break;
2729 case FL_FLOCK:
2730 res = flock_lock_file_wait(file, fl);
2731 break;
2732 default:
2733 BUG();
2734 }
2735 if (res < 0)
2736 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
2737 __FUNCTION__);
2738 return res;
2739}
2740
faf5f49c
TM
2741struct nfs4_unlockdata {
2742 struct nfs_lockargs arg;
2743 struct nfs_locku_opargs luargs;
2744 struct nfs_lockres res;
2745 struct nfs4_lock_state *lsp;
2746 struct nfs_open_context *ctx;
2747 atomic_t refcount;
2748 struct completion completion;
2749};
2750
2751static void nfs4_locku_release_calldata(struct nfs4_unlockdata *calldata)
1da177e4 2752{
faf5f49c
TM
2753 if (atomic_dec_and_test(&calldata->refcount)) {
2754 nfs_free_seqid(calldata->luargs.seqid);
2755 nfs4_put_lock_state(calldata->lsp);
2756 put_nfs_open_context(calldata->ctx);
2757 kfree(calldata);
2758 }
2759}
2760
2761static void nfs4_locku_complete(struct nfs4_unlockdata *calldata)
2762{
2763 complete(&calldata->completion);
2764 nfs4_locku_release_calldata(calldata);
2765}
2766
2767static void nfs4_locku_done(struct rpc_task *task)
2768{
2769 struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
2770
2771 nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid);
2772 switch (task->tk_status) {
2773 case 0:
2774 memcpy(calldata->lsp->ls_stateid.data,
2775 calldata->res.u.stateid.data,
2776 sizeof(calldata->lsp->ls_stateid.data));
2777 break;
2778 case -NFS4ERR_STALE_STATEID:
2779 case -NFS4ERR_EXPIRED:
2780 nfs4_schedule_state_recovery(calldata->res.server->nfs4_state);
2781 break;
2782 default:
2783 if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) {
2784 rpc_restart_call(task);
2785 return;
2786 }
2787 }
2788 nfs4_locku_complete(calldata);
2789}
2790
2791static void nfs4_locku_begin(struct rpc_task *task)
2792{
2793 struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
1da177e4
LT
2794 struct rpc_message msg = {
2795 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
faf5f49c
TM
2796 .rpc_argp = &calldata->arg,
2797 .rpc_resp = &calldata->res,
2798 .rpc_cred = calldata->lsp->ls_state->owner->so_cred,
1da177e4 2799 };
faf5f49c
TM
2800 int status;
2801
2802 status = nfs_wait_on_sequence(calldata->luargs.seqid, task);
2803 if (status != 0)
2804 return;
2805 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
2806 nfs4_locku_complete(calldata);
2807 task->tk_exit = NULL;
2808 rpc_exit(task, 0);
2809 return;
2810 }
2811 rpc_call_setup(task, &msg, 0);
2812}
2813
2814static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
2815{
2816 struct nfs4_unlockdata *calldata;
2817 struct inode *inode = state->inode;
2818 struct nfs_server *server = NFS_SERVER(inode);
1da177e4 2819 struct nfs4_lock_state *lsp;
8d0a8a9d 2820 int status;
faf5f49c 2821
8d0a8a9d
TM
2822 status = nfs4_set_lock_state(state, request);
2823 if (status != 0)
faf5f49c 2824 return status;
8d0a8a9d 2825 lsp = request->fl_u.nfs4_fl.owner;
1da177e4 2826 /* We might have lost the locks! */
8d0a8a9d 2827 if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
faf5f49c
TM
2828 return 0;
2829 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
2830 if (calldata == NULL)
2831 return -ENOMEM;
2832 calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2833 if (calldata->luargs.seqid == NULL) {
2834 kfree(calldata);
2835 return -ENOMEM;
2836 }
2837 calldata->luargs.stateid = &lsp->ls_stateid;
2838 calldata->arg.fh = NFS_FH(inode);
2839 calldata->arg.type = nfs4_lck_type(cmd, request);
2840 calldata->arg.offset = request->fl_start;
2841 calldata->arg.length = nfs4_lck_length(request);
2842 calldata->arg.u.locku = &calldata->luargs;
2843 calldata->res.server = server;
2844 calldata->lsp = lsp;
2845 atomic_inc(&lsp->ls_count);
2846
2847 /* Ensure we don't close file until we're done freeing locks! */
2848 calldata->ctx = get_nfs_open_context((struct nfs_open_context*)request->fl_file->private_data);
2849
2850 atomic_set(&calldata->refcount, 2);
2851 init_completion(&calldata->completion);
2852
2853 status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_locku_begin,
2854 nfs4_locku_done, calldata);
1da177e4 2855 if (status == 0)
faf5f49c
TM
2856 wait_for_completion_interruptible(&calldata->completion);
2857 do_vfs_lock(request->fl_file, request);
2858 nfs4_locku_release_calldata(calldata);
1da177e4
LT
2859 return status;
2860}
2861
1da177e4
LT
2862static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
2863{
2864 struct inode *inode = state->inode;
2865 struct nfs_server *server = NFS_SERVER(inode);
8d0a8a9d 2866 struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
06735b34
TM
2867 struct nfs_lock_opargs largs = {
2868 .lock_stateid = &lsp->ls_stateid,
2869 .open_stateid = &state->stateid,
2870 .lock_owner = {
2871 .clientid = server->nfs4_state->cl_clientid,
2872 .id = lsp->ls_id,
2873 },
2874 .reclaim = reclaim,
2875 };
1da177e4
LT
2876 struct nfs_lockargs arg = {
2877 .fh = NFS_FH(inode),
2878 .type = nfs4_lck_type(cmd, request),
2879 .offset = request->fl_start,
2880 .length = nfs4_lck_length(request),
06735b34
TM
2881 .u = {
2882 .lock = &largs,
2883 },
1da177e4
LT
2884 };
2885 struct nfs_lockres res = {
2886 .server = server,
2887 };
2888 struct rpc_message msg = {
2889 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
2890 .rpc_argp = &arg,
2891 .rpc_resp = &res,
2892 .rpc_cred = state->owner->so_cred,
2893 };
cee54fc9 2894 int status = -ENOMEM;
1da177e4 2895
06735b34
TM
2896 largs.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2897 if (largs.lock_seqid == NULL)
cee54fc9
TM
2898 return -ENOMEM;
2899 if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
1da177e4 2900 struct nfs4_state_owner *owner = state->owner;
06735b34
TM
2901
2902 largs.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
2903 if (largs.open_seqid == NULL)
2904 goto out;
1da177e4 2905 largs.new_lock_owner = 1;
06735b34
TM
2906 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
2907 /* increment open seqid on success, and seqid mutating errors */
2908 if (largs.new_lock_owner != 0) {
2909 nfs_increment_open_seqid(status, largs.open_seqid);
2910 if (status == 0)
2911 nfs_confirm_seqid(&lsp->ls_seqid, 0);
8d0a8a9d 2912 }
06735b34
TM
2913 nfs_free_seqid(largs.open_seqid);
2914 } else
1da177e4 2915 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
06735b34
TM
2916 /* increment lock seqid on success, and seqid mutating errors*/
2917 nfs_increment_lock_seqid(status, largs.lock_seqid);
1da177e4 2918 /* save the returned stateid. */
cee54fc9 2919 if (status == 0) {
06735b34
TM
2920 memcpy(lsp->ls_stateid.data, res.u.stateid.data,
2921 sizeof(lsp->ls_stateid.data));
cee54fc9
TM
2922 lsp->ls_flags |= NFS_LOCK_INITIALIZED;
2923 } else if (status == -NFS4ERR_DENIED)
1da177e4 2924 status = -EAGAIN;
06735b34
TM
2925out:
2926 nfs_free_seqid(largs.lock_seqid);
1da177e4
LT
2927 return status;
2928}
2929
2930static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
2931{
202b50dc
TM
2932 struct nfs_server *server = NFS_SERVER(state->inode);
2933 struct nfs4_exception exception = { };
2934 int err;
2935
2936 do {
2937 err = _nfs4_do_setlk(state, F_SETLK, request, 1);
2938 if (err != -NFS4ERR_DELAY)
2939 break;
2940 nfs4_handle_exception(server, err, &exception);
2941 } while (exception.retry);
2942 return err;
1da177e4
LT
2943}
2944
2945static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
2946{
202b50dc
TM
2947 struct nfs_server *server = NFS_SERVER(state->inode);
2948 struct nfs4_exception exception = { };
2949 int err;
2950
2951 do {
2952 err = _nfs4_do_setlk(state, F_SETLK, request, 0);
2953 if (err != -NFS4ERR_DELAY)
2954 break;
2955 nfs4_handle_exception(server, err, &exception);
2956 } while (exception.retry);
2957 return err;
1da177e4
LT
2958}
2959
2960static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2961{
2962 struct nfs4_client *clp = state->owner->so_client;
2963 int status;
2964
2965 down_read(&clp->cl_sem);
8d0a8a9d
TM
2966 status = nfs4_set_lock_state(state, request);
2967 if (status == 0)
2968 status = _nfs4_do_setlk(state, cmd, request, 0);
1da177e4
LT
2969 if (status == 0) {
2970 /* Note: we always want to sleep here! */
2971 request->fl_flags |= FL_SLEEP;
2972 if (do_vfs_lock(request->fl_file, request) < 0)
2973 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
2974 }
2975 up_read(&clp->cl_sem);
2976 return status;
2977}
2978
2979static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2980{
2981 struct nfs4_exception exception = { };
2982 int err;
2983
2984 do {
2985 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2986 _nfs4_proc_setlk(state, cmd, request),
2987 &exception);
2988 } while (exception.retry);
2989 return err;
2990}
2991
2992static int
2993nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
2994{
2995 struct nfs_open_context *ctx;
2996 struct nfs4_state *state;
2997 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
2998 int status;
2999
3000 /* verify open state */
3001 ctx = (struct nfs_open_context *)filp->private_data;
3002 state = ctx->state;
3003
3004 if (request->fl_start < 0 || request->fl_end < 0)
3005 return -EINVAL;
3006
3007 if (IS_GETLK(cmd))
3008 return nfs4_proc_getlk(state, F_GETLK, request);
3009
3010 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
3011 return -EINVAL;
3012
3013 if (request->fl_type == F_UNLCK)
3014 return nfs4_proc_unlck(state, cmd, request);
3015
3016 do {
3017 status = nfs4_proc_setlk(state, cmd, request);
3018 if ((status != -EAGAIN) || IS_SETLK(cmd))
3019 break;
3020 timeout = nfs4_set_lock_task_retry(timeout);
3021 status = -ERESTARTSYS;
3022 if (signalled())
3023 break;
3024 } while(status < 0);
1da177e4
LT
3025 return status;
3026}
3027
6b3b5496 3028
aa1870af
BF
3029#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3030
6b3b5496
BF
3031int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
3032 size_t buflen, int flags)
3033{
4b580ee3
BF
3034 struct inode *inode = dentry->d_inode;
3035
3036 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3037 return -EOPNOTSUPP;
3038
3039 if (!S_ISREG(inode->i_mode) &&
3040 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3041 return -EPERM;
3042
3043 return nfs4_proc_set_acl(inode, buf, buflen);
6b3b5496
BF
3044}
3045
3046/* The getxattr man page suggests returning -ENODATA for unknown attributes,
3047 * and that's what we'll do for e.g. user attributes that haven't been set.
3048 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3049 * attributes in kernel-managed attribute namespaces. */
3050ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
3051 size_t buflen)
3052{
aa1870af
BF
3053 struct inode *inode = dentry->d_inode;
3054
3055 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3056 return -EOPNOTSUPP;
3057
3058 return nfs4_proc_get_acl(inode, buf, buflen);
6b3b5496
BF
3059}
3060
3061ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
3062{
aa1870af 3063 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
6b3b5496
BF
3064
3065 if (buf && buflen < len)
3066 return -ERANGE;
3067 if (buf)
aa1870af
BF
3068 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
3069 return len;
6b3b5496
BF
3070}
3071
1da177e4
LT
3072struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
3073 .recover_open = nfs4_open_reclaim,
3074 .recover_lock = nfs4_lock_reclaim,
3075};
3076
3077struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = {
3078 .recover_open = nfs4_open_expired,
3079 .recover_lock = nfs4_lock_expired,
3080};
3081
6b3b5496
BF
3082static struct inode_operations nfs4_file_inode_operations = {
3083 .permission = nfs_permission,
3084 .getattr = nfs_getattr,
3085 .setattr = nfs_setattr,
3086 .getxattr = nfs4_getxattr,
3087 .setxattr = nfs4_setxattr,
3088 .listxattr = nfs4_listxattr,
3089};
3090
1da177e4
LT
3091struct nfs_rpc_ops nfs_v4_clientops = {
3092 .version = 4, /* protocol version */
3093 .dentry_ops = &nfs4_dentry_operations,
3094 .dir_inode_ops = &nfs4_dir_inode_operations,
6b3b5496 3095 .file_inode_ops = &nfs4_file_inode_operations,
1da177e4
LT
3096 .getroot = nfs4_proc_get_root,
3097 .getattr = nfs4_proc_getattr,
3098 .setattr = nfs4_proc_setattr,
3099 .lookup = nfs4_proc_lookup,
3100 .access = nfs4_proc_access,
3101 .readlink = nfs4_proc_readlink,
3102 .read = nfs4_proc_read,
3103 .write = nfs4_proc_write,
3104 .commit = nfs4_proc_commit,
3105 .create = nfs4_proc_create,
3106 .remove = nfs4_proc_remove,
3107 .unlink_setup = nfs4_proc_unlink_setup,
3108 .unlink_done = nfs4_proc_unlink_done,
3109 .rename = nfs4_proc_rename,
3110 .link = nfs4_proc_link,
3111 .symlink = nfs4_proc_symlink,
3112 .mkdir = nfs4_proc_mkdir,
3113 .rmdir = nfs4_proc_remove,
3114 .readdir = nfs4_proc_readdir,
3115 .mknod = nfs4_proc_mknod,
3116 .statfs = nfs4_proc_statfs,
3117 .fsinfo = nfs4_proc_fsinfo,
3118 .pathconf = nfs4_proc_pathconf,
3119 .decode_dirent = nfs4_decode_dirent,
3120 .read_setup = nfs4_proc_read_setup,
3121 .write_setup = nfs4_proc_write_setup,
3122 .commit_setup = nfs4_proc_commit_setup,
02a913a7
TM
3123 .file_open = nfs_open,
3124 .file_release = nfs_release,
1da177e4 3125 .lock = nfs4_proc_lock,
e50a1c2e 3126 .clear_acl_cache = nfs4_zap_acl_attr,
1da177e4
LT
3127};
3128
3129/*
3130 * Local variables:
3131 * c-basic-offset: 8
3132 * End:
3133 */