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