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