drm/i915|intel-gtt: consolidate intel-gtt.h headers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / afs / vnode.c
blob25cf4c3f4ff7ded56a2b0f0183b00584668104c7
1 /* AFS vnode management
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/fs.h>
16 #include <linux/sched.h>
17 #include "internal.h"
19 #if 0
20 static noinline bool dump_tree_aux(struct rb_node *node, struct rb_node *parent,
21 int depth, char lr)
23 struct afs_vnode *vnode;
24 bool bad = false;
26 if (!node)
27 return false;
29 if (node->rb_left)
30 bad = dump_tree_aux(node->rb_left, node, depth + 2, '/');
32 vnode = rb_entry(node, struct afs_vnode, cb_promise);
33 _debug("%c %*.*s%c%p {%d}",
34 rb_is_red(node) ? 'R' : 'B',
35 depth, depth, "", lr,
36 vnode, vnode->cb_expires_at);
37 if (rb_parent(node) != parent) {
38 printk("BAD: %p != %p\n", rb_parent(node), parent);
39 bad = true;
42 if (node->rb_right)
43 bad |= dump_tree_aux(node->rb_right, node, depth + 2, '\\');
45 return bad;
48 static noinline void dump_tree(const char *name, struct afs_server *server)
50 _enter("%s", name);
51 if (dump_tree_aux(server->cb_promises.rb_node, NULL, 0, '-'))
52 BUG();
54 #endif
57 * insert a vnode into the backing server's vnode tree
59 static void afs_install_vnode(struct afs_vnode *vnode,
60 struct afs_server *server)
62 struct afs_server *old_server = vnode->server;
63 struct afs_vnode *xvnode;
64 struct rb_node *parent, **p;
66 _enter("%p,%p", vnode, server);
68 if (old_server) {
69 spin_lock(&old_server->fs_lock);
70 rb_erase(&vnode->server_rb, &old_server->fs_vnodes);
71 spin_unlock(&old_server->fs_lock);
74 afs_get_server(server);
75 vnode->server = server;
76 afs_put_server(old_server);
78 /* insert into the server's vnode tree in FID order */
79 spin_lock(&server->fs_lock);
81 parent = NULL;
82 p = &server->fs_vnodes.rb_node;
83 while (*p) {
84 parent = *p;
85 xvnode = rb_entry(parent, struct afs_vnode, server_rb);
86 if (vnode->fid.vid < xvnode->fid.vid)
87 p = &(*p)->rb_left;
88 else if (vnode->fid.vid > xvnode->fid.vid)
89 p = &(*p)->rb_right;
90 else if (vnode->fid.vnode < xvnode->fid.vnode)
91 p = &(*p)->rb_left;
92 else if (vnode->fid.vnode > xvnode->fid.vnode)
93 p = &(*p)->rb_right;
94 else if (vnode->fid.unique < xvnode->fid.unique)
95 p = &(*p)->rb_left;
96 else if (vnode->fid.unique > xvnode->fid.unique)
97 p = &(*p)->rb_right;
98 else
99 BUG(); /* can't happen unless afs_iget() malfunctions */
102 rb_link_node(&vnode->server_rb, parent, p);
103 rb_insert_color(&vnode->server_rb, &server->fs_vnodes);
105 spin_unlock(&server->fs_lock);
106 _leave("");
110 * insert a vnode into the promising server's update/expiration tree
111 * - caller must hold vnode->lock
113 static void afs_vnode_note_promise(struct afs_vnode *vnode,
114 struct afs_server *server)
116 struct afs_server *old_server;
117 struct afs_vnode *xvnode;
118 struct rb_node *parent, **p;
120 _enter("%p,%p", vnode, server);
122 ASSERT(server != NULL);
124 old_server = vnode->server;
125 if (vnode->cb_promised) {
126 if (server == old_server &&
127 vnode->cb_expires == vnode->cb_expires_at) {
128 _leave(" [no change]");
129 return;
132 spin_lock(&old_server->cb_lock);
133 if (vnode->cb_promised) {
134 _debug("delete");
135 rb_erase(&vnode->cb_promise, &old_server->cb_promises);
136 vnode->cb_promised = false;
138 spin_unlock(&old_server->cb_lock);
141 if (vnode->server != server)
142 afs_install_vnode(vnode, server);
144 vnode->cb_expires_at = vnode->cb_expires;
145 _debug("PROMISE on %p {%lu}",
146 vnode, (unsigned long) vnode->cb_expires_at);
148 /* abuse an RB-tree to hold the expiration order (we may have multiple
149 * items with the same expiration time) */
150 spin_lock(&server->cb_lock);
152 parent = NULL;
153 p = &server->cb_promises.rb_node;
154 while (*p) {
155 parent = *p;
156 xvnode = rb_entry(parent, struct afs_vnode, cb_promise);
157 if (vnode->cb_expires_at < xvnode->cb_expires_at)
158 p = &(*p)->rb_left;
159 else
160 p = &(*p)->rb_right;
163 rb_link_node(&vnode->cb_promise, parent, p);
164 rb_insert_color(&vnode->cb_promise, &server->cb_promises);
165 vnode->cb_promised = true;
167 spin_unlock(&server->cb_lock);
168 _leave("");
172 * handle remote file deletion by discarding the callback promise
174 static void afs_vnode_deleted_remotely(struct afs_vnode *vnode)
176 struct afs_server *server;
178 _enter("{%p}", vnode->server);
180 set_bit(AFS_VNODE_DELETED, &vnode->flags);
182 server = vnode->server;
183 if (server) {
184 if (vnode->cb_promised) {
185 spin_lock(&server->cb_lock);
186 if (vnode->cb_promised) {
187 rb_erase(&vnode->cb_promise,
188 &server->cb_promises);
189 vnode->cb_promised = false;
191 spin_unlock(&server->cb_lock);
194 spin_lock(&server->fs_lock);
195 rb_erase(&vnode->server_rb, &server->fs_vnodes);
196 spin_unlock(&server->fs_lock);
198 vnode->server = NULL;
199 afs_put_server(server);
200 } else {
201 ASSERT(!vnode->cb_promised);
204 _leave("");
208 * finish off updating the recorded status of a file after a successful
209 * operation completion
210 * - starts callback expiry timer
211 * - adds to server's callback list
213 void afs_vnode_finalise_status_update(struct afs_vnode *vnode,
214 struct afs_server *server)
216 struct afs_server *oldserver = NULL;
218 _enter("%p,%p", vnode, server);
220 spin_lock(&vnode->lock);
221 clear_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
222 afs_vnode_note_promise(vnode, server);
223 vnode->update_cnt--;
224 ASSERTCMP(vnode->update_cnt, >=, 0);
225 spin_unlock(&vnode->lock);
227 wake_up_all(&vnode->update_waitq);
228 afs_put_server(oldserver);
229 _leave("");
233 * finish off updating the recorded status of a file after an operation failed
235 static void afs_vnode_status_update_failed(struct afs_vnode *vnode, int ret)
237 _enter("{%x:%u},%d", vnode->fid.vid, vnode->fid.vnode, ret);
239 spin_lock(&vnode->lock);
241 clear_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
243 if (ret == -ENOENT) {
244 /* the file was deleted on the server */
245 _debug("got NOENT from server - marking file deleted");
246 afs_vnode_deleted_remotely(vnode);
249 vnode->update_cnt--;
250 ASSERTCMP(vnode->update_cnt, >=, 0);
251 spin_unlock(&vnode->lock);
253 wake_up_all(&vnode->update_waitq);
254 _leave("");
258 * fetch file status from the volume
259 * - don't issue a fetch if:
260 * - the changed bit is not set and there's a valid callback
261 * - there are any outstanding ops that will fetch the status
262 * - TODO implement local caching
264 int afs_vnode_fetch_status(struct afs_vnode *vnode,
265 struct afs_vnode *auth_vnode, struct key *key)
267 struct afs_server *server;
268 unsigned long acl_order;
269 int ret;
271 DECLARE_WAITQUEUE(myself, current);
273 _enter("%s,{%x:%u.%u}",
274 vnode->volume->vlocation->vldb.name,
275 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
277 if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
278 vnode->cb_promised) {
279 _leave(" [unchanged]");
280 return 0;
283 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
284 _leave(" [deleted]");
285 return -ENOENT;
288 acl_order = 0;
289 if (auth_vnode)
290 acl_order = auth_vnode->acl_order;
292 spin_lock(&vnode->lock);
294 if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
295 vnode->cb_promised) {
296 spin_unlock(&vnode->lock);
297 _leave(" [unchanged]");
298 return 0;
301 ASSERTCMP(vnode->update_cnt, >=, 0);
303 if (vnode->update_cnt > 0) {
304 /* someone else started a fetch */
305 _debug("wait on fetch %d", vnode->update_cnt);
307 set_current_state(TASK_UNINTERRUPTIBLE);
308 ASSERT(myself.func != NULL);
309 add_wait_queue(&vnode->update_waitq, &myself);
311 /* wait for the status to be updated */
312 for (;;) {
313 if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
314 break;
315 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
316 break;
318 /* check to see if it got updated and invalidated all
319 * before we saw it */
320 if (vnode->update_cnt == 0) {
321 remove_wait_queue(&vnode->update_waitq,
322 &myself);
323 set_current_state(TASK_RUNNING);
324 goto get_anyway;
327 spin_unlock(&vnode->lock);
329 schedule();
330 set_current_state(TASK_UNINTERRUPTIBLE);
332 spin_lock(&vnode->lock);
335 remove_wait_queue(&vnode->update_waitq, &myself);
336 spin_unlock(&vnode->lock);
337 set_current_state(TASK_RUNNING);
339 return test_bit(AFS_VNODE_DELETED, &vnode->flags) ?
340 -ENOENT : 0;
343 get_anyway:
344 /* okay... we're going to have to initiate the op */
345 vnode->update_cnt++;
347 spin_unlock(&vnode->lock);
349 /* merge AFS status fetches and clear outstanding callback on this
350 * vnode */
351 do {
352 /* pick a server to query */
353 server = afs_volume_pick_fileserver(vnode);
354 if (IS_ERR(server))
355 goto no_server;
357 _debug("USING SERVER: %p{%08x}",
358 server, ntohl(server->addr.s_addr));
360 ret = afs_fs_fetch_file_status(server, key, vnode, NULL,
361 &afs_sync_call);
363 } while (!afs_volume_release_fileserver(vnode, server, ret));
365 /* adjust the flags */
366 if (ret == 0) {
367 _debug("adjust");
368 if (auth_vnode)
369 afs_cache_permit(vnode, key, acl_order);
370 afs_vnode_finalise_status_update(vnode, server);
371 afs_put_server(server);
372 } else {
373 _debug("failed [%d]", ret);
374 afs_vnode_status_update_failed(vnode, ret);
377 ASSERTCMP(vnode->update_cnt, >=, 0);
379 _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
380 return ret;
382 no_server:
383 spin_lock(&vnode->lock);
384 vnode->update_cnt--;
385 ASSERTCMP(vnode->update_cnt, >=, 0);
386 spin_unlock(&vnode->lock);
387 _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
388 return PTR_ERR(server);
392 * fetch file data from the volume
393 * - TODO implement caching
395 int afs_vnode_fetch_data(struct afs_vnode *vnode, struct key *key,
396 off_t offset, size_t length, struct page *page)
398 struct afs_server *server;
399 int ret;
401 _enter("%s{%x:%u.%u},%x,,,",
402 vnode->volume->vlocation->vldb.name,
403 vnode->fid.vid,
404 vnode->fid.vnode,
405 vnode->fid.unique,
406 key_serial(key));
408 /* this op will fetch the status */
409 spin_lock(&vnode->lock);
410 vnode->update_cnt++;
411 spin_unlock(&vnode->lock);
413 /* merge in AFS status fetches and clear outstanding callback on this
414 * vnode */
415 do {
416 /* pick a server to query */
417 server = afs_volume_pick_fileserver(vnode);
418 if (IS_ERR(server))
419 goto no_server;
421 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
423 ret = afs_fs_fetch_data(server, key, vnode, offset, length,
424 page, &afs_sync_call);
426 } while (!afs_volume_release_fileserver(vnode, server, ret));
428 /* adjust the flags */
429 if (ret == 0) {
430 afs_vnode_finalise_status_update(vnode, server);
431 afs_put_server(server);
432 } else {
433 afs_vnode_status_update_failed(vnode, ret);
436 _leave(" = %d", ret);
437 return ret;
439 no_server:
440 spin_lock(&vnode->lock);
441 vnode->update_cnt--;
442 ASSERTCMP(vnode->update_cnt, >=, 0);
443 spin_unlock(&vnode->lock);
444 return PTR_ERR(server);
448 * make a file or a directory
450 int afs_vnode_create(struct afs_vnode *vnode, struct key *key,
451 const char *name, umode_t mode, struct afs_fid *newfid,
452 struct afs_file_status *newstatus,
453 struct afs_callback *newcb, struct afs_server **_server)
455 struct afs_server *server;
456 int ret;
458 _enter("%s{%x:%u.%u},%x,%s,,",
459 vnode->volume->vlocation->vldb.name,
460 vnode->fid.vid,
461 vnode->fid.vnode,
462 vnode->fid.unique,
463 key_serial(key),
464 name);
466 /* this op will fetch the status on the directory we're creating in */
467 spin_lock(&vnode->lock);
468 vnode->update_cnt++;
469 spin_unlock(&vnode->lock);
471 do {
472 /* pick a server to query */
473 server = afs_volume_pick_fileserver(vnode);
474 if (IS_ERR(server))
475 goto no_server;
477 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
479 ret = afs_fs_create(server, key, vnode, name, mode, newfid,
480 newstatus, newcb, &afs_sync_call);
482 } while (!afs_volume_release_fileserver(vnode, server, ret));
484 /* adjust the flags */
485 if (ret == 0) {
486 afs_vnode_finalise_status_update(vnode, server);
487 *_server = server;
488 } else {
489 afs_vnode_status_update_failed(vnode, ret);
490 *_server = NULL;
493 _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
494 return ret;
496 no_server:
497 spin_lock(&vnode->lock);
498 vnode->update_cnt--;
499 ASSERTCMP(vnode->update_cnt, >=, 0);
500 spin_unlock(&vnode->lock);
501 _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
502 return PTR_ERR(server);
506 * remove a file or directory
508 int afs_vnode_remove(struct afs_vnode *vnode, struct key *key, const char *name,
509 bool isdir)
511 struct afs_server *server;
512 int ret;
514 _enter("%s{%x:%u.%u},%x,%s",
515 vnode->volume->vlocation->vldb.name,
516 vnode->fid.vid,
517 vnode->fid.vnode,
518 vnode->fid.unique,
519 key_serial(key),
520 name);
522 /* this op will fetch the status on the directory we're removing from */
523 spin_lock(&vnode->lock);
524 vnode->update_cnt++;
525 spin_unlock(&vnode->lock);
527 do {
528 /* pick a server to query */
529 server = afs_volume_pick_fileserver(vnode);
530 if (IS_ERR(server))
531 goto no_server;
533 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
535 ret = afs_fs_remove(server, key, vnode, name, isdir,
536 &afs_sync_call);
538 } while (!afs_volume_release_fileserver(vnode, server, ret));
540 /* adjust the flags */
541 if (ret == 0) {
542 afs_vnode_finalise_status_update(vnode, server);
543 afs_put_server(server);
544 } else {
545 afs_vnode_status_update_failed(vnode, ret);
548 _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
549 return ret;
551 no_server:
552 spin_lock(&vnode->lock);
553 vnode->update_cnt--;
554 ASSERTCMP(vnode->update_cnt, >=, 0);
555 spin_unlock(&vnode->lock);
556 _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
557 return PTR_ERR(server);
561 * create a hard link
563 int afs_vnode_link(struct afs_vnode *dvnode, struct afs_vnode *vnode,
564 struct key *key, const char *name)
566 struct afs_server *server;
567 int ret;
569 _enter("%s{%x:%u.%u},%s{%x:%u.%u},%x,%s",
570 dvnode->volume->vlocation->vldb.name,
571 dvnode->fid.vid,
572 dvnode->fid.vnode,
573 dvnode->fid.unique,
574 vnode->volume->vlocation->vldb.name,
575 vnode->fid.vid,
576 vnode->fid.vnode,
577 vnode->fid.unique,
578 key_serial(key),
579 name);
581 /* this op will fetch the status on the directory we're removing from */
582 spin_lock(&vnode->lock);
583 vnode->update_cnt++;
584 spin_unlock(&vnode->lock);
585 spin_lock(&dvnode->lock);
586 dvnode->update_cnt++;
587 spin_unlock(&dvnode->lock);
589 do {
590 /* pick a server to query */
591 server = afs_volume_pick_fileserver(dvnode);
592 if (IS_ERR(server))
593 goto no_server;
595 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
597 ret = afs_fs_link(server, key, dvnode, vnode, name,
598 &afs_sync_call);
600 } while (!afs_volume_release_fileserver(dvnode, server, ret));
602 /* adjust the flags */
603 if (ret == 0) {
604 afs_vnode_finalise_status_update(vnode, server);
605 afs_vnode_finalise_status_update(dvnode, server);
606 afs_put_server(server);
607 } else {
608 afs_vnode_status_update_failed(vnode, ret);
609 afs_vnode_status_update_failed(dvnode, ret);
612 _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
613 return ret;
615 no_server:
616 spin_lock(&vnode->lock);
617 vnode->update_cnt--;
618 ASSERTCMP(vnode->update_cnt, >=, 0);
619 spin_unlock(&vnode->lock);
620 spin_lock(&dvnode->lock);
621 dvnode->update_cnt--;
622 ASSERTCMP(dvnode->update_cnt, >=, 0);
623 spin_unlock(&dvnode->lock);
624 _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
625 return PTR_ERR(server);
629 * create a symbolic link
631 int afs_vnode_symlink(struct afs_vnode *vnode, struct key *key,
632 const char *name, const char *content,
633 struct afs_fid *newfid,
634 struct afs_file_status *newstatus,
635 struct afs_server **_server)
637 struct afs_server *server;
638 int ret;
640 _enter("%s{%x:%u.%u},%x,%s,%s,,,",
641 vnode->volume->vlocation->vldb.name,
642 vnode->fid.vid,
643 vnode->fid.vnode,
644 vnode->fid.unique,
645 key_serial(key),
646 name, content);
648 /* this op will fetch the status on the directory we're creating in */
649 spin_lock(&vnode->lock);
650 vnode->update_cnt++;
651 spin_unlock(&vnode->lock);
653 do {
654 /* pick a server to query */
655 server = afs_volume_pick_fileserver(vnode);
656 if (IS_ERR(server))
657 goto no_server;
659 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
661 ret = afs_fs_symlink(server, key, vnode, name, content,
662 newfid, newstatus, &afs_sync_call);
664 } while (!afs_volume_release_fileserver(vnode, server, ret));
666 /* adjust the flags */
667 if (ret == 0) {
668 afs_vnode_finalise_status_update(vnode, server);
669 *_server = server;
670 } else {
671 afs_vnode_status_update_failed(vnode, ret);
672 *_server = NULL;
675 _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
676 return ret;
678 no_server:
679 spin_lock(&vnode->lock);
680 vnode->update_cnt--;
681 ASSERTCMP(vnode->update_cnt, >=, 0);
682 spin_unlock(&vnode->lock);
683 _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
684 return PTR_ERR(server);
688 * rename a file
690 int afs_vnode_rename(struct afs_vnode *orig_dvnode,
691 struct afs_vnode *new_dvnode,
692 struct key *key,
693 const char *orig_name,
694 const char *new_name)
696 struct afs_server *server;
697 int ret;
699 _enter("%s{%x:%u.%u},%s{%u,%u,%u},%x,%s,%s",
700 orig_dvnode->volume->vlocation->vldb.name,
701 orig_dvnode->fid.vid,
702 orig_dvnode->fid.vnode,
703 orig_dvnode->fid.unique,
704 new_dvnode->volume->vlocation->vldb.name,
705 new_dvnode->fid.vid,
706 new_dvnode->fid.vnode,
707 new_dvnode->fid.unique,
708 key_serial(key),
709 orig_name,
710 new_name);
712 /* this op will fetch the status on both the directories we're dealing
713 * with */
714 spin_lock(&orig_dvnode->lock);
715 orig_dvnode->update_cnt++;
716 spin_unlock(&orig_dvnode->lock);
717 if (new_dvnode != orig_dvnode) {
718 spin_lock(&new_dvnode->lock);
719 new_dvnode->update_cnt++;
720 spin_unlock(&new_dvnode->lock);
723 do {
724 /* pick a server to query */
725 server = afs_volume_pick_fileserver(orig_dvnode);
726 if (IS_ERR(server))
727 goto no_server;
729 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
731 ret = afs_fs_rename(server, key, orig_dvnode, orig_name,
732 new_dvnode, new_name, &afs_sync_call);
734 } while (!afs_volume_release_fileserver(orig_dvnode, server, ret));
736 /* adjust the flags */
737 if (ret == 0) {
738 afs_vnode_finalise_status_update(orig_dvnode, server);
739 if (new_dvnode != orig_dvnode)
740 afs_vnode_finalise_status_update(new_dvnode, server);
741 afs_put_server(server);
742 } else {
743 afs_vnode_status_update_failed(orig_dvnode, ret);
744 if (new_dvnode != orig_dvnode)
745 afs_vnode_status_update_failed(new_dvnode, ret);
748 _leave(" = %d [cnt %d]", ret, orig_dvnode->update_cnt);
749 return ret;
751 no_server:
752 spin_lock(&orig_dvnode->lock);
753 orig_dvnode->update_cnt--;
754 ASSERTCMP(orig_dvnode->update_cnt, >=, 0);
755 spin_unlock(&orig_dvnode->lock);
756 if (new_dvnode != orig_dvnode) {
757 spin_lock(&new_dvnode->lock);
758 new_dvnode->update_cnt--;
759 ASSERTCMP(new_dvnode->update_cnt, >=, 0);
760 spin_unlock(&new_dvnode->lock);
762 _leave(" = %ld [cnt %d]", PTR_ERR(server), orig_dvnode->update_cnt);
763 return PTR_ERR(server);
767 * write to a file
769 int afs_vnode_store_data(struct afs_writeback *wb, pgoff_t first, pgoff_t last,
770 unsigned offset, unsigned to)
772 struct afs_server *server;
773 struct afs_vnode *vnode = wb->vnode;
774 int ret;
776 _enter("%s{%x:%u.%u},%x,%lx,%lx,%x,%x",
777 vnode->volume->vlocation->vldb.name,
778 vnode->fid.vid,
779 vnode->fid.vnode,
780 vnode->fid.unique,
781 key_serial(wb->key),
782 first, last, offset, to);
784 /* this op will fetch the status */
785 spin_lock(&vnode->lock);
786 vnode->update_cnt++;
787 spin_unlock(&vnode->lock);
789 do {
790 /* pick a server to query */
791 server = afs_volume_pick_fileserver(vnode);
792 if (IS_ERR(server))
793 goto no_server;
795 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
797 ret = afs_fs_store_data(server, wb, first, last, offset, to,
798 &afs_sync_call);
800 } while (!afs_volume_release_fileserver(vnode, server, ret));
802 /* adjust the flags */
803 if (ret == 0) {
804 afs_vnode_finalise_status_update(vnode, server);
805 afs_put_server(server);
806 } else {
807 afs_vnode_status_update_failed(vnode, ret);
810 _leave(" = %d", ret);
811 return ret;
813 no_server:
814 spin_lock(&vnode->lock);
815 vnode->update_cnt--;
816 ASSERTCMP(vnode->update_cnt, >=, 0);
817 spin_unlock(&vnode->lock);
818 return PTR_ERR(server);
822 * set the attributes on a file
824 int afs_vnode_setattr(struct afs_vnode *vnode, struct key *key,
825 struct iattr *attr)
827 struct afs_server *server;
828 int ret;
830 _enter("%s{%x:%u.%u},%x",
831 vnode->volume->vlocation->vldb.name,
832 vnode->fid.vid,
833 vnode->fid.vnode,
834 vnode->fid.unique,
835 key_serial(key));
837 /* this op will fetch the status */
838 spin_lock(&vnode->lock);
839 vnode->update_cnt++;
840 spin_unlock(&vnode->lock);
842 do {
843 /* pick a server to query */
844 server = afs_volume_pick_fileserver(vnode);
845 if (IS_ERR(server))
846 goto no_server;
848 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
850 ret = afs_fs_setattr(server, key, vnode, attr, &afs_sync_call);
852 } while (!afs_volume_release_fileserver(vnode, server, ret));
854 /* adjust the flags */
855 if (ret == 0) {
856 afs_vnode_finalise_status_update(vnode, server);
857 afs_put_server(server);
858 } else {
859 afs_vnode_status_update_failed(vnode, ret);
862 _leave(" = %d", ret);
863 return ret;
865 no_server:
866 spin_lock(&vnode->lock);
867 vnode->update_cnt--;
868 ASSERTCMP(vnode->update_cnt, >=, 0);
869 spin_unlock(&vnode->lock);
870 return PTR_ERR(server);
874 * get the status of a volume
876 int afs_vnode_get_volume_status(struct afs_vnode *vnode, struct key *key,
877 struct afs_volume_status *vs)
879 struct afs_server *server;
880 int ret;
882 _enter("%s{%x:%u.%u},%x,",
883 vnode->volume->vlocation->vldb.name,
884 vnode->fid.vid,
885 vnode->fid.vnode,
886 vnode->fid.unique,
887 key_serial(key));
889 do {
890 /* pick a server to query */
891 server = afs_volume_pick_fileserver(vnode);
892 if (IS_ERR(server))
893 goto no_server;
895 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
897 ret = afs_fs_get_volume_status(server, key, vnode, vs, &afs_sync_call);
899 } while (!afs_volume_release_fileserver(vnode, server, ret));
901 /* adjust the flags */
902 if (ret == 0)
903 afs_put_server(server);
905 _leave(" = %d", ret);
906 return ret;
908 no_server:
909 return PTR_ERR(server);
913 * get a lock on a file
915 int afs_vnode_set_lock(struct afs_vnode *vnode, struct key *key,
916 afs_lock_type_t type)
918 struct afs_server *server;
919 int ret;
921 _enter("%s{%x:%u.%u},%x,%u",
922 vnode->volume->vlocation->vldb.name,
923 vnode->fid.vid,
924 vnode->fid.vnode,
925 vnode->fid.unique,
926 key_serial(key), type);
928 do {
929 /* pick a server to query */
930 server = afs_volume_pick_fileserver(vnode);
931 if (IS_ERR(server))
932 goto no_server;
934 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
936 ret = afs_fs_set_lock(server, key, vnode, type, &afs_sync_call);
938 } while (!afs_volume_release_fileserver(vnode, server, ret));
940 /* adjust the flags */
941 if (ret == 0)
942 afs_put_server(server);
944 _leave(" = %d", ret);
945 return ret;
947 no_server:
948 return PTR_ERR(server);
952 * extend a lock on a file
954 int afs_vnode_extend_lock(struct afs_vnode *vnode, struct key *key)
956 struct afs_server *server;
957 int ret;
959 _enter("%s{%x:%u.%u},%x",
960 vnode->volume->vlocation->vldb.name,
961 vnode->fid.vid,
962 vnode->fid.vnode,
963 vnode->fid.unique,
964 key_serial(key));
966 do {
967 /* pick a server to query */
968 server = afs_volume_pick_fileserver(vnode);
969 if (IS_ERR(server))
970 goto no_server;
972 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
974 ret = afs_fs_extend_lock(server, key, vnode, &afs_sync_call);
976 } while (!afs_volume_release_fileserver(vnode, server, ret));
978 /* adjust the flags */
979 if (ret == 0)
980 afs_put_server(server);
982 _leave(" = %d", ret);
983 return ret;
985 no_server:
986 return PTR_ERR(server);
990 * release a lock on a file
992 int afs_vnode_release_lock(struct afs_vnode *vnode, struct key *key)
994 struct afs_server *server;
995 int ret;
997 _enter("%s{%x:%u.%u},%x",
998 vnode->volume->vlocation->vldb.name,
999 vnode->fid.vid,
1000 vnode->fid.vnode,
1001 vnode->fid.unique,
1002 key_serial(key));
1004 do {
1005 /* pick a server to query */
1006 server = afs_volume_pick_fileserver(vnode);
1007 if (IS_ERR(server))
1008 goto no_server;
1010 _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
1012 ret = afs_fs_release_lock(server, key, vnode, &afs_sync_call);
1014 } while (!afs_volume_release_fileserver(vnode, server, ret));
1016 /* adjust the flags */
1017 if (ret == 0)
1018 afs_put_server(server);
1020 _leave(" = %d", ret);
1021 return ret;
1023 no_server:
1024 return PTR_ERR(server);