blob: 8154f257946957243001f8f5470656297736f27b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4proc.c
3 *
4 * Client-side procedure declarations for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/mm.h>
39#include <linux/utsname.h>
40#include <linux/delay.h>
41#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/sunrpc/clnt.h>
44#include <linux/nfs.h>
45#include <linux/nfs4.h>
46#include <linux/nfs_fs.h>
47#include <linux/nfs_page.h>
48#include <linux/smp_lock.h>
49#include <linux/namei.h>
Trond Myklebust02a913a2005-10-18 14:20:17 -070050#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Trond Myklebust4ce79712005-06-22 17:16:21 +000052#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#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
Trond Myklebustcdd4e682006-01-03 09:55:12 +010060struct nfs4_opendata;
61static int _nfs4_proc_open_confirm(struct nfs4_opendata *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
Trond Myklebustfaf5f492005-10-18 14:20:15 -070063static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
Trond Myklebustfaf5f492005-10-18 14:20:15 -070065static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
67extern struct rpc_procinfo nfs4_procedures[];
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* Prevent leaks of NFSv4 errors into userland */
70int nfs4_map_errors(int err)
71{
72 if (err < -1000) {
73 dprintk("%s could not handle NFSv4 error %d\n",
74 __FUNCTION__, -err);
75 return -EIO;
76 }
77 return err;
78}
79
80/*
81 * This is our standard bitmap for GETATTR requests.
82 */
83const u32 nfs4_fattr_bitmap[2] = {
84 FATTR4_WORD0_TYPE
85 | FATTR4_WORD0_CHANGE
86 | FATTR4_WORD0_SIZE
87 | FATTR4_WORD0_FSID
88 | FATTR4_WORD0_FILEID,
89 FATTR4_WORD1_MODE
90 | FATTR4_WORD1_NUMLINKS
91 | FATTR4_WORD1_OWNER
92 | FATTR4_WORD1_OWNER_GROUP
93 | FATTR4_WORD1_RAWDEV
94 | FATTR4_WORD1_SPACE_USED
95 | FATTR4_WORD1_TIME_ACCESS
96 | FATTR4_WORD1_TIME_METADATA
97 | FATTR4_WORD1_TIME_MODIFY
98};
99
100const u32 nfs4_statfs_bitmap[2] = {
101 FATTR4_WORD0_FILES_AVAIL
102 | FATTR4_WORD0_FILES_FREE
103 | FATTR4_WORD0_FILES_TOTAL,
104 FATTR4_WORD1_SPACE_AVAIL
105 | FATTR4_WORD1_SPACE_FREE
106 | FATTR4_WORD1_SPACE_TOTAL
107};
108
Trond Myklebust4ce79712005-06-22 17:16:21 +0000109const u32 nfs4_pathconf_bitmap[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 FATTR4_WORD0_MAXLINK
111 | FATTR4_WORD0_MAXNAME,
112 0
113};
114
115const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
116 | FATTR4_WORD0_MAXREAD
117 | FATTR4_WORD0_MAXWRITE
118 | FATTR4_WORD0_LEASE_TIME,
119 0
120};
121
122static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry,
123 struct nfs4_readdir_arg *readdir)
124{
125 u32 *start, *p;
126
127 BUG_ON(readdir->count < 80);
128 if (cookie > 2) {
Adrian Bunkb7ef1952005-06-22 17:16:28 +0000129 readdir->cookie = cookie;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
131 return;
132 }
133
134 readdir->cookie = 0;
135 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
136 if (cookie == 2)
137 return;
138
139 /*
140 * NFSv4 servers do not return entries for '.' and '..'
141 * Therefore, we fake these entries here. We let '.'
142 * have cookie 0 and '..' have cookie 1. Note that
143 * when talking to the server, we always send cookie 0
144 * instead of 1 or 2.
145 */
146 start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0);
147
148 if (cookie == 0) {
149 *p++ = xdr_one; /* next */
150 *p++ = xdr_zero; /* cookie, first word */
151 *p++ = xdr_one; /* cookie, second word */
152 *p++ = xdr_one; /* entry len */
153 memcpy(p, ".\0\0\0", 4); /* entry */
154 p++;
155 *p++ = xdr_one; /* bitmap length */
156 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
157 *p++ = htonl(8); /* attribute buffer length */
158 p = xdr_encode_hyper(p, dentry->d_inode->i_ino);
159 }
160
161 *p++ = xdr_one; /* next */
162 *p++ = xdr_zero; /* cookie, first word */
163 *p++ = xdr_two; /* cookie, second word */
164 *p++ = xdr_two; /* entry len */
165 memcpy(p, "..\0\0", 4); /* entry */
166 p++;
167 *p++ = xdr_one; /* bitmap length */
168 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
169 *p++ = htonl(8); /* attribute buffer length */
170 p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino);
171
172 readdir->pgbase = (char *)p - (char *)start;
173 readdir->count -= readdir->pgbase;
174 kunmap_atomic(start, KM_USER0);
175}
176
177static void
178renew_lease(struct nfs_server *server, unsigned long timestamp)
179{
180 struct nfs4_client *clp = server->nfs4_state;
181 spin_lock(&clp->cl_lock);
182 if (time_before(clp->cl_last_renewal,timestamp))
183 clp->cl_last_renewal = timestamp;
184 spin_unlock(&clp->cl_lock);
185}
186
187static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo)
188{
189 struct nfs_inode *nfsi = NFS_I(inode);
190
Trond Myklebustdecf4912005-10-27 22:12:39 -0400191 spin_lock(&inode->i_lock);
192 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (cinfo->before == nfsi->change_attr && cinfo->atomic)
194 nfsi->change_attr = cinfo->after;
Trond Myklebustdecf4912005-10-27 22:12:39 -0400195 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100198struct nfs4_opendata {
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100199 atomic_t count;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100200 struct nfs_openargs o_arg;
201 struct nfs_openres o_res;
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100202 struct nfs_open_confirmargs c_arg;
203 struct nfs_open_confirmres c_res;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100204 struct nfs_fattr f_attr;
205 struct nfs_fattr dir_attr;
206 struct dentry *dentry;
207 struct dentry *dir;
208 struct nfs4_state_owner *owner;
209 struct iattr attrs;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100210 int rpc_status;
211 int cancelled;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100212};
213
214static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
215 struct nfs4_state_owner *sp, int flags,
216 const struct iattr *attrs)
217{
218 struct dentry *parent = dget_parent(dentry);
219 struct inode *dir = parent->d_inode;
220 struct nfs_server *server = NFS_SERVER(dir);
221 struct nfs4_opendata *p;
222
223 p = kzalloc(sizeof(*p), GFP_KERNEL);
224 if (p == NULL)
225 goto err;
226 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
227 if (p->o_arg.seqid == NULL)
228 goto err_free;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100229 atomic_set(&p->count, 1);
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100230 p->dentry = dget(dentry);
231 p->dir = parent;
232 p->owner = sp;
233 atomic_inc(&sp->so_count);
234 p->o_arg.fh = NFS_FH(dir);
235 p->o_arg.open_flags = flags,
236 p->o_arg.clientid = server->nfs4_state->cl_clientid;
237 p->o_arg.id = sp->so_id;
238 p->o_arg.name = &dentry->d_name;
239 p->o_arg.server = server;
240 p->o_arg.bitmask = server->attr_bitmask;
241 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
242 p->o_res.f_attr = &p->f_attr;
243 p->o_res.dir_attr = &p->dir_attr;
244 p->o_res.server = server;
245 nfs_fattr_init(&p->f_attr);
246 nfs_fattr_init(&p->dir_attr);
247 if (flags & O_EXCL) {
248 u32 *s = (u32 *) p->o_arg.u.verifier.data;
249 s[0] = jiffies;
250 s[1] = current->pid;
251 } else if (flags & O_CREAT) {
252 p->o_arg.u.attrs = &p->attrs;
253 memcpy(&p->attrs, attrs, sizeof(p->attrs));
254 }
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100255 p->c_arg.fh = &p->o_res.fh;
256 p->c_arg.stateid = &p->o_res.stateid;
257 p->c_arg.seqid = p->o_arg.seqid;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100258 return p;
259err_free:
260 kfree(p);
261err:
262 dput(parent);
263 return NULL;
264}
265
266static void nfs4_opendata_free(struct nfs4_opendata *p)
267{
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100268 if (p != NULL && atomic_dec_and_test(&p->count)) {
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100269 nfs_free_seqid(p->o_arg.seqid);
270 nfs4_put_state_owner(p->owner);
271 dput(p->dir);
272 dput(p->dentry);
273 kfree(p);
274 }
275}
276
Trond Myklebust95121352005-10-18 14:20:12 -0700277/* Helper for asynchronous RPC calls */
Trond Myklebust4ce70ad2006-01-03 09:55:05 +0100278static int nfs4_call_async(struct rpc_clnt *clnt,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100279 const struct rpc_call_ops *tk_ops, void *calldata)
Trond Myklebust95121352005-10-18 14:20:12 -0700280{
281 struct rpc_task *task;
282
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100283 if (!(task = rpc_new_task(clnt, RPC_TASK_ASYNC, tk_ops, calldata)))
Trond Myklebust95121352005-10-18 14:20:12 -0700284 return -ENOMEM;
Trond Myklebust95121352005-10-18 14:20:12 -0700285 rpc_execute(task);
286 return 0;
287}
288
Trond Myklebust06f814a2006-01-03 09:55:07 +0100289static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
290{
291 sigset_t oldset;
292 int ret;
293
294 rpc_clnt_sigmask(task->tk_client, &oldset);
295 ret = rpc_wait_for_completion_task(task);
296 rpc_clnt_sigunmask(task->tk_client, &oldset);
297 return ret;
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
301{
302 struct inode *inode = state->inode;
303
304 open_flags &= (FMODE_READ|FMODE_WRITE);
Trond Myklebustd5308382005-11-04 15:33:38 -0500305 /* Protect against nfs4_find_state_byowner() */
Trond Myklebustec073422005-10-20 14:22:47 -0700306 spin_lock(&state->owner->so_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 spin_lock(&inode->i_lock);
Trond Myklebust4cecb762005-11-04 15:32:58 -0500308 memcpy(&state->stateid, stateid, sizeof(state->stateid));
309 if ((open_flags & FMODE_WRITE))
310 state->nwriters++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (open_flags & FMODE_READ)
312 state->nreaders++;
Trond Myklebust4cecb762005-11-04 15:32:58 -0500313 nfs4_state_set_mode_locked(state, state->state | open_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 spin_unlock(&inode->i_lock);
Trond Myklebustec073422005-10-20 14:22:47 -0700315 spin_unlock(&state->owner->so_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100318static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
319{
320 struct inode *inode;
321 struct nfs4_state *state = NULL;
322
323 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
324 goto out;
325 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
326 if (inode == NULL)
327 goto out;
328 state = nfs4_get_open_state(inode, data->owner);
329 if (state == NULL)
330 goto put_inode;
331 update_open_stateid(state, &data->o_res.stateid, data->o_arg.open_flags);
332put_inode:
333 iput(inode);
334out:
335 return state;
336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338/*
339 * OPEN_RECLAIM:
340 * reclaim state on the server after a reboot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 */
342static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
343{
344 struct inode *inode = state->inode;
345 struct nfs_server *server = NFS_SERVER(inode);
346 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
347 struct nfs_openargs o_arg = {
348 .fh = NFS_FH(inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 .id = sp->so_id,
350 .open_flags = state->state,
351 .clientid = server->nfs4_state->cl_clientid,
352 .claim = NFS4_OPEN_CLAIM_PREVIOUS,
353 .bitmask = server->attr_bitmask,
354 };
355 struct nfs_openres o_res = {
356 .server = server, /* Grrr */
357 };
358 struct rpc_message msg = {
359 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
360 .rpc_argp = &o_arg,
361 .rpc_resp = &o_res,
362 .rpc_cred = sp->so_cred,
363 };
364 int status;
365
366 if (delegation != NULL) {
367 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
368 memcpy(&state->stateid, &delegation->stateid,
369 sizeof(state->stateid));
370 set_bit(NFS_DELEGATED_STATE, &state->flags);
371 return 0;
372 }
373 o_arg.u.delegation_type = delegation->type;
374 }
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700375 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
376 if (o_arg.seqid == NULL)
377 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700379 /* Confirm the sequence as being established */
380 nfs_confirm_seqid(&sp->so_seqid, status);
381 nfs_increment_open_seqid(status, o_arg.seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (status == 0) {
383 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
384 if (o_res.delegation_type != 0) {
385 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
386 /* Did the server issue an immediate delegation recall? */
387 if (o_res.do_recall)
388 nfs_async_inode_return_delegation(inode, &o_res.stateid);
389 }
390 }
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700391 nfs_free_seqid(o_arg.seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 clear_bit(NFS_DELEGATED_STATE, &state->flags);
393 /* Ensure we update the inode attributes */
394 NFS_CACHEINV(inode);
395 return status;
396}
397
398static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
399{
400 struct nfs_server *server = NFS_SERVER(state->inode);
401 struct nfs4_exception exception = { };
402 int err;
403 do {
404 err = _nfs4_open_reclaim(sp, state);
Trond Myklebust202b50d2005-06-22 17:16:29 +0000405 if (err != -NFS4ERR_DELAY)
406 break;
407 nfs4_handle_exception(server, err, &exception);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 } while (exception.retry);
409 return err;
410}
411
412static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
413{
414 struct nfs4_state_owner *sp = state->owner;
415 struct inode *inode = dentry->d_inode;
416 struct nfs_server *server = NFS_SERVER(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 struct rpc_message msg = {
418 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 .rpc_cred = sp->so_cred,
420 };
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100421 struct nfs4_opendata *opendata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 int status = 0;
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
425 goto out;
426 if (state->state == 0)
427 goto out;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100428 opendata = nfs4_opendata_alloc(dentry, sp, state->state, NULL);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700429 status = -ENOMEM;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100430 if (opendata == NULL)
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700431 goto out;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100432 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
433 msg.rpc_argp = &opendata->o_arg;
434 msg.rpc_resp = &opendata->o_res;
435 memcpy(opendata->o_arg.u.delegation.data, state->stateid.data,
436 sizeof(opendata->o_arg.u.delegation.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100438 nfs_increment_open_seqid(status, opendata->o_arg.seqid);
Trond Myklebust0a8838f2005-10-18 14:20:14 -0700439 if (status != 0)
440 goto out_free;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100441 if(opendata->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) {
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100442 status = _nfs4_proc_open_confirm(opendata);
Trond Myklebust0a8838f2005-10-18 14:20:14 -0700443 if (status != 0)
444 goto out_free;
445 }
446 nfs_confirm_seqid(&sp->so_seqid, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 if (status >= 0) {
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100448 memcpy(state->stateid.data, opendata->o_res.stateid.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 sizeof(state->stateid.data));
450 clear_bit(NFS_DELEGATED_STATE, &state->flags);
451 }
Trond Myklebust0a8838f2005-10-18 14:20:14 -0700452out_free:
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100453 nfs4_opendata_free(opendata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return status;
456}
457
458int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
459{
460 struct nfs4_exception exception = { };
461 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
462 int err;
463 do {
464 err = _nfs4_open_delegation_recall(dentry, state);
465 switch (err) {
466 case 0:
467 return err;
468 case -NFS4ERR_STALE_CLIENTID:
469 case -NFS4ERR_STALE_STATEID:
470 case -NFS4ERR_EXPIRED:
471 /* Don't recall a delegation if it was lost */
472 nfs4_schedule_state_recovery(server->nfs4_state);
473 return err;
474 }
475 err = nfs4_handle_exception(server, err, &exception);
476 } while (exception.retry);
477 return err;
478}
479
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100480static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100482 struct nfs4_opendata *data = calldata;
483 struct rpc_message msg = {
484 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
485 .rpc_argp = &data->c_arg,
486 .rpc_resp = &data->c_res,
487 .rpc_cred = data->owner->so_cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 };
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100489 rpc_call_setup(task, &msg, 0);
490}
491
492static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
493{
494 struct nfs4_opendata *data = calldata;
495
496 data->rpc_status = task->tk_status;
497 if (RPC_ASSASSINATED(task))
498 return;
499 if (data->rpc_status == 0)
500 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
501 sizeof(data->o_res.stateid.data));
502 nfs_increment_open_seqid(data->rpc_status, data->c_arg.seqid);
503 nfs_confirm_seqid(&data->owner->so_seqid, data->rpc_status);
504}
505
506static void nfs4_open_confirm_release(void *calldata)
507{
508 struct nfs4_opendata *data = calldata;
509 struct nfs4_state *state = NULL;
510
511 /* If this request hasn't been cancelled, do nothing */
512 if (data->cancelled == 0)
513 goto out_free;
514 /* In case of error, no cleanup! */
515 if (data->rpc_status != 0)
516 goto out_free;
517 nfs_confirm_seqid(&data->owner->so_seqid, 0);
518 state = nfs4_opendata_to_nfs4_state(data);
519 if (state != NULL)
520 nfs4_close_state(state, data->o_arg.open_flags);
521out_free:
522 nfs4_opendata_free(data);
523}
524
525static const struct rpc_call_ops nfs4_open_confirm_ops = {
526 .rpc_call_prepare = nfs4_open_confirm_prepare,
527 .rpc_call_done = nfs4_open_confirm_done,
528 .rpc_release = nfs4_open_confirm_release,
529};
530
531/*
532 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
533 */
534static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
535{
536 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
537 struct rpc_task *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 int status;
539
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100540 atomic_inc(&data->count);
541 task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_open_confirm_ops, data);
542 if (IS_ERR(task)) {
543 nfs4_opendata_free(data);
544 return PTR_ERR(task);
545 }
546 status = nfs4_wait_for_completion_rpc_task(task);
547 if (status != 0) {
548 data->cancelled = 1;
549 smp_wmb();
550 } else
551 status = data->rpc_status;
552 rpc_release_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return status;
554}
555
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100556static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100558 struct nfs4_opendata *data = calldata;
559 struct nfs4_state_owner *sp = data->owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 struct rpc_message msg = {
561 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100562 .rpc_argp = &data->o_arg,
563 .rpc_resp = &data->o_res,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .rpc_cred = sp->so_cred,
565 };
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100566
567 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
568 return;
569 /* Update sequence id. */
570 data->o_arg.id = sp->so_id;
571 data->o_arg.clientid = sp->so_client->cl_clientid;
572 rpc_call_setup(task, &msg, 0);
573}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100575static void nfs4_open_done(struct rpc_task *task, void *calldata)
576{
577 struct nfs4_opendata *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100579 data->rpc_status = task->tk_status;
580 if (RPC_ASSASSINATED(task))
581 return;
582 if (task->tk_status == 0) {
583 switch (data->o_res.f_attr->mode & S_IFMT) {
Trond Myklebust6f926b52005-10-18 14:20:18 -0700584 case S_IFREG:
585 break;
586 case S_IFLNK:
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100587 data->rpc_status = -ELOOP;
Trond Myklebust6f926b52005-10-18 14:20:18 -0700588 break;
589 case S_IFDIR:
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100590 data->rpc_status = -EISDIR;
Trond Myklebust6f926b52005-10-18 14:20:18 -0700591 break;
592 default:
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100593 data->rpc_status = -ENOTDIR;
Trond Myklebust6f926b52005-10-18 14:20:18 -0700594 }
595 }
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100596 nfs_increment_open_seqid(data->rpc_status, data->o_arg.seqid);
597}
Trond Myklebust6f926b52005-10-18 14:20:18 -0700598
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100599static void nfs4_open_release(void *calldata)
600{
601 struct nfs4_opendata *data = calldata;
602 struct nfs4_state *state = NULL;
603
604 /* If this request hasn't been cancelled, do nothing */
605 if (data->cancelled == 0)
606 goto out_free;
607 /* In case of error, no cleanup! */
608 if (data->rpc_status != 0)
609 goto out_free;
610 /* In case we need an open_confirm, no cleanup! */
611 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
612 goto out_free;
613 nfs_confirm_seqid(&data->owner->so_seqid, 0);
614 state = nfs4_opendata_to_nfs4_state(data);
615 if (state != NULL)
616 nfs4_close_state(state, data->o_arg.open_flags);
617out_free:
618 nfs4_opendata_free(data);
619}
620
621static const struct rpc_call_ops nfs4_open_ops = {
622 .rpc_call_prepare = nfs4_open_prepare,
623 .rpc_call_done = nfs4_open_done,
624 .rpc_release = nfs4_open_release,
625};
626
627/*
628 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
629 */
630static int _nfs4_proc_open(struct nfs4_opendata *data)
631{
632 struct inode *dir = data->dir->d_inode;
633 struct nfs_server *server = NFS_SERVER(dir);
634 struct nfs_openargs *o_arg = &data->o_arg;
635 struct nfs_openres *o_res = &data->o_res;
636 struct rpc_task *task;
637 int status;
638
639 atomic_inc(&data->count);
640 task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_open_ops, data);
641 if (IS_ERR(task)) {
642 nfs4_opendata_free(data);
643 return PTR_ERR(task);
644 }
645 status = nfs4_wait_for_completion_rpc_task(task);
646 if (status != 0) {
647 data->cancelled = 1;
648 smp_wmb();
649 } else
650 status = data->rpc_status;
651 rpc_release_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (status != 0)
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100653 return status;
654
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400655 if (o_arg->open_flags & O_CREAT) {
656 update_changeattr(dir, &o_res->cinfo);
657 nfs_post_op_update_inode(dir, o_res->dir_attr);
658 } else
659 nfs_refresh_inode(dir, o_res->dir_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100661 status = _nfs4_proc_open_confirm(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 if (status != 0)
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100663 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100665 nfs_confirm_seqid(&data->owner->so_seqid, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100667 return server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr);
668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
671static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags)
672{
673 struct nfs_access_entry cache;
674 int mask = 0;
675 int status;
676
677 if (openflags & FMODE_READ)
678 mask |= MAY_READ;
679 if (openflags & FMODE_WRITE)
680 mask |= MAY_WRITE;
681 status = nfs_access_get_cached(inode, cred, &cache);
682 if (status == 0)
683 goto out;
684
685 /* Be clever: ask server to check for all possible rights */
686 cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ;
687 cache.cred = cred;
688 cache.jiffies = jiffies;
689 status = _nfs4_proc_access(inode, &cache);
690 if (status != 0)
691 return status;
692 nfs_access_add_cache(inode, &cache);
693out:
694 if ((cache.mask & mask) == mask)
695 return 0;
696 return -EACCES;
697}
698
699/*
700 * OPEN_EXPIRED:
701 * reclaim state on the server after a network partition.
702 * Assumes caller holds the appropriate lock
703 */
704static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
705{
706 struct dentry *parent = dget_parent(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 struct inode *inode = state->inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100709 struct nfs4_opendata *opendata;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100710 struct nfs4_state *newstate;
711 int openflags = state->state & (FMODE_READ|FMODE_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 int status = 0;
713
714 if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100715 status = _nfs4_do_access(inode, sp->so_cred, openflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (status < 0)
717 goto out;
718 memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid));
719 set_bit(NFS_DELEGATED_STATE, &state->flags);
720 goto out;
721 }
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700722 status = -ENOMEM;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100723 opendata = nfs4_opendata_alloc(dentry, sp, openflags, NULL);
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100724 if (opendata == NULL)
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700725 goto out;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100726 status = _nfs4_proc_open(opendata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 if (status != 0)
728 goto out_nodeleg;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100729 newstate = nfs4_opendata_to_nfs4_state(opendata);
730 if (newstate != state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 goto out_stale;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100732 if (opendata->o_res.delegation_type != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM))
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100734 nfs_inode_set_delegation(inode, sp->so_cred,
735 &opendata->o_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 else
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100737 nfs_inode_reclaim_delegation(inode, sp->so_cred,
738 &opendata->o_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100740out_close_state:
741 nfs4_close_state(newstate, openflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742out_nodeleg:
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100743 nfs4_opendata_free(opendata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 clear_bit(NFS_DELEGATED_STATE, &state->flags);
745out:
746 dput(parent);
747 return status;
748out_stale:
749 status = -ESTALE;
750 /* Invalidate the state owner so we don't ever use it again */
751 nfs4_drop_state_owner(sp);
752 d_drop(dentry);
753 /* Should we be trying to close that stateid? */
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100754 goto out_close_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
Trond Myklebust202b50d2005-06-22 17:16:29 +0000757static inline int nfs4_do_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
758{
759 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
760 struct nfs4_exception exception = { };
761 int err;
762
763 do {
764 err = _nfs4_open_expired(sp, state, dentry);
765 if (err == -NFS4ERR_DELAY)
766 nfs4_handle_exception(server, err, &exception);
767 } while (exception.retry);
768 return err;
769}
770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
772{
773 struct nfs_inode *nfsi = NFS_I(state->inode);
774 struct nfs_open_context *ctx;
775 int status;
776
777 spin_lock(&state->inode->i_lock);
778 list_for_each_entry(ctx, &nfsi->open_files, list) {
779 if (ctx->state != state)
780 continue;
781 get_nfs_open_context(ctx);
782 spin_unlock(&state->inode->i_lock);
Trond Myklebust202b50d2005-06-22 17:16:29 +0000783 status = nfs4_do_open_expired(sp, state, ctx->dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 put_nfs_open_context(ctx);
785 return status;
786 }
787 spin_unlock(&state->inode->i_lock);
788 return -ENOENT;
789}
790
791/*
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100792 * Returns a referenced nfs4_state if there is an open delegation on the file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 */
794static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res)
795{
796 struct nfs_delegation *delegation;
797 struct nfs_server *server = NFS_SERVER(inode);
798 struct nfs4_client *clp = server->nfs4_state;
799 struct nfs_inode *nfsi = NFS_I(inode);
800 struct nfs4_state_owner *sp = NULL;
801 struct nfs4_state *state = NULL;
802 int open_flags = flags & (FMODE_READ|FMODE_WRITE);
803 int err;
804
805 /* Protect against reboot recovery - NOTE ORDER! */
806 down_read(&clp->cl_sem);
807 /* Protect against delegation recall */
808 down_read(&nfsi->rwsem);
809 delegation = NFS_I(inode)->delegation;
810 err = -ENOENT;
811 if (delegation == NULL || (delegation->type & open_flags) != open_flags)
812 goto out_err;
813 err = -ENOMEM;
814 if (!(sp = nfs4_get_state_owner(server, cred))) {
815 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
816 goto out_err;
817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 state = nfs4_get_open_state(inode, sp);
819 if (state == NULL)
820 goto out_err;
821
822 err = -ENOENT;
823 if ((state->state & open_flags) == open_flags) {
824 spin_lock(&inode->i_lock);
825 if (open_flags & FMODE_READ)
826 state->nreaders++;
827 if (open_flags & FMODE_WRITE)
828 state->nwriters++;
829 spin_unlock(&inode->i_lock);
830 goto out_ok;
831 } else if (state->state != 0)
832 goto out_err;
833
834 lock_kernel();
835 err = _nfs4_do_access(inode, cred, open_flags);
836 unlock_kernel();
837 if (err != 0)
838 goto out_err;
839 set_bit(NFS_DELEGATED_STATE, &state->flags);
840 update_open_stateid(state, &delegation->stateid, open_flags);
841out_ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 nfs4_put_state_owner(sp);
843 up_read(&nfsi->rwsem);
844 up_read(&clp->cl_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 *res = state;
846 return 0;
847out_err:
848 if (sp != NULL) {
849 if (state != NULL)
850 nfs4_put_open_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 nfs4_put_state_owner(sp);
852 }
853 up_read(&nfsi->rwsem);
854 up_read(&clp->cl_sem);
Trond Myklebustb8e5c4c2005-10-18 14:20:20 -0700855 if (err != -EACCES)
856 nfs_inode_return_delegation(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 return err;
858}
859
860static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred)
861{
862 struct nfs4_exception exception = { };
863 struct nfs4_state *res;
864 int err;
865
866 do {
867 err = _nfs4_open_delegated(inode, flags, cred, &res);
868 if (err == 0)
869 break;
870 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode),
871 err, &exception));
872 } while (exception.retry);
873 return res;
874}
875
876/*
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100877 * Returns a referenced nfs4_state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 */
879static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
880{
881 struct nfs4_state_owner *sp;
882 struct nfs4_state *state = NULL;
883 struct nfs_server *server = NFS_SERVER(dir);
884 struct nfs4_client *clp = server->nfs4_state;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100885 struct nfs4_opendata *opendata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 /* Protect against reboot recovery conflicts */
889 down_read(&clp->cl_sem);
890 status = -ENOMEM;
891 if (!(sp = nfs4_get_state_owner(server, cred))) {
892 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
893 goto out_err;
894 }
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100895 opendata = nfs4_opendata_alloc(dentry, sp, flags, sattr);
896 if (opendata == NULL)
897 goto err_put_state_owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100899 status = _nfs4_proc_open(opendata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 if (status != 0)
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100901 goto err_opendata_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 status = -ENOMEM;
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100904 state = nfs4_opendata_to_nfs4_state(opendata);
905 if (state == NULL)
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100906 goto err_opendata_free;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100907 if (opendata->o_res.delegation_type != 0)
Trond Myklebust24ac23a2006-01-03 09:55:11 +0100908 nfs_inode_set_delegation(state->inode, cred, &opendata->o_res);
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100909 nfs4_opendata_free(opendata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 nfs4_put_state_owner(sp);
911 up_read(&clp->cl_sem);
912 *res = state;
913 return 0;
Trond Myklebuste56e0b782006-01-03 09:55:08 +0100914err_opendata_free:
915 nfs4_opendata_free(opendata);
916err_put_state_owner:
917 nfs4_put_state_owner(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918out_err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
920 up_read(&clp->cl_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 *res = NULL;
922 return status;
923}
924
925
926static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred)
927{
928 struct nfs4_exception exception = { };
929 struct nfs4_state *res;
930 int status;
931
932 do {
933 status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res);
934 if (status == 0)
935 break;
936 /* NOTE: BAD_SEQID means the server and client disagree about the
937 * book-keeping w.r.t. state-changing operations
938 * (OPEN/CLOSE/LOCK/LOCKU...)
939 * It is actually a sign of a bug on the client or on the server.
940 *
941 * If we receive a BAD_SEQID error in the particular case of
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700942 * doing an OPEN, we assume that nfs_increment_open_seqid() will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 * have unhashed the old state_owner for us, and that we can
944 * therefore safely retry using a new one. We should still warn
945 * the user though...
946 */
947 if (status == -NFS4ERR_BAD_SEQID) {
948 printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n");
949 exception.retry = 1;
950 continue;
951 }
Trond Myklebust550f5742005-10-18 14:20:21 -0700952 /*
953 * BAD_STATEID on OPEN means that the server cancelled our
954 * state before it received the OPEN_CONFIRM.
955 * Recover by retrying the request as per the discussion
956 * on Page 181 of RFC3530.
957 */
958 if (status == -NFS4ERR_BAD_STATEID) {
959 exception.retry = 1;
960 continue;
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
963 status, &exception));
964 } while (exception.retry);
965 return res;
966}
967
968static int _nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
969 struct nfs_fh *fhandle, struct iattr *sattr,
970 struct nfs4_state *state)
971{
972 struct nfs_setattrargs arg = {
973 .fh = fhandle,
974 .iap = sattr,
975 .server = server,
976 .bitmask = server->attr_bitmask,
977 };
978 struct nfs_setattrres res = {
979 .fattr = fattr,
980 .server = server,
981 };
982 struct rpc_message msg = {
983 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
984 .rpc_argp = &arg,
985 .rpc_resp = &res,
986 };
Trond Myklebust65e43082005-08-16 11:49:44 -0400987 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Trond Myklebust0e574af2005-10-27 22:12:38 -0400989 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Trond Myklebust08e9eac2005-06-22 17:16:29 +0000991 if (state != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 msg.rpc_cred = state->owner->so_cred;
Trond Myklebust08e9eac2005-06-22 17:16:29 +0000993 nfs4_copy_stateid(&arg.stateid, state, current->files);
994 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
996
Trond Myklebust65e43082005-08-16 11:49:44 -0400997 status = rpc_call_sync(server->client, &msg, 0);
998 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
1000
1001static int nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
1002 struct nfs_fh *fhandle, struct iattr *sattr,
1003 struct nfs4_state *state)
1004{
1005 struct nfs4_exception exception = { };
1006 int err;
1007 do {
1008 err = nfs4_handle_exception(server,
1009 _nfs4_do_setattr(server, fattr, fhandle, sattr,
1010 state),
1011 &exception);
1012 } while (exception.retry);
1013 return err;
1014}
1015
1016struct nfs4_closedata {
1017 struct inode *inode;
1018 struct nfs4_state *state;
1019 struct nfs_closeargs arg;
1020 struct nfs_closeres res;
Trond Myklebust516a6af2005-10-27 22:12:41 -04001021 struct nfs_fattr fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022};
1023
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001024static void nfs4_free_closedata(void *data)
Trond Myklebust95121352005-10-18 14:20:12 -07001025{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001026 struct nfs4_closedata *calldata = data;
1027 struct nfs4_state_owner *sp = calldata->state->owner;
Trond Myklebust95121352005-10-18 14:20:12 -07001028
1029 nfs4_put_open_state(calldata->state);
1030 nfs_free_seqid(calldata->arg.seqid);
Trond Myklebust95121352005-10-18 14:20:12 -07001031 nfs4_put_state_owner(sp);
Trond Myklebust95121352005-10-18 14:20:12 -07001032 kfree(calldata);
1033}
1034
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001035static void nfs4_close_done(struct rpc_task *task, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001037 struct nfs4_closedata *calldata = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 struct nfs4_state *state = calldata->state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 struct nfs_server *server = NFS_SERVER(calldata->inode);
1040
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01001041 if (RPC_ASSASSINATED(task))
1042 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 /* hmm. we are done with the inode, and in the process of freeing
1044 * the state_owner. we keep this around to process errors
1045 */
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001046 nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 switch (task->tk_status) {
1048 case 0:
1049 memcpy(&state->stateid, &calldata->res.stateid,
1050 sizeof(state->stateid));
1051 break;
1052 case -NFS4ERR_STALE_STATEID:
1053 case -NFS4ERR_EXPIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 nfs4_schedule_state_recovery(server->nfs4_state);
1055 break;
1056 default:
1057 if (nfs4_async_handle_error(task, server) == -EAGAIN) {
1058 rpc_restart_call(task);
1059 return;
1060 }
1061 }
Trond Myklebust516a6af2005-10-27 22:12:41 -04001062 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01001065static void nfs4_close_prepare(struct rpc_task *task, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01001067 struct nfs4_closedata *calldata = data;
Trond Myklebust95121352005-10-18 14:20:12 -07001068 struct nfs4_state *state = calldata->state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 struct rpc_message msg = {
1070 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
1071 .rpc_argp = &calldata->arg,
1072 .rpc_resp = &calldata->res,
Trond Myklebust95121352005-10-18 14:20:12 -07001073 .rpc_cred = state->owner->so_cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 };
Trond Myklebust4cecb762005-11-04 15:32:58 -05001075 int mode = 0, old_mode;
Trond Myklebust95121352005-10-18 14:20:12 -07001076
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001077 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
Trond Myklebust95121352005-10-18 14:20:12 -07001078 return;
Trond Myklebust95121352005-10-18 14:20:12 -07001079 /* Recalculate the new open mode in case someone reopened the file
1080 * while we were waiting in line to be scheduled.
1081 */
Trond Myklebust4cecb762005-11-04 15:32:58 -05001082 spin_lock(&state->owner->so_lock);
1083 spin_lock(&calldata->inode->i_lock);
1084 mode = old_mode = state->state;
1085 if (state->nreaders == 0)
1086 mode &= ~FMODE_READ;
1087 if (state->nwriters == 0)
1088 mode &= ~FMODE_WRITE;
1089 nfs4_state_set_mode_locked(state, mode);
1090 spin_unlock(&calldata->inode->i_lock);
1091 spin_unlock(&state->owner->so_lock);
1092 if (mode == old_mode || test_bit(NFS_DELEGATED_STATE, &state->flags)) {
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001093 /* Note: exit _without_ calling nfs4_close_done */
1094 task->tk_action = NULL;
Trond Myklebust95121352005-10-18 14:20:12 -07001095 return;
1096 }
Trond Myklebust516a6af2005-10-27 22:12:41 -04001097 nfs_fattr_init(calldata->res.fattr);
Trond Myklebust95121352005-10-18 14:20:12 -07001098 if (mode != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
Trond Myklebust95121352005-10-18 14:20:12 -07001100 calldata->arg.open_flags = mode;
1101 rpc_call_setup(task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001104static const struct rpc_call_ops nfs4_close_ops = {
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01001105 .rpc_call_prepare = nfs4_close_prepare,
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001106 .rpc_call_done = nfs4_close_done,
1107 .rpc_release = nfs4_free_closedata,
1108};
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110/*
1111 * It is possible for data to be read/written from a mem-mapped file
1112 * after the sys_close call (which hits the vfs layer as a flush).
1113 * This means that we can't safely call nfsv4 close on a file until
1114 * the inode is cleared. This in turn means that we are not good
1115 * NFSv4 citizens - we do not indicate to the server to update the file's
1116 * share state even when we are done with one of the three share
1117 * stateid's in the inode.
1118 *
1119 * NOTE: Caller must be holding the sp->so_owner semaphore!
1120 */
Trond Myklebust4cecb762005-11-04 15:32:58 -05001121int nfs4_do_close(struct inode *inode, struct nfs4_state *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Trond Myklebust516a6af2005-10-27 22:12:41 -04001123 struct nfs_server *server = NFS_SERVER(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 struct nfs4_closedata *calldata;
Trond Myklebust95121352005-10-18 14:20:12 -07001125 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Trond Myklebust95121352005-10-18 14:20:12 -07001127 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 if (calldata == NULL)
Trond Myklebust95121352005-10-18 14:20:12 -07001129 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 calldata->inode = inode;
1131 calldata->state = state;
1132 calldata->arg.fh = NFS_FH(inode);
Trond Myklebust95121352005-10-18 14:20:12 -07001133 calldata->arg.stateid = &state->stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 /* Serialization for the sequence id */
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001135 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
Trond Myklebust95121352005-10-18 14:20:12 -07001136 if (calldata->arg.seqid == NULL)
1137 goto out_free_calldata;
Trond Myklebust516a6af2005-10-27 22:12:41 -04001138 calldata->arg.bitmask = server->attr_bitmask;
1139 calldata->res.fattr = &calldata->fattr;
1140 calldata->res.server = server;
Trond Myklebust95121352005-10-18 14:20:12 -07001141
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01001142 status = nfs4_call_async(server->client, &nfs4_close_ops, calldata);
Trond Myklebust95121352005-10-18 14:20:12 -07001143 if (status == 0)
1144 goto out;
1145
1146 nfs_free_seqid(calldata->arg.seqid);
1147out_free_calldata:
1148 kfree(calldata);
1149out:
1150 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Trond Myklebust02a913a2005-10-18 14:20:17 -07001153static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state)
1154{
1155 struct file *filp;
1156
1157 filp = lookup_instantiate_filp(nd, dentry, NULL);
1158 if (!IS_ERR(filp)) {
1159 struct nfs_open_context *ctx;
1160 ctx = (struct nfs_open_context *)filp->private_data;
1161 ctx->state = state;
1162 } else
1163 nfs4_close_state(state, nd->intent.open.flags);
1164}
1165
1166struct dentry *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1168{
1169 struct iattr attr;
1170 struct rpc_cred *cred;
1171 struct nfs4_state *state;
Trond Myklebust02a913a2005-10-18 14:20:17 -07001172 struct dentry *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 if (nd->flags & LOOKUP_CREATE) {
1175 attr.ia_mode = nd->intent.open.create_mode;
1176 attr.ia_valid = ATTR_MODE;
1177 if (!IS_POSIXACL(dir))
1178 attr.ia_mode &= ~current->fs->umask;
1179 } else {
1180 attr.ia_valid = 0;
1181 BUG_ON(nd->intent.open.flags & O_CREAT);
1182 }
1183
1184 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1185 if (IS_ERR(cred))
Trond Myklebust02a913a2005-10-18 14:20:17 -07001186 return (struct dentry *)cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
1188 put_rpccred(cred);
Trond Myklebust02a913a2005-10-18 14:20:17 -07001189 if (IS_ERR(state)) {
1190 if (PTR_ERR(state) == -ENOENT)
1191 d_add(dentry, NULL);
1192 return (struct dentry *)state;
1193 }
Trond Myklebust24ac23a2006-01-03 09:55:11 +01001194 res = d_add_unique(dentry, igrab(state->inode));
Trond Myklebust02a913a2005-10-18 14:20:17 -07001195 if (res != NULL)
1196 dentry = res;
1197 nfs4_intent_set_file(nd, dentry, state);
1198 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
1201int
Trond Myklebust02a913a2005-10-18 14:20:17 -07001202nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
1204 struct rpc_cred *cred;
1205 struct nfs4_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1208 if (IS_ERR(cred))
1209 return PTR_ERR(cred);
1210 state = nfs4_open_delegated(dentry->d_inode, openflags, cred);
1211 if (IS_ERR(state))
1212 state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
1213 put_rpccred(cred);
Trond Myklebust02a913a2005-10-18 14:20:17 -07001214 if (IS_ERR(state)) {
1215 switch (PTR_ERR(state)) {
1216 case -EPERM:
1217 case -EACCES:
1218 case -EDQUOT:
1219 case -ENOSPC:
1220 case -EROFS:
1221 lookup_instantiate_filp(nd, (struct dentry *)state, NULL);
1222 return 1;
1223 case -ENOENT:
1224 if (dentry->d_inode == NULL)
1225 return 1;
1226 }
1227 goto out_drop;
1228 }
Trond Myklebust24ac23a2006-01-03 09:55:11 +01001229 if (state->inode == dentry->d_inode) {
Trond Myklebust02a913a2005-10-18 14:20:17 -07001230 nfs4_intent_set_file(nd, dentry, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 return 1;
1232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 nfs4_close_state(state, openflags);
Trond Myklebust02a913a2005-10-18 14:20:17 -07001234out_drop:
1235 d_drop(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 return 0;
1237}
1238
1239
1240static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1241{
1242 struct nfs4_server_caps_res res = {};
1243 struct rpc_message msg = {
1244 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
1245 .rpc_argp = fhandle,
1246 .rpc_resp = &res,
1247 };
1248 int status;
1249
1250 status = rpc_call_sync(server->client, &msg, 0);
1251 if (status == 0) {
1252 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
1253 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
1254 server->caps |= NFS_CAP_ACLS;
1255 if (res.has_links != 0)
1256 server->caps |= NFS_CAP_HARDLINKS;
1257 if (res.has_symlinks != 0)
1258 server->caps |= NFS_CAP_SYMLINKS;
1259 server->acl_bitmask = res.acl_bitmask;
1260 }
1261 return status;
1262}
1263
1264static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1265{
1266 struct nfs4_exception exception = { };
1267 int err;
1268 do {
1269 err = nfs4_handle_exception(server,
1270 _nfs4_server_capabilities(server, fhandle),
1271 &exception);
1272 } while (exception.retry);
1273 return err;
1274}
1275
1276static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1277 struct nfs_fsinfo *info)
1278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 struct nfs4_lookup_root_arg args = {
1280 .bitmask = nfs4_fattr_bitmap,
1281 };
1282 struct nfs4_lookup_res res = {
1283 .server = server,
Trond Myklebust0e574af2005-10-27 22:12:38 -04001284 .fattr = info->fattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 .fh = fhandle,
1286 };
1287 struct rpc_message msg = {
1288 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
1289 .rpc_argp = &args,
1290 .rpc_resp = &res,
1291 };
Trond Myklebust0e574af2005-10-27 22:12:38 -04001292 nfs_fattr_init(info->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 return rpc_call_sync(server->client, &msg, 0);
1294}
1295
1296static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1297 struct nfs_fsinfo *info)
1298{
1299 struct nfs4_exception exception = { };
1300 int err;
1301 do {
1302 err = nfs4_handle_exception(server,
1303 _nfs4_lookup_root(server, fhandle, info),
1304 &exception);
1305 } while (exception.retry);
1306 return err;
1307}
1308
1309static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
1310 struct nfs_fsinfo *info)
1311{
1312 struct nfs_fattr * fattr = info->fattr;
1313 unsigned char * p;
1314 struct qstr q;
1315 struct nfs4_lookup_arg args = {
1316 .dir_fh = fhandle,
1317 .name = &q,
1318 .bitmask = nfs4_fattr_bitmap,
1319 };
1320 struct nfs4_lookup_res res = {
1321 .server = server,
1322 .fattr = fattr,
1323 .fh = fhandle,
1324 };
1325 struct rpc_message msg = {
1326 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1327 .rpc_argp = &args,
1328 .rpc_resp = &res,
1329 };
1330 int status;
1331
1332 /*
1333 * Now we do a separate LOOKUP for each component of the mount path.
1334 * The LOOKUPs are done separately so that we can conveniently
1335 * catch an ERR_WRONGSEC if it occurs along the way...
1336 */
1337 status = nfs4_lookup_root(server, fhandle, info);
1338 if (status)
1339 goto out;
1340
1341 p = server->mnt_path;
1342 for (;;) {
1343 struct nfs4_exception exception = { };
1344
1345 while (*p == '/')
1346 p++;
1347 if (!*p)
1348 break;
1349 q.name = p;
1350 while (*p && (*p != '/'))
1351 p++;
1352 q.len = p - q.name;
1353
1354 do {
Trond Myklebust0e574af2005-10-27 22:12:38 -04001355 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 status = nfs4_handle_exception(server,
1357 rpc_call_sync(server->client, &msg, 0),
1358 &exception);
1359 } while (exception.retry);
1360 if (status == 0)
1361 continue;
1362 if (status == -ENOENT) {
1363 printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path);
1364 printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n");
1365 }
1366 break;
1367 }
1368 if (status == 0)
1369 status = nfs4_server_capabilities(server, fhandle);
1370 if (status == 0)
1371 status = nfs4_do_fsinfo(server, fhandle, info);
1372out:
1373 return status;
1374}
1375
1376static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1377{
1378 struct nfs4_getattr_arg args = {
1379 .fh = fhandle,
1380 .bitmask = server->attr_bitmask,
1381 };
1382 struct nfs4_getattr_res res = {
1383 .fattr = fattr,
1384 .server = server,
1385 };
1386 struct rpc_message msg = {
1387 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
1388 .rpc_argp = &args,
1389 .rpc_resp = &res,
1390 };
1391
Trond Myklebust0e574af2005-10-27 22:12:38 -04001392 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 return rpc_call_sync(server->client, &msg, 0);
1394}
1395
1396static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1397{
1398 struct nfs4_exception exception = { };
1399 int err;
1400 do {
1401 err = nfs4_handle_exception(server,
1402 _nfs4_proc_getattr(server, fhandle, fattr),
1403 &exception);
1404 } while (exception.retry);
1405 return err;
1406}
1407
1408/*
1409 * The file is not closed if it is opened due to the a request to change
1410 * the size of the file. The open call will not be needed once the
1411 * VFS layer lookup-intents are implemented.
1412 *
1413 * Close is called when the inode is destroyed.
1414 * If we haven't opened the file for O_WRONLY, we
1415 * need to in the size_change case to obtain a stateid.
1416 *
1417 * Got race?
1418 * Because OPEN is always done by name in nfsv4, it is
1419 * possible that we opened a different file by the same
1420 * name. We can recognize this race condition, but we
1421 * can't do anything about it besides returning an error.
1422 *
1423 * This will be fixed with VFS changes (lookup-intent).
1424 */
1425static int
1426nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1427 struct iattr *sattr)
1428{
Trond Myklebust08e9eac2005-06-22 17:16:29 +00001429 struct rpc_cred *cred;
1430 struct inode *inode = dentry->d_inode;
Trond Myklebustd5308382005-11-04 15:33:38 -05001431 struct nfs_open_context *ctx;
1432 struct nfs4_state *state = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 int status;
1434
Trond Myklebust0e574af2005-10-27 22:12:38 -04001435 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Trond Myklebust08e9eac2005-06-22 17:16:29 +00001437 cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
1438 if (IS_ERR(cred))
1439 return PTR_ERR(cred);
Trond Myklebustd5308382005-11-04 15:33:38 -05001440
1441 /* Search for an existing open(O_WRITE) file */
1442 ctx = nfs_find_open_context(inode, cred, FMODE_WRITE);
1443 if (ctx != NULL)
1444 state = ctx->state;
Trond Myklebust08e9eac2005-06-22 17:16:29 +00001445
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 status = nfs4_do_setattr(NFS_SERVER(inode), fattr,
1447 NFS_FH(inode), sattr, state);
Trond Myklebust65e43082005-08-16 11:49:44 -04001448 if (status == 0)
1449 nfs_setattr_update_inode(inode, sattr);
Trond Myklebustd5308382005-11-04 15:33:38 -05001450 if (ctx != NULL)
1451 put_nfs_open_context(ctx);
Trond Myklebust08e9eac2005-06-22 17:16:29 +00001452 put_rpccred(cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 return status;
1454}
1455
1456static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,
1457 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1458{
1459 int status;
1460 struct nfs_server *server = NFS_SERVER(dir);
1461 struct nfs4_lookup_arg args = {
1462 .bitmask = server->attr_bitmask,
1463 .dir_fh = NFS_FH(dir),
1464 .name = name,
1465 };
1466 struct nfs4_lookup_res res = {
1467 .server = server,
1468 .fattr = fattr,
1469 .fh = fhandle,
1470 };
1471 struct rpc_message msg = {
1472 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1473 .rpc_argp = &args,
1474 .rpc_resp = &res,
1475 };
1476
Trond Myklebust0e574af2005-10-27 22:12:38 -04001477 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
1479 dprintk("NFS call lookup %s\n", name->name);
1480 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1481 dprintk("NFS reply lookup: %d\n", status);
1482 return status;
1483}
1484
1485static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1486{
1487 struct nfs4_exception exception = { };
1488 int err;
1489 do {
1490 err = nfs4_handle_exception(NFS_SERVER(dir),
1491 _nfs4_proc_lookup(dir, name, fhandle, fattr),
1492 &exception);
1493 } while (exception.retry);
1494 return err;
1495}
1496
1497static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1498{
1499 struct nfs4_accessargs args = {
1500 .fh = NFS_FH(inode),
1501 };
1502 struct nfs4_accessres res = { 0 };
1503 struct rpc_message msg = {
1504 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
1505 .rpc_argp = &args,
1506 .rpc_resp = &res,
1507 .rpc_cred = entry->cred,
1508 };
1509 int mode = entry->mask;
1510 int status;
1511
1512 /*
1513 * Determine which access bits we want to ask for...
1514 */
1515 if (mode & MAY_READ)
1516 args.access |= NFS4_ACCESS_READ;
1517 if (S_ISDIR(inode->i_mode)) {
1518 if (mode & MAY_WRITE)
1519 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
1520 if (mode & MAY_EXEC)
1521 args.access |= NFS4_ACCESS_LOOKUP;
1522 } else {
1523 if (mode & MAY_WRITE)
1524 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
1525 if (mode & MAY_EXEC)
1526 args.access |= NFS4_ACCESS_EXECUTE;
1527 }
1528 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1529 if (!status) {
1530 entry->mask = 0;
1531 if (res.access & NFS4_ACCESS_READ)
1532 entry->mask |= MAY_READ;
1533 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
1534 entry->mask |= MAY_WRITE;
1535 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
1536 entry->mask |= MAY_EXEC;
1537 }
1538 return status;
1539}
1540
1541static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1542{
1543 struct nfs4_exception exception = { };
1544 int err;
1545 do {
1546 err = nfs4_handle_exception(NFS_SERVER(inode),
1547 _nfs4_proc_access(inode, entry),
1548 &exception);
1549 } while (exception.retry);
1550 return err;
1551}
1552
1553/*
1554 * TODO: For the time being, we don't try to get any attributes
1555 * along with any of the zero-copy operations READ, READDIR,
1556 * READLINK, WRITE.
1557 *
1558 * In the case of the first three, we want to put the GETATTR
1559 * after the read-type operation -- this is because it is hard
1560 * to predict the length of a GETATTR response in v4, and thus
1561 * align the READ data correctly. This means that the GETATTR
1562 * may end up partially falling into the page cache, and we should
1563 * shift it into the 'tail' of the xdr_buf before processing.
1564 * To do this efficiently, we need to know the total length
1565 * of data received, which doesn't seem to be available outside
1566 * of the RPC layer.
1567 *
1568 * In the case of WRITE, we also want to put the GETATTR after
1569 * the operation -- in this case because we want to make sure
1570 * we get the post-operation mtime and size. This means that
1571 * we can't use xdr_encode_pages() as written: we need a variant
1572 * of it which would leave room in the 'tail' iovec.
1573 *
1574 * Both of these changes to the XDR layer would in fact be quite
1575 * minor, but I decided to leave them for a subsequent patch.
1576 */
1577static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
1578 unsigned int pgbase, unsigned int pglen)
1579{
1580 struct nfs4_readlink args = {
1581 .fh = NFS_FH(inode),
1582 .pgbase = pgbase,
1583 .pglen = pglen,
1584 .pages = &page,
1585 };
1586 struct rpc_message msg = {
1587 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
1588 .rpc_argp = &args,
1589 .rpc_resp = NULL,
1590 };
1591
1592 return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1593}
1594
1595static int nfs4_proc_readlink(struct inode *inode, struct page *page,
1596 unsigned int pgbase, unsigned int pglen)
1597{
1598 struct nfs4_exception exception = { };
1599 int err;
1600 do {
1601 err = nfs4_handle_exception(NFS_SERVER(inode),
1602 _nfs4_proc_readlink(inode, page, pgbase, pglen),
1603 &exception);
1604 } while (exception.retry);
1605 return err;
1606}
1607
1608static int _nfs4_proc_read(struct nfs_read_data *rdata)
1609{
1610 int flags = rdata->flags;
1611 struct inode *inode = rdata->inode;
1612 struct nfs_fattr *fattr = rdata->res.fattr;
1613 struct nfs_server *server = NFS_SERVER(inode);
1614 struct rpc_message msg = {
1615 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
1616 .rpc_argp = &rdata->args,
1617 .rpc_resp = &rdata->res,
1618 .rpc_cred = rdata->cred,
1619 };
1620 unsigned long timestamp = jiffies;
1621 int status;
1622
1623 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
1624 (long long) rdata->args.offset);
1625
Trond Myklebust0e574af2005-10-27 22:12:38 -04001626 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 status = rpc_call_sync(server->client, &msg, flags);
1628 if (!status)
1629 renew_lease(server, timestamp);
1630 dprintk("NFS reply read: %d\n", status);
1631 return status;
1632}
1633
1634static int nfs4_proc_read(struct nfs_read_data *rdata)
1635{
1636 struct nfs4_exception exception = { };
1637 int err;
1638 do {
1639 err = nfs4_handle_exception(NFS_SERVER(rdata->inode),
1640 _nfs4_proc_read(rdata),
1641 &exception);
1642 } while (exception.retry);
1643 return err;
1644}
1645
1646static int _nfs4_proc_write(struct nfs_write_data *wdata)
1647{
1648 int rpcflags = wdata->flags;
1649 struct inode *inode = wdata->inode;
1650 struct nfs_fattr *fattr = wdata->res.fattr;
1651 struct nfs_server *server = NFS_SERVER(inode);
1652 struct rpc_message msg = {
1653 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
1654 .rpc_argp = &wdata->args,
1655 .rpc_resp = &wdata->res,
1656 .rpc_cred = wdata->cred,
1657 };
1658 int status;
1659
1660 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
1661 (long long) wdata->args.offset);
1662
Trond Myklebust3b6efee2005-12-03 15:20:21 -05001663 wdata->args.bitmask = server->attr_bitmask;
1664 wdata->res.server = server;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001665 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 status = rpc_call_sync(server->client, &msg, rpcflags);
1667 dprintk("NFS reply write: %d\n", status);
Trond Myklebust3b6efee2005-12-03 15:20:21 -05001668 if (status < 0)
1669 return status;
1670 nfs_post_op_update_inode(inode, fattr);
1671 return wdata->res.count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
1674static int nfs4_proc_write(struct nfs_write_data *wdata)
1675{
1676 struct nfs4_exception exception = { };
1677 int err;
1678 do {
1679 err = nfs4_handle_exception(NFS_SERVER(wdata->inode),
1680 _nfs4_proc_write(wdata),
1681 &exception);
1682 } while (exception.retry);
1683 return err;
1684}
1685
1686static int _nfs4_proc_commit(struct nfs_write_data *cdata)
1687{
1688 struct inode *inode = cdata->inode;
1689 struct nfs_fattr *fattr = cdata->res.fattr;
1690 struct nfs_server *server = NFS_SERVER(inode);
1691 struct rpc_message msg = {
1692 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
1693 .rpc_argp = &cdata->args,
1694 .rpc_resp = &cdata->res,
1695 .rpc_cred = cdata->cred,
1696 };
1697 int status;
1698
1699 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
1700 (long long) cdata->args.offset);
1701
Trond Myklebust3b6efee2005-12-03 15:20:21 -05001702 cdata->args.bitmask = server->attr_bitmask;
1703 cdata->res.server = server;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001704 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 status = rpc_call_sync(server->client, &msg, 0);
1706 dprintk("NFS reply commit: %d\n", status);
Trond Myklebust3b6efee2005-12-03 15:20:21 -05001707 if (status >= 0)
1708 nfs_post_op_update_inode(inode, fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 return status;
1710}
1711
1712static int nfs4_proc_commit(struct nfs_write_data *cdata)
1713{
1714 struct nfs4_exception exception = { };
1715 int err;
1716 do {
1717 err = nfs4_handle_exception(NFS_SERVER(cdata->inode),
1718 _nfs4_proc_commit(cdata),
1719 &exception);
1720 } while (exception.retry);
1721 return err;
1722}
1723
1724/*
1725 * Got race?
1726 * We will need to arrange for the VFS layer to provide an atomic open.
1727 * Until then, this create/open method is prone to inefficiency and race
1728 * conditions due to the lookup, create, and open VFS calls from sys_open()
1729 * placed on the wire.
1730 *
1731 * Given the above sorry state of affairs, I'm simply sending an OPEN.
1732 * The file will be opened again in the subsequent VFS open call
1733 * (nfs4_proc_file_open).
1734 *
1735 * The open for read will just hang around to be used by any process that
1736 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1737 */
1738
1739static int
1740nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Trond Myklebust02a913a2005-10-18 14:20:17 -07001741 int flags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742{
1743 struct nfs4_state *state;
1744 struct rpc_cred *cred;
1745 int status = 0;
1746
1747 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1748 if (IS_ERR(cred)) {
1749 status = PTR_ERR(cred);
1750 goto out;
1751 }
1752 state = nfs4_do_open(dir, dentry, flags, sattr, cred);
1753 put_rpccred(cred);
1754 if (IS_ERR(state)) {
1755 status = PTR_ERR(state);
1756 goto out;
1757 }
Trond Myklebust24ac23a2006-01-03 09:55:11 +01001758 d_instantiate(dentry, igrab(state->inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 if (flags & O_EXCL) {
1760 struct nfs_fattr fattr;
1761 status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,
1762 NFS_FH(state->inode), sattr, state);
Trond Myklebust02a913a2005-10-18 14:20:17 -07001763 if (status == 0)
Trond Myklebust65e43082005-08-16 11:49:44 -04001764 nfs_setattr_update_inode(state->inode, sattr);
Trond Myklebust02a913a2005-10-18 14:20:17 -07001765 }
1766 if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN))
1767 nfs4_intent_set_file(nd, dentry, state);
1768 else
1769 nfs4_close_state(state, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770out:
1771 return status;
1772}
1773
1774static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
1775{
Trond Myklebust16e42952005-10-27 22:12:44 -04001776 struct nfs_server *server = NFS_SERVER(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 struct nfs4_remove_arg args = {
1778 .fh = NFS_FH(dir),
1779 .name = name,
Trond Myklebust16e42952005-10-27 22:12:44 -04001780 .bitmask = server->attr_bitmask,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 };
Trond Myklebust16e42952005-10-27 22:12:44 -04001782 struct nfs_fattr dir_attr;
1783 struct nfs4_remove_res res = {
1784 .server = server,
1785 .dir_attr = &dir_attr,
1786 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 struct rpc_message msg = {
1788 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
1789 .rpc_argp = &args,
1790 .rpc_resp = &res,
1791 };
1792 int status;
1793
Trond Myklebust16e42952005-10-27 22:12:44 -04001794 nfs_fattr_init(res.dir_attr);
1795 status = rpc_call_sync(server->client, &msg, 0);
1796 if (status == 0) {
1797 update_changeattr(dir, &res.cinfo);
1798 nfs_post_op_update_inode(dir, res.dir_attr);
1799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 return status;
1801}
1802
1803static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
1804{
1805 struct nfs4_exception exception = { };
1806 int err;
1807 do {
1808 err = nfs4_handle_exception(NFS_SERVER(dir),
1809 _nfs4_proc_remove(dir, name),
1810 &exception);
1811 } while (exception.retry);
1812 return err;
1813}
1814
1815struct unlink_desc {
1816 struct nfs4_remove_arg args;
Trond Myklebust16e42952005-10-27 22:12:44 -04001817 struct nfs4_remove_res res;
1818 struct nfs_fattr dir_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819};
1820
1821static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir,
1822 struct qstr *name)
1823{
Trond Myklebust16e42952005-10-27 22:12:44 -04001824 struct nfs_server *server = NFS_SERVER(dir->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 struct unlink_desc *up;
1826
1827 up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL);
1828 if (!up)
1829 return -ENOMEM;
1830
1831 up->args.fh = NFS_FH(dir->d_inode);
1832 up->args.name = name;
Trond Myklebust16e42952005-10-27 22:12:44 -04001833 up->args.bitmask = server->attr_bitmask;
1834 up->res.server = server;
1835 up->res.dir_attr = &up->dir_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
1837 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
1838 msg->rpc_argp = &up->args;
1839 msg->rpc_resp = &up->res;
1840 return 0;
1841}
1842
1843static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
1844{
1845 struct rpc_message *msg = &task->tk_msg;
1846 struct unlink_desc *up;
1847
1848 if (msg->rpc_resp != NULL) {
1849 up = container_of(msg->rpc_resp, struct unlink_desc, res);
Trond Myklebust16e42952005-10-27 22:12:44 -04001850 update_changeattr(dir->d_inode, &up->res.cinfo);
1851 nfs_post_op_update_inode(dir->d_inode, up->res.dir_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 kfree(up);
1853 msg->rpc_resp = NULL;
1854 msg->rpc_argp = NULL;
1855 }
1856 return 0;
1857}
1858
1859static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1860 struct inode *new_dir, struct qstr *new_name)
1861{
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001862 struct nfs_server *server = NFS_SERVER(old_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 struct nfs4_rename_arg arg = {
1864 .old_dir = NFS_FH(old_dir),
1865 .new_dir = NFS_FH(new_dir),
1866 .old_name = old_name,
1867 .new_name = new_name,
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001868 .bitmask = server->attr_bitmask,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 };
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001870 struct nfs_fattr old_fattr, new_fattr;
1871 struct nfs4_rename_res res = {
1872 .server = server,
1873 .old_fattr = &old_fattr,
1874 .new_fattr = &new_fattr,
1875 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 struct rpc_message msg = {
1877 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
1878 .rpc_argp = &arg,
1879 .rpc_resp = &res,
1880 };
1881 int status;
1882
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001883 nfs_fattr_init(res.old_fattr);
1884 nfs_fattr_init(res.new_fattr);
1885 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887 if (!status) {
1888 update_changeattr(old_dir, &res.old_cinfo);
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001889 nfs_post_op_update_inode(old_dir, res.old_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 update_changeattr(new_dir, &res.new_cinfo);
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001891 nfs_post_op_update_inode(new_dir, res.new_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 }
1893 return status;
1894}
1895
1896static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1897 struct inode *new_dir, struct qstr *new_name)
1898{
1899 struct nfs4_exception exception = { };
1900 int err;
1901 do {
1902 err = nfs4_handle_exception(NFS_SERVER(old_dir),
1903 _nfs4_proc_rename(old_dir, old_name,
1904 new_dir, new_name),
1905 &exception);
1906 } while (exception.retry);
1907 return err;
1908}
1909
1910static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1911{
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001912 struct nfs_server *server = NFS_SERVER(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 struct nfs4_link_arg arg = {
1914 .fh = NFS_FH(inode),
1915 .dir_fh = NFS_FH(dir),
1916 .name = name,
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001917 .bitmask = server->attr_bitmask,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 };
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001919 struct nfs_fattr fattr, dir_attr;
1920 struct nfs4_link_res res = {
1921 .server = server,
1922 .fattr = &fattr,
1923 .dir_attr = &dir_attr,
1924 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 struct rpc_message msg = {
1926 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
1927 .rpc_argp = &arg,
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001928 .rpc_resp = &res,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 };
1930 int status;
1931
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001932 nfs_fattr_init(res.fattr);
1933 nfs_fattr_init(res.dir_attr);
1934 status = rpc_call_sync(server->client, &msg, 0);
1935 if (!status) {
1936 update_changeattr(dir, &res.cinfo);
1937 nfs_post_op_update_inode(dir, res.dir_attr);
1938 nfs_refresh_inode(inode, res.fattr);
1939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
1941 return status;
1942}
1943
1944static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1945{
1946 struct nfs4_exception exception = { };
1947 int err;
1948 do {
1949 err = nfs4_handle_exception(NFS_SERVER(inode),
1950 _nfs4_proc_link(inode, dir, name),
1951 &exception);
1952 } while (exception.retry);
1953 return err;
1954}
1955
1956static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1957 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1958 struct nfs_fattr *fattr)
1959{
1960 struct nfs_server *server = NFS_SERVER(dir);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001961 struct nfs_fattr dir_fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 struct nfs4_create_arg arg = {
1963 .dir_fh = NFS_FH(dir),
1964 .server = server,
1965 .name = name,
1966 .attrs = sattr,
1967 .ftype = NF4LNK,
1968 .bitmask = server->attr_bitmask,
1969 };
1970 struct nfs4_create_res res = {
1971 .server = server,
1972 .fh = fhandle,
1973 .fattr = fattr,
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001974 .dir_fattr = &dir_fattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 };
1976 struct rpc_message msg = {
1977 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK],
1978 .rpc_argp = &arg,
1979 .rpc_resp = &res,
1980 };
1981 int status;
1982
1983 if (path->len > NFS4_MAXPATHLEN)
1984 return -ENAMETOOLONG;
1985 arg.u.symlink = path;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001986 nfs_fattr_init(fattr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001987 nfs_fattr_init(&dir_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1990 if (!status)
1991 update_changeattr(dir, &res.dir_cinfo);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001992 nfs_post_op_update_inode(dir, res.dir_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 return status;
1994}
1995
1996static int nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1997 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1998 struct nfs_fattr *fattr)
1999{
2000 struct nfs4_exception exception = { };
2001 int err;
2002 do {
2003 err = nfs4_handle_exception(NFS_SERVER(dir),
2004 _nfs4_proc_symlink(dir, name, path, sattr,
2005 fhandle, fattr),
2006 &exception);
2007 } while (exception.retry);
2008 return err;
2009}
2010
2011static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2012 struct iattr *sattr)
2013{
2014 struct nfs_server *server = NFS_SERVER(dir);
2015 struct nfs_fh fhandle;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002016 struct nfs_fattr fattr, dir_fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 struct nfs4_create_arg arg = {
2018 .dir_fh = NFS_FH(dir),
2019 .server = server,
2020 .name = &dentry->d_name,
2021 .attrs = sattr,
2022 .ftype = NF4DIR,
2023 .bitmask = server->attr_bitmask,
2024 };
2025 struct nfs4_create_res res = {
2026 .server = server,
2027 .fh = &fhandle,
2028 .fattr = &fattr,
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002029 .dir_fattr = &dir_fattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 };
2031 struct rpc_message msg = {
2032 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
2033 .rpc_argp = &arg,
2034 .rpc_resp = &res,
2035 };
2036 int status;
2037
Trond Myklebust0e574af2005-10-27 22:12:38 -04002038 nfs_fattr_init(&fattr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002039 nfs_fattr_init(&dir_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
2042 if (!status) {
2043 update_changeattr(dir, &res.dir_cinfo);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002044 nfs_post_op_update_inode(dir, res.dir_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 status = nfs_instantiate(dentry, &fhandle, &fattr);
2046 }
2047 return status;
2048}
2049
2050static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2051 struct iattr *sattr)
2052{
2053 struct nfs4_exception exception = { };
2054 int err;
2055 do {
2056 err = nfs4_handle_exception(NFS_SERVER(dir),
2057 _nfs4_proc_mkdir(dir, dentry, sattr),
2058 &exception);
2059 } while (exception.retry);
2060 return err;
2061}
2062
2063static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2064 u64 cookie, struct page *page, unsigned int count, int plus)
2065{
2066 struct inode *dir = dentry->d_inode;
2067 struct nfs4_readdir_arg args = {
2068 .fh = NFS_FH(dir),
2069 .pages = &page,
2070 .pgbase = 0,
2071 .count = count,
2072 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2073 };
2074 struct nfs4_readdir_res res;
2075 struct rpc_message msg = {
2076 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
2077 .rpc_argp = &args,
2078 .rpc_resp = &res,
2079 .rpc_cred = cred,
2080 };
2081 int status;
2082
Trond Myklebusteadf4592005-06-22 17:16:39 +00002083 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__,
2084 dentry->d_parent->d_name.name,
2085 dentry->d_name.name,
2086 (unsigned long long)cookie);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 lock_kernel();
2088 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2089 res.pgbase = args.pgbase;
2090 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
2091 if (status == 0)
2092 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2093 unlock_kernel();
Trond Myklebusteadf4592005-06-22 17:16:39 +00002094 dprintk("%s: returns %d\n", __FUNCTION__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 return status;
2096}
2097
2098static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2099 u64 cookie, struct page *page, unsigned int count, int plus)
2100{
2101 struct nfs4_exception exception = { };
2102 int err;
2103 do {
2104 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2105 _nfs4_proc_readdir(dentry, cred, cookie,
2106 page, count, plus),
2107 &exception);
2108 } while (exception.retry);
2109 return err;
2110}
2111
2112static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2113 struct iattr *sattr, dev_t rdev)
2114{
2115 struct nfs_server *server = NFS_SERVER(dir);
2116 struct nfs_fh fh;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002117 struct nfs_fattr fattr, dir_fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct nfs4_create_arg arg = {
2119 .dir_fh = NFS_FH(dir),
2120 .server = server,
2121 .name = &dentry->d_name,
2122 .attrs = sattr,
2123 .bitmask = server->attr_bitmask,
2124 };
2125 struct nfs4_create_res res = {
2126 .server = server,
2127 .fh = &fh,
2128 .fattr = &fattr,
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002129 .dir_fattr = &dir_fattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 };
2131 struct rpc_message msg = {
2132 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
2133 .rpc_argp = &arg,
2134 .rpc_resp = &res,
2135 };
2136 int status;
2137 int mode = sattr->ia_mode;
2138
Trond Myklebust0e574af2005-10-27 22:12:38 -04002139 nfs_fattr_init(&fattr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002140 nfs_fattr_init(&dir_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2143 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
2144 if (S_ISFIFO(mode))
2145 arg.ftype = NF4FIFO;
2146 else if (S_ISBLK(mode)) {
2147 arg.ftype = NF4BLK;
2148 arg.u.device.specdata1 = MAJOR(rdev);
2149 arg.u.device.specdata2 = MINOR(rdev);
2150 }
2151 else if (S_ISCHR(mode)) {
2152 arg.ftype = NF4CHR;
2153 arg.u.device.specdata1 = MAJOR(rdev);
2154 arg.u.device.specdata2 = MINOR(rdev);
2155 }
2156 else
2157 arg.ftype = NF4SOCK;
2158
2159 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
2160 if (status == 0) {
2161 update_changeattr(dir, &res.dir_cinfo);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04002162 nfs_post_op_update_inode(dir, res.dir_fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 status = nfs_instantiate(dentry, &fh, &fattr);
2164 }
2165 return status;
2166}
2167
2168static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2169 struct iattr *sattr, dev_t rdev)
2170{
2171 struct nfs4_exception exception = { };
2172 int err;
2173 do {
2174 err = nfs4_handle_exception(NFS_SERVER(dir),
2175 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
2176 &exception);
2177 } while (exception.retry);
2178 return err;
2179}
2180
2181static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
2182 struct nfs_fsstat *fsstat)
2183{
2184 struct nfs4_statfs_arg args = {
2185 .fh = fhandle,
2186 .bitmask = server->attr_bitmask,
2187 };
2188 struct rpc_message msg = {
2189 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
2190 .rpc_argp = &args,
2191 .rpc_resp = fsstat,
2192 };
2193
Trond Myklebust0e574af2005-10-27 22:12:38 -04002194 nfs_fattr_init(fsstat->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 return rpc_call_sync(server->client, &msg, 0);
2196}
2197
2198static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
2199{
2200 struct nfs4_exception exception = { };
2201 int err;
2202 do {
2203 err = nfs4_handle_exception(server,
2204 _nfs4_proc_statfs(server, fhandle, fsstat),
2205 &exception);
2206 } while (exception.retry);
2207 return err;
2208}
2209
2210static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
2211 struct nfs_fsinfo *fsinfo)
2212{
2213 struct nfs4_fsinfo_arg args = {
2214 .fh = fhandle,
2215 .bitmask = server->attr_bitmask,
2216 };
2217 struct rpc_message msg = {
2218 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
2219 .rpc_argp = &args,
2220 .rpc_resp = fsinfo,
2221 };
2222
2223 return rpc_call_sync(server->client, &msg, 0);
2224}
2225
2226static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
2227{
2228 struct nfs4_exception exception = { };
2229 int err;
2230
2231 do {
2232 err = nfs4_handle_exception(server,
2233 _nfs4_do_fsinfo(server, fhandle, fsinfo),
2234 &exception);
2235 } while (exception.retry);
2236 return err;
2237}
2238
2239static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
2240{
Trond Myklebust0e574af2005-10-27 22:12:38 -04002241 nfs_fattr_init(fsinfo->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 return nfs4_do_fsinfo(server, fhandle, fsinfo);
2243}
2244
2245static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
2246 struct nfs_pathconf *pathconf)
2247{
2248 struct nfs4_pathconf_arg args = {
2249 .fh = fhandle,
2250 .bitmask = server->attr_bitmask,
2251 };
2252 struct rpc_message msg = {
2253 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
2254 .rpc_argp = &args,
2255 .rpc_resp = pathconf,
2256 };
2257
2258 /* None of the pathconf attributes are mandatory to implement */
2259 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
2260 memset(pathconf, 0, sizeof(*pathconf));
2261 return 0;
2262 }
2263
Trond Myklebust0e574af2005-10-27 22:12:38 -04002264 nfs_fattr_init(pathconf->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 return rpc_call_sync(server->client, &msg, 0);
2266}
2267
2268static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
2269 struct nfs_pathconf *pathconf)
2270{
2271 struct nfs4_exception exception = { };
2272 int err;
2273
2274 do {
2275 err = nfs4_handle_exception(server,
2276 _nfs4_proc_pathconf(server, fhandle, pathconf),
2277 &exception);
2278 } while (exception.retry);
2279 return err;
2280}
2281
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002282static void nfs4_read_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002284 struct nfs_read_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 struct inode *inode = data->inode;
2286
2287 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2288 rpc_restart_call(task);
2289 return;
2290 }
2291 if (task->tk_status > 0)
2292 renew_lease(NFS_SERVER(inode), data->timestamp);
2293 /* Call back common NFS readpage processing */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002294 nfs_readpage_result(task, calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002297static const struct rpc_call_ops nfs4_read_ops = {
2298 .rpc_call_done = nfs4_read_done,
2299 .rpc_release = nfs_readdata_release,
2300};
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302static void
2303nfs4_proc_read_setup(struct nfs_read_data *data)
2304{
2305 struct rpc_task *task = &data->task;
2306 struct rpc_message msg = {
2307 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
2308 .rpc_argp = &data->args,
2309 .rpc_resp = &data->res,
2310 .rpc_cred = data->cred,
2311 };
2312 struct inode *inode = data->inode;
2313 int flags;
2314
2315 data->timestamp = jiffies;
2316
2317 /* N.B. Do we need to test? Never called for swapfile inode */
2318 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
2319
2320 /* Finalize the task. */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002321 rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs4_read_ops, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 rpc_call_setup(task, &msg, 0);
2323}
2324
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002325static void nfs4_write_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002327 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 struct inode *inode = data->inode;
2329
2330 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2331 rpc_restart_call(task);
2332 return;
2333 }
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002334 if (task->tk_status >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 renew_lease(NFS_SERVER(inode), data->timestamp);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002336 nfs_post_op_update_inode(inode, data->res.fattr);
2337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 /* Call back common NFS writeback processing */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002339 nfs_writeback_done(task, calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340}
2341
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002342static const struct rpc_call_ops nfs4_write_ops = {
2343 .rpc_call_done = nfs4_write_done,
2344 .rpc_release = nfs_writedata_release,
2345};
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347static void
2348nfs4_proc_write_setup(struct nfs_write_data *data, int how)
2349{
2350 struct rpc_task *task = &data->task;
2351 struct rpc_message msg = {
2352 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
2353 .rpc_argp = &data->args,
2354 .rpc_resp = &data->res,
2355 .rpc_cred = data->cred,
2356 };
2357 struct inode *inode = data->inode;
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002358 struct nfs_server *server = NFS_SERVER(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 int stable;
2360 int flags;
2361
2362 if (how & FLUSH_STABLE) {
2363 if (!NFS_I(inode)->ncommit)
2364 stable = NFS_FILE_SYNC;
2365 else
2366 stable = NFS_DATA_SYNC;
2367 } else
2368 stable = NFS_UNSTABLE;
2369 data->args.stable = stable;
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002370 data->args.bitmask = server->attr_bitmask;
2371 data->res.server = server;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
2373 data->timestamp = jiffies;
2374
2375 /* Set the initial flags for the task. */
2376 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2377
2378 /* Finalize the task. */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002379 rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs4_write_ops, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 rpc_call_setup(task, &msg, 0);
2381}
2382
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002383static void nfs4_commit_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002385 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 struct inode *inode = data->inode;
2387
2388 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2389 rpc_restart_call(task);
2390 return;
2391 }
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002392 if (task->tk_status >= 0)
2393 nfs_post_op_update_inode(inode, data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 /* Call back common NFS writeback processing */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002395 nfs_commit_done(task, calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396}
2397
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002398static const struct rpc_call_ops nfs4_commit_ops = {
2399 .rpc_call_done = nfs4_commit_done,
2400 .rpc_release = nfs_commit_release,
2401};
2402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403static void
2404nfs4_proc_commit_setup(struct nfs_write_data *data, int how)
2405{
2406 struct rpc_task *task = &data->task;
2407 struct rpc_message msg = {
2408 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
2409 .rpc_argp = &data->args,
2410 .rpc_resp = &data->res,
2411 .rpc_cred = data->cred,
2412 };
2413 struct inode *inode = data->inode;
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002414 struct nfs_server *server = NFS_SERVER(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 int flags;
2416
Trond Myklebust4f9838c2005-10-27 22:12:44 -04002417 data->args.bitmask = server->attr_bitmask;
2418 data->res.server = server;
2419
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 /* Set the initial flags for the task. */
2421 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2422
2423 /* Finalize the task. */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002424 rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs4_commit_ops, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 rpc_call_setup(task, &msg, 0);
2426}
2427
2428/*
2429 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2430 * standalone procedure for queueing an asynchronous RENEW.
2431 */
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002432static void nfs4_renew_done(struct rpc_task *task, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
2434 struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp;
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002435 unsigned long timestamp = (unsigned long)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
2437 if (task->tk_status < 0) {
2438 switch (task->tk_status) {
2439 case -NFS4ERR_STALE_CLIENTID:
2440 case -NFS4ERR_EXPIRED:
2441 case -NFS4ERR_CB_PATH_DOWN:
2442 nfs4_schedule_state_recovery(clp);
2443 }
2444 return;
2445 }
2446 spin_lock(&clp->cl_lock);
2447 if (time_before(clp->cl_last_renewal,timestamp))
2448 clp->cl_last_renewal = timestamp;
2449 spin_unlock(&clp->cl_lock);
2450}
2451
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002452static const struct rpc_call_ops nfs4_renew_ops = {
2453 .rpc_call_done = nfs4_renew_done,
2454};
2455
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456int
2457nfs4_proc_async_renew(struct nfs4_client *clp)
2458{
2459 struct rpc_message msg = {
2460 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2461 .rpc_argp = clp,
2462 .rpc_cred = clp->cl_cred,
2463 };
2464
2465 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
Trond Myklebust963d8fe2006-01-03 09:55:04 +01002466 &nfs4_renew_ops, (void *)jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467}
2468
2469int
2470nfs4_proc_renew(struct nfs4_client *clp)
2471{
2472 struct rpc_message msg = {
2473 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2474 .rpc_argp = clp,
2475 .rpc_cred = clp->cl_cred,
2476 };
2477 unsigned long now = jiffies;
2478 int status;
2479
2480 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2481 if (status < 0)
2482 return status;
2483 spin_lock(&clp->cl_lock);
2484 if (time_before(clp->cl_last_renewal,now))
2485 clp->cl_last_renewal = now;
2486 spin_unlock(&clp->cl_lock);
2487 return 0;
2488}
2489
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00002490static inline int nfs4_server_supports_acls(struct nfs_server *server)
2491{
2492 return (server->caps & NFS_CAP_ACLS)
2493 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
2494 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
2495}
2496
2497/* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2498 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2499 * the stack.
2500 */
2501#define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2502
2503static void buf_to_pages(const void *buf, size_t buflen,
2504 struct page **pages, unsigned int *pgbase)
2505{
2506 const void *p = buf;
2507
2508 *pgbase = offset_in_page(buf);
2509 p -= *pgbase;
2510 while (p < buf + buflen) {
2511 *(pages++) = virt_to_page(p);
2512 p += PAGE_CACHE_SIZE;
2513 }
2514}
2515
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002516struct nfs4_cached_acl {
2517 int cached;
2518 size_t len;
Andrew Morton3e9d4152005-06-22 17:16:28 +00002519 char data[0];
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002520};
2521
2522static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00002523{
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002524 struct nfs_inode *nfsi = NFS_I(inode);
2525
2526 spin_lock(&inode->i_lock);
2527 kfree(nfsi->nfs4_acl);
2528 nfsi->nfs4_acl = acl;
2529 spin_unlock(&inode->i_lock);
2530}
2531
2532static void nfs4_zap_acl_attr(struct inode *inode)
2533{
2534 nfs4_set_cached_acl(inode, NULL);
2535}
2536
2537static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
2538{
2539 struct nfs_inode *nfsi = NFS_I(inode);
2540 struct nfs4_cached_acl *acl;
2541 int ret = -ENOENT;
2542
2543 spin_lock(&inode->i_lock);
2544 acl = nfsi->nfs4_acl;
2545 if (acl == NULL)
2546 goto out;
2547 if (buf == NULL) /* user is just asking for length */
2548 goto out_len;
2549 if (acl->cached == 0)
2550 goto out;
2551 ret = -ERANGE; /* see getxattr(2) man page */
2552 if (acl->len > buflen)
2553 goto out;
2554 memcpy(buf, acl->data, acl->len);
2555out_len:
2556 ret = acl->len;
2557out:
2558 spin_unlock(&inode->i_lock);
2559 return ret;
2560}
2561
2562static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
2563{
2564 struct nfs4_cached_acl *acl;
2565
2566 if (buf && acl_len <= PAGE_SIZE) {
2567 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
2568 if (acl == NULL)
2569 goto out;
2570 acl->cached = 1;
2571 memcpy(acl->data, buf, acl_len);
2572 } else {
2573 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
2574 if (acl == NULL)
2575 goto out;
2576 acl->cached = 0;
2577 }
2578 acl->len = acl_len;
2579out:
2580 nfs4_set_cached_acl(inode, acl);
2581}
2582
2583static inline ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
2584{
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00002585 struct page *pages[NFS4ACL_MAXPAGES];
2586 struct nfs_getaclargs args = {
2587 .fh = NFS_FH(inode),
2588 .acl_pages = pages,
2589 .acl_len = buflen,
2590 };
2591 size_t resp_len = buflen;
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002592 void *resp_buf;
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00002593 struct rpc_message msg = {
2594 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
2595 .rpc_argp = &args,
2596 .rpc_resp = &resp_len,
2597 };
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002598 struct page *localpage = NULL;
2599 int ret;
2600
2601 if (buflen < PAGE_SIZE) {
2602 /* As long as we're doing a round trip to the server anyway,
2603 * let's be prepared for a page of acl data. */
2604 localpage = alloc_page(GFP_KERNEL);
2605 resp_buf = page_address(localpage);
2606 if (localpage == NULL)
2607 return -ENOMEM;
2608 args.acl_pages[0] = localpage;
2609 args.acl_pgbase = 0;
J. Bruce Fields1d95db82005-10-13 16:54:32 -04002610 resp_len = args.acl_len = PAGE_SIZE;
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002611 } else {
2612 resp_buf = buf;
2613 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
2614 }
2615 ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2616 if (ret)
2617 goto out_free;
2618 if (resp_len > args.acl_len)
2619 nfs4_write_cached_acl(inode, NULL, resp_len);
2620 else
2621 nfs4_write_cached_acl(inode, resp_buf, resp_len);
2622 if (buf) {
2623 ret = -ERANGE;
2624 if (resp_len > buflen)
2625 goto out_free;
2626 if (localpage)
2627 memcpy(buf, resp_buf, resp_len);
2628 }
2629 ret = resp_len;
2630out_free:
2631 if (localpage)
2632 __free_page(localpage);
2633 return ret;
2634}
2635
2636static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
2637{
2638 struct nfs_server *server = NFS_SERVER(inode);
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00002639 int ret;
2640
2641 if (!nfs4_server_supports_acls(server))
2642 return -EOPNOTSUPP;
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002643 ret = nfs_revalidate_inode(server, inode);
2644 if (ret < 0)
2645 return ret;
2646 ret = nfs4_read_cached_acl(inode, buf, buflen);
2647 if (ret != -ENOENT)
2648 return ret;
2649 return nfs4_get_acl_uncached(inode, buf, buflen);
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00002650}
2651
J. Bruce Fields4b580ee2005-06-22 17:16:23 +00002652static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
2653{
2654 struct nfs_server *server = NFS_SERVER(inode);
2655 struct page *pages[NFS4ACL_MAXPAGES];
2656 struct nfs_setaclargs arg = {
2657 .fh = NFS_FH(inode),
2658 .acl_pages = pages,
2659 .acl_len = buflen,
2660 };
2661 struct rpc_message msg = {
2662 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
2663 .rpc_argp = &arg,
2664 .rpc_resp = NULL,
2665 };
2666 int ret;
2667
2668 if (!nfs4_server_supports_acls(server))
2669 return -EOPNOTSUPP;
Trond Myklebust642ac542005-10-18 14:20:19 -07002670 nfs_inode_return_delegation(inode);
J. Bruce Fields4b580ee2005-06-22 17:16:23 +00002671 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
2672 ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0);
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00002673 if (ret == 0)
2674 nfs4_write_cached_acl(inode, buf, buflen);
J. Bruce Fields4b580ee2005-06-22 17:16:23 +00002675 return ret;
2676}
2677
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678static int
Trond Myklebustfaf5f492005-10-18 14:20:15 -07002679nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
2681 struct nfs4_client *clp = server->nfs4_state;
2682
2683 if (!clp || task->tk_status >= 0)
2684 return 0;
2685 switch(task->tk_status) {
2686 case -NFS4ERR_STALE_CLIENTID:
2687 case -NFS4ERR_STALE_STATEID:
2688 case -NFS4ERR_EXPIRED:
2689 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL);
2690 nfs4_schedule_state_recovery(clp);
2691 if (test_bit(NFS4CLNT_OK, &clp->cl_state))
2692 rpc_wake_up_task(task);
2693 task->tk_status = 0;
2694 return -EAGAIN;
2695 case -NFS4ERR_GRACE:
2696 case -NFS4ERR_DELAY:
2697 rpc_delay(task, NFS4_POLL_RETRY_MAX);
2698 task->tk_status = 0;
2699 return -EAGAIN;
2700 case -NFS4ERR_OLD_STATEID:
2701 task->tk_status = 0;
2702 return -EAGAIN;
2703 }
2704 task->tk_status = nfs4_map_errors(task->tk_status);
2705 return 0;
2706}
2707
2708static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp)
2709{
2710 DEFINE_WAIT(wait);
2711 sigset_t oldset;
2712 int interruptible, res = 0;
2713
2714 might_sleep();
2715
2716 rpc_clnt_sigmask(clnt, &oldset);
2717 interruptible = TASK_UNINTERRUPTIBLE;
2718 if (clnt->cl_intr)
2719 interruptible = TASK_INTERRUPTIBLE;
2720 prepare_to_wait(&clp->cl_waitq, &wait, interruptible);
2721 nfs4_schedule_state_recovery(clp);
2722 if (clnt->cl_intr && signalled())
2723 res = -ERESTARTSYS;
2724 else if (!test_bit(NFS4CLNT_OK, &clp->cl_state))
2725 schedule();
2726 finish_wait(&clp->cl_waitq, &wait);
2727 rpc_clnt_sigunmask(clnt, &oldset);
2728 return res;
2729}
2730
2731static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
2732{
2733 sigset_t oldset;
2734 int res = 0;
2735
2736 might_sleep();
2737
2738 if (*timeout <= 0)
2739 *timeout = NFS4_POLL_RETRY_MIN;
2740 if (*timeout > NFS4_POLL_RETRY_MAX)
2741 *timeout = NFS4_POLL_RETRY_MAX;
2742 rpc_clnt_sigmask(clnt, &oldset);
2743 if (clnt->cl_intr) {
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07002744 schedule_timeout_interruptible(*timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 if (signalled())
2746 res = -ERESTARTSYS;
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07002747 } else
2748 schedule_timeout_uninterruptible(*timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 rpc_clnt_sigunmask(clnt, &oldset);
2750 *timeout <<= 1;
2751 return res;
2752}
2753
2754/* This is the error handling routine for processes that are allowed
2755 * to sleep.
2756 */
Trond Myklebustfaf5f492005-10-18 14:20:15 -07002757int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758{
2759 struct nfs4_client *clp = server->nfs4_state;
2760 int ret = errorcode;
2761
2762 exception->retry = 0;
2763 switch(errorcode) {
2764 case 0:
2765 return 0;
2766 case -NFS4ERR_STALE_CLIENTID:
2767 case -NFS4ERR_STALE_STATEID:
2768 case -NFS4ERR_EXPIRED:
2769 ret = nfs4_wait_clnt_recover(server->client, clp);
2770 if (ret == 0)
2771 exception->retry = 1;
2772 break;
2773 case -NFS4ERR_GRACE:
2774 case -NFS4ERR_DELAY:
2775 ret = nfs4_delay(server->client, &exception->timeout);
Trond Myklebust2c566172005-11-04 15:33:50 -05002776 if (ret != 0)
2777 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 case -NFS4ERR_OLD_STATEID:
Trond Myklebust2c566172005-11-04 15:33:50 -05002779 exception->retry = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 }
2781 /* We failed to handle the error */
2782 return nfs4_map_errors(ret);
2783}
2784
2785int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port)
2786{
2787 nfs4_verifier sc_verifier;
2788 struct nfs4_setclientid setclientid = {
2789 .sc_verifier = &sc_verifier,
2790 .sc_prog = program,
2791 };
2792 struct rpc_message msg = {
2793 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
2794 .rpc_argp = &setclientid,
2795 .rpc_resp = clp,
2796 .rpc_cred = clp->cl_cred,
2797 };
2798 u32 *p;
2799 int loop = 0;
2800 int status;
2801
2802 p = (u32*)sc_verifier.data;
2803 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
2804 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
2805
2806 for(;;) {
2807 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
2808 sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u",
2809 clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr),
2810 clp->cl_cred->cr_ops->cr_name,
2811 clp->cl_id_uniquifier);
2812 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
2813 sizeof(setclientid.sc_netid), "tcp");
2814 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
2815 sizeof(setclientid.sc_uaddr), "%s.%d.%d",
2816 clp->cl_ipaddr, port >> 8, port & 255);
2817
2818 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2819 if (status != -NFS4ERR_CLID_INUSE)
2820 break;
2821 if (signalled())
2822 break;
2823 if (loop++ & 1)
2824 ssleep(clp->cl_lease_time + 1);
2825 else
2826 if (++clp->cl_id_uniquifier == 0)
2827 break;
2828 }
2829 return status;
2830}
2831
2832int
2833nfs4_proc_setclientid_confirm(struct nfs4_client *clp)
2834{
2835 struct nfs_fsinfo fsinfo;
2836 struct rpc_message msg = {
2837 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
2838 .rpc_argp = clp,
2839 .rpc_resp = &fsinfo,
2840 .rpc_cred = clp->cl_cred,
2841 };
2842 unsigned long now;
2843 int status;
2844
2845 now = jiffies;
2846 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2847 if (status == 0) {
2848 spin_lock(&clp->cl_lock);
2849 clp->cl_lease_time = fsinfo.lease_time * HZ;
2850 clp->cl_last_renewal = now;
2851 spin_unlock(&clp->cl_lock);
2852 }
2853 return status;
2854}
2855
2856static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2857{
2858 struct nfs4_delegreturnargs args = {
2859 .fhandle = NFS_FH(inode),
2860 .stateid = stateid,
2861 };
2862 struct rpc_message msg = {
2863 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
2864 .rpc_argp = &args,
2865 .rpc_cred = cred,
2866 };
2867
2868 return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2869}
2870
2871int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2872{
2873 struct nfs_server *server = NFS_SERVER(inode);
2874 struct nfs4_exception exception = { };
2875 int err;
2876 do {
2877 err = _nfs4_proc_delegreturn(inode, cred, stateid);
2878 switch (err) {
2879 case -NFS4ERR_STALE_STATEID:
2880 case -NFS4ERR_EXPIRED:
2881 nfs4_schedule_state_recovery(server->nfs4_state);
2882 case 0:
2883 return 0;
2884 }
2885 err = nfs4_handle_exception(server, err, &exception);
2886 } while (exception.retry);
2887 return err;
2888}
2889
2890#define NFS4_LOCK_MINTIMEOUT (1 * HZ)
2891#define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
2892
2893/*
2894 * sleep, with exponential backoff, and retry the LOCK operation.
2895 */
2896static unsigned long
2897nfs4_set_lock_task_retry(unsigned long timeout)
2898{
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07002899 schedule_timeout_interruptible(timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 timeout <<= 1;
2901 if (timeout > NFS4_LOCK_MAXTIMEOUT)
2902 return NFS4_LOCK_MAXTIMEOUT;
2903 return timeout;
2904}
2905
2906static inline int
2907nfs4_lck_type(int cmd, struct file_lock *request)
2908{
2909 /* set lock type */
2910 switch (request->fl_type) {
2911 case F_RDLCK:
2912 return IS_SETLKW(cmd) ? NFS4_READW_LT : NFS4_READ_LT;
2913 case F_WRLCK:
2914 return IS_SETLKW(cmd) ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
2915 case F_UNLCK:
2916 return NFS4_WRITE_LT;
2917 }
2918 BUG();
2919 return 0;
2920}
2921
2922static inline uint64_t
2923nfs4_lck_length(struct file_lock *request)
2924{
2925 if (request->fl_end == OFFSET_MAX)
2926 return ~(uint64_t)0;
2927 return request->fl_end - request->fl_start + 1;
2928}
2929
2930static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2931{
2932 struct inode *inode = state->inode;
2933 struct nfs_server *server = NFS_SERVER(inode);
2934 struct nfs4_client *clp = server->nfs4_state;
2935 struct nfs_lockargs arg = {
2936 .fh = NFS_FH(inode),
2937 .type = nfs4_lck_type(cmd, request),
2938 .offset = request->fl_start,
2939 .length = nfs4_lck_length(request),
2940 };
2941 struct nfs_lockres res = {
2942 .server = server,
2943 };
2944 struct rpc_message msg = {
2945 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
2946 .rpc_argp = &arg,
2947 .rpc_resp = &res,
2948 .rpc_cred = state->owner->so_cred,
2949 };
2950 struct nfs_lowner nlo;
2951 struct nfs4_lock_state *lsp;
2952 int status;
2953
2954 down_read(&clp->cl_sem);
2955 nlo.clientid = clp->cl_clientid;
Trond Myklebust8d0a8a92005-06-22 17:16:32 +00002956 status = nfs4_set_lock_state(state, request);
2957 if (status != 0)
2958 goto out;
2959 lsp = request->fl_u.nfs4_fl.owner;
2960 nlo.id = lsp->ls_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 arg.u.lockt = &nlo;
2962 status = rpc_call_sync(server->client, &msg, 0);
2963 if (!status) {
2964 request->fl_type = F_UNLCK;
2965 } else if (status == -NFS4ERR_DENIED) {
2966 int64_t len, start, end;
2967 start = res.u.denied.offset;
2968 len = res.u.denied.length;
2969 end = start + len - 1;
2970 if (end < 0 || len == 0)
2971 request->fl_end = OFFSET_MAX;
2972 else
2973 request->fl_end = (loff_t)end;
2974 request->fl_start = (loff_t)start;
2975 request->fl_type = F_WRLCK;
2976 if (res.u.denied.type & 1)
2977 request->fl_type = F_RDLCK;
2978 request->fl_pid = 0;
2979 status = 0;
2980 }
Trond Myklebust8d0a8a92005-06-22 17:16:32 +00002981out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 up_read(&clp->cl_sem);
2983 return status;
2984}
2985
2986static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2987{
2988 struct nfs4_exception exception = { };
2989 int err;
2990
2991 do {
2992 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2993 _nfs4_proc_getlk(state, cmd, request),
2994 &exception);
2995 } while (exception.retry);
2996 return err;
2997}
2998
2999static int do_vfs_lock(struct file *file, struct file_lock *fl)
3000{
3001 int res = 0;
3002 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
3003 case FL_POSIX:
3004 res = posix_lock_file_wait(file, fl);
3005 break;
3006 case FL_FLOCK:
3007 res = flock_lock_file_wait(file, fl);
3008 break;
3009 default:
3010 BUG();
3011 }
3012 if (res < 0)
3013 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
3014 __FUNCTION__);
3015 return res;
3016}
3017
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003018struct nfs4_unlockdata {
3019 struct nfs_lockargs arg;
3020 struct nfs_locku_opargs luargs;
3021 struct nfs_lockres res;
3022 struct nfs4_lock_state *lsp;
3023 struct nfs_open_context *ctx;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003024};
3025
Trond Myklebust06f814a2006-01-03 09:55:07 +01003026static void nfs4_locku_release_calldata(void *data)
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003027{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003028 struct nfs4_unlockdata *calldata = data;
Trond Myklebust06f814a2006-01-03 09:55:07 +01003029 nfs_free_seqid(calldata->luargs.seqid);
3030 nfs4_put_lock_state(calldata->lsp);
3031 put_nfs_open_context(calldata->ctx);
3032 kfree(calldata);
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003033}
3034
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003035static void nfs4_locku_done(struct rpc_task *task, void *data)
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003036{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003037 struct nfs4_unlockdata *calldata = data;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003038
Trond Myklebust06f814a2006-01-03 09:55:07 +01003039 if (RPC_ASSASSINATED(task))
3040 return;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003041 nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid);
3042 switch (task->tk_status) {
3043 case 0:
3044 memcpy(calldata->lsp->ls_stateid.data,
3045 calldata->res.u.stateid.data,
3046 sizeof(calldata->lsp->ls_stateid.data));
3047 break;
3048 case -NFS4ERR_STALE_STATEID:
3049 case -NFS4ERR_EXPIRED:
3050 nfs4_schedule_state_recovery(calldata->res.server->nfs4_state);
3051 break;
3052 default:
3053 if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) {
3054 rpc_restart_call(task);
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003055 }
3056 }
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003057}
3058
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01003059static void nfs4_locku_prepare(struct rpc_task *task, void *data)
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003060{
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01003061 struct nfs4_unlockdata *calldata = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 struct rpc_message msg = {
3063 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003064 .rpc_argp = &calldata->arg,
3065 .rpc_resp = &calldata->res,
3066 .rpc_cred = calldata->lsp->ls_state->owner->so_cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 };
Trond Myklebust8d0a8a92005-06-22 17:16:32 +00003068 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003070 status = nfs_wait_on_sequence(calldata->luargs.seqid, task);
3071 if (status != 0)
3072 return;
3073 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003074 /* Note: exit _without_ running nfs4_locku_done */
3075 task->tk_action = NULL;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003076 return;
3077 }
3078 rpc_call_setup(task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003081static const struct rpc_call_ops nfs4_locku_ops = {
Trond Myklebust4ce70ad2006-01-03 09:55:05 +01003082 .rpc_call_prepare = nfs4_locku_prepare,
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003083 .rpc_call_done = nfs4_locku_done,
Trond Myklebust06f814a2006-01-03 09:55:07 +01003084 .rpc_release = nfs4_locku_release_calldata,
Trond Myklebust963d8fe2006-01-03 09:55:04 +01003085};
3086
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
3088{
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003089 struct nfs4_unlockdata *calldata;
3090 struct inode *inode = state->inode;
3091 struct nfs_server *server = NFS_SERVER(inode);
3092 struct nfs4_lock_state *lsp;
Trond Myklebust06f814a2006-01-03 09:55:07 +01003093 struct rpc_task *task;
3094 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003096 /* Is this a delegated lock? */
3097 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
Trond Myklebust06f814a2006-01-03 09:55:07 +01003098 goto out;
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003099
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003100 status = nfs4_set_lock_state(state, request);
3101 if (status != 0)
Trond Myklebust06f814a2006-01-03 09:55:07 +01003102 goto out;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003103 lsp = request->fl_u.nfs4_fl.owner;
3104 /* We might have lost the locks! */
3105 if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
Trond Myklebust06f814a2006-01-03 09:55:07 +01003106 goto out;
3107 status = -ENOMEM;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003108 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
3109 if (calldata == NULL)
Trond Myklebust06f814a2006-01-03 09:55:07 +01003110 goto out;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003111 calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid);
3112 if (calldata->luargs.seqid == NULL) {
3113 kfree(calldata);
Trond Myklebust06f814a2006-01-03 09:55:07 +01003114 goto out;
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003115 }
3116 calldata->luargs.stateid = &lsp->ls_stateid;
3117 calldata->arg.fh = NFS_FH(inode);
3118 calldata->arg.type = nfs4_lck_type(cmd, request);
3119 calldata->arg.offset = request->fl_start;
3120 calldata->arg.length = nfs4_lck_length(request);
3121 calldata->arg.u.locku = &calldata->luargs;
3122 calldata->res.server = server;
3123 calldata->lsp = lsp;
3124 atomic_inc(&lsp->ls_count);
3125
3126 /* Ensure we don't close file until we're done freeing locks! */
3127 calldata->ctx = get_nfs_open_context((struct nfs_open_context*)request->fl_file->private_data);
3128
Trond Myklebust06f814a2006-01-03 09:55:07 +01003129 task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_locku_ops, calldata);
3130 if (!IS_ERR(task)) {
3131 status = nfs4_wait_for_completion_rpc_task(task);
3132 rpc_release_task(task);
3133 } else {
3134 status = PTR_ERR(task);
3135 nfs4_locku_release_calldata(calldata);
3136 }
3137out:
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003138 do_vfs_lock(request->fl_file, request);
Trond Myklebustfaf5f492005-10-18 14:20:15 -07003139 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
3143{
3144 struct inode *inode = state->inode;
3145 struct nfs_server *server = NFS_SERVER(inode);
Trond Myklebust8d0a8a92005-06-22 17:16:32 +00003146 struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
Trond Myklebust06735b32005-10-18 14:20:15 -07003147 struct nfs_lock_opargs largs = {
3148 .lock_stateid = &lsp->ls_stateid,
3149 .open_stateid = &state->stateid,
3150 .lock_owner = {
3151 .clientid = server->nfs4_state->cl_clientid,
3152 .id = lsp->ls_id,
3153 },
3154 .reclaim = reclaim,
3155 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 struct nfs_lockargs arg = {
3157 .fh = NFS_FH(inode),
3158 .type = nfs4_lck_type(cmd, request),
3159 .offset = request->fl_start,
3160 .length = nfs4_lck_length(request),
Trond Myklebust06735b32005-10-18 14:20:15 -07003161 .u = {
3162 .lock = &largs,
3163 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 };
3165 struct nfs_lockres res = {
3166 .server = server,
3167 };
3168 struct rpc_message msg = {
3169 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
3170 .rpc_argp = &arg,
3171 .rpc_resp = &res,
3172 .rpc_cred = state->owner->so_cred,
3173 };
Trond Myklebustcee54fc2005-10-18 14:20:12 -07003174 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175
Trond Myklebust06735b32005-10-18 14:20:15 -07003176 largs.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
3177 if (largs.lock_seqid == NULL)
Trond Myklebustcee54fc2005-10-18 14:20:12 -07003178 return -ENOMEM;
3179 if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 struct nfs4_state_owner *owner = state->owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
Trond Myklebust06735b32005-10-18 14:20:15 -07003182 largs.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
3183 if (largs.open_seqid == NULL)
3184 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 largs.new_lock_owner = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
Trond Myklebust06735b32005-10-18 14:20:15 -07003187 /* increment open seqid on success, and seqid mutating errors */
3188 if (largs.new_lock_owner != 0) {
3189 nfs_increment_open_seqid(status, largs.open_seqid);
3190 if (status == 0)
3191 nfs_confirm_seqid(&lsp->ls_seqid, 0);
3192 }
3193 nfs_free_seqid(largs.open_seqid);
3194 } else
3195 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
3196 /* increment lock seqid on success, and seqid mutating errors*/
3197 nfs_increment_lock_seqid(status, largs.lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 /* save the returned stateid. */
Trond Myklebustcee54fc2005-10-18 14:20:12 -07003199 if (status == 0) {
Trond Myklebust06735b32005-10-18 14:20:15 -07003200 memcpy(lsp->ls_stateid.data, res.u.stateid.data,
3201 sizeof(lsp->ls_stateid.data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -07003202 lsp->ls_flags |= NFS_LOCK_INITIALIZED;
3203 } else if (status == -NFS4ERR_DENIED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 status = -EAGAIN;
Trond Myklebust06735b32005-10-18 14:20:15 -07003205out:
3206 nfs_free_seqid(largs.lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 return status;
3208}
3209
3210static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
3211{
Trond Myklebust202b50d2005-06-22 17:16:29 +00003212 struct nfs_server *server = NFS_SERVER(state->inode);
3213 struct nfs4_exception exception = { };
3214 int err;
3215
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003216 /* Cache the lock if possible... */
3217 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
3218 return 0;
Trond Myklebust202b50d2005-06-22 17:16:29 +00003219 do {
3220 err = _nfs4_do_setlk(state, F_SETLK, request, 1);
3221 if (err != -NFS4ERR_DELAY)
3222 break;
3223 nfs4_handle_exception(server, err, &exception);
3224 } while (exception.retry);
3225 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226}
3227
3228static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
3229{
Trond Myklebust202b50d2005-06-22 17:16:29 +00003230 struct nfs_server *server = NFS_SERVER(state->inode);
3231 struct nfs4_exception exception = { };
3232 int err;
3233
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003234 err = nfs4_set_lock_state(state, request);
3235 if (err != 0)
3236 return err;
Trond Myklebust202b50d2005-06-22 17:16:29 +00003237 do {
3238 err = _nfs4_do_setlk(state, F_SETLK, request, 0);
3239 if (err != -NFS4ERR_DELAY)
3240 break;
3241 nfs4_handle_exception(server, err, &exception);
3242 } while (exception.retry);
3243 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244}
3245
3246static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3247{
3248 struct nfs4_client *clp = state->owner->so_client;
3249 int status;
3250
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003251 /* Is this a delegated open? */
Trond Myklebustff604062005-11-25 17:10:01 -05003252 if (NFS_I(state->inode)->delegation_state != 0) {
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003253 /* Yes: cache locks! */
3254 status = do_vfs_lock(request->fl_file, request);
3255 /* ...but avoid races with delegation recall... */
3256 if (status < 0 || test_bit(NFS_DELEGATED_STATE, &state->flags))
Trond Myklebustff604062005-11-25 17:10:01 -05003257 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 }
Trond Myklebustff604062005-11-25 17:10:01 -05003259 down_read(&clp->cl_sem);
Trond Myklebust6bfc93e2005-11-04 15:39:36 -05003260 status = nfs4_set_lock_state(state, request);
3261 if (status != 0)
3262 goto out;
3263 status = _nfs4_do_setlk(state, cmd, request, 0);
3264 if (status != 0)
3265 goto out;
3266 /* Note: we always want to sleep here! */
3267 request->fl_flags |= FL_SLEEP;
3268 if (do_vfs_lock(request->fl_file, request) < 0)
3269 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
3270out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 up_read(&clp->cl_sem);
3272 return status;
3273}
3274
3275static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3276{
3277 struct nfs4_exception exception = { };
3278 int err;
3279
3280 do {
3281 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3282 _nfs4_proc_setlk(state, cmd, request),
3283 &exception);
3284 } while (exception.retry);
3285 return err;
3286}
3287
3288static int
3289nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
3290{
3291 struct nfs_open_context *ctx;
3292 struct nfs4_state *state;
3293 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
3294 int status;
3295
3296 /* verify open state */
3297 ctx = (struct nfs_open_context *)filp->private_data;
3298 state = ctx->state;
3299
3300 if (request->fl_start < 0 || request->fl_end < 0)
3301 return -EINVAL;
3302
3303 if (IS_GETLK(cmd))
3304 return nfs4_proc_getlk(state, F_GETLK, request);
3305
3306 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
3307 return -EINVAL;
3308
3309 if (request->fl_type == F_UNLCK)
3310 return nfs4_proc_unlck(state, cmd, request);
3311
3312 do {
3313 status = nfs4_proc_setlk(state, cmd, request);
3314 if ((status != -EAGAIN) || IS_SETLK(cmd))
3315 break;
3316 timeout = nfs4_set_lock_task_retry(timeout);
3317 status = -ERESTARTSYS;
3318 if (signalled())
3319 break;
3320 } while(status < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 return status;
3322}
3323
Trond Myklebust888e6942005-11-04 15:38:11 -05003324int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
3325{
3326 struct nfs_server *server = NFS_SERVER(state->inode);
3327 struct nfs4_exception exception = { };
3328 int err;
3329
3330 err = nfs4_set_lock_state(state, fl);
3331 if (err != 0)
3332 goto out;
3333 do {
3334 err = _nfs4_do_setlk(state, F_SETLK, fl, 0);
3335 if (err != -NFS4ERR_DELAY)
3336 break;
3337 err = nfs4_handle_exception(server, err, &exception);
3338 } while (exception.retry);
3339out:
3340 return err;
3341}
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003342
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00003343#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3344
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003345int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
3346 size_t buflen, int flags)
3347{
J. Bruce Fields4b580ee2005-06-22 17:16:23 +00003348 struct inode *inode = dentry->d_inode;
3349
3350 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3351 return -EOPNOTSUPP;
3352
3353 if (!S_ISREG(inode->i_mode) &&
3354 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3355 return -EPERM;
3356
3357 return nfs4_proc_set_acl(inode, buf, buflen);
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003358}
3359
3360/* The getxattr man page suggests returning -ENODATA for unknown attributes,
3361 * and that's what we'll do for e.g. user attributes that haven't been set.
3362 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3363 * attributes in kernel-managed attribute namespaces. */
3364ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
3365 size_t buflen)
3366{
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00003367 struct inode *inode = dentry->d_inode;
3368
3369 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3370 return -EOPNOTSUPP;
3371
3372 return nfs4_proc_get_acl(inode, buf, buflen);
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003373}
3374
3375ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
3376{
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00003377 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003378
3379 if (buf && buflen < len)
3380 return -ERANGE;
3381 if (buf)
J. Bruce Fieldsaa1870a2005-06-22 17:16:22 +00003382 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
3383 return len;
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003384}
3385
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
3387 .recover_open = nfs4_open_reclaim,
3388 .recover_lock = nfs4_lock_reclaim,
3389};
3390
3391struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = {
3392 .recover_open = nfs4_open_expired,
3393 .recover_lock = nfs4_lock_expired,
3394};
3395
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003396static struct inode_operations nfs4_file_inode_operations = {
3397 .permission = nfs_permission,
3398 .getattr = nfs_getattr,
3399 .setattr = nfs_setattr,
3400 .getxattr = nfs4_getxattr,
3401 .setxattr = nfs4_setxattr,
3402 .listxattr = nfs4_listxattr,
3403};
3404
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405struct nfs_rpc_ops nfs_v4_clientops = {
3406 .version = 4, /* protocol version */
3407 .dentry_ops = &nfs4_dentry_operations,
3408 .dir_inode_ops = &nfs4_dir_inode_operations,
J. Bruce Fields6b3b5492005-06-22 17:16:22 +00003409 .file_inode_ops = &nfs4_file_inode_operations,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 .getroot = nfs4_proc_get_root,
3411 .getattr = nfs4_proc_getattr,
3412 .setattr = nfs4_proc_setattr,
3413 .lookup = nfs4_proc_lookup,
3414 .access = nfs4_proc_access,
3415 .readlink = nfs4_proc_readlink,
3416 .read = nfs4_proc_read,
3417 .write = nfs4_proc_write,
3418 .commit = nfs4_proc_commit,
3419 .create = nfs4_proc_create,
3420 .remove = nfs4_proc_remove,
3421 .unlink_setup = nfs4_proc_unlink_setup,
3422 .unlink_done = nfs4_proc_unlink_done,
3423 .rename = nfs4_proc_rename,
3424 .link = nfs4_proc_link,
3425 .symlink = nfs4_proc_symlink,
3426 .mkdir = nfs4_proc_mkdir,
3427 .rmdir = nfs4_proc_remove,
3428 .readdir = nfs4_proc_readdir,
3429 .mknod = nfs4_proc_mknod,
3430 .statfs = nfs4_proc_statfs,
3431 .fsinfo = nfs4_proc_fsinfo,
3432 .pathconf = nfs4_proc_pathconf,
3433 .decode_dirent = nfs4_decode_dirent,
3434 .read_setup = nfs4_proc_read_setup,
3435 .write_setup = nfs4_proc_write_setup,
3436 .commit_setup = nfs4_proc_commit_setup,
Trond Myklebust02a913a2005-10-18 14:20:17 -07003437 .file_open = nfs_open,
3438 .file_release = nfs_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 .lock = nfs4_proc_lock,
J. Bruce Fieldse50a1c22005-06-22 17:16:23 +00003440 .clear_acl_cache = nfs4_zap_acl_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441};
3442
3443/*
3444 * Local variables:
3445 * c-basic-offset: 8
3446 * End:
3447 */