1 /* dir.c: AFS filesystem directory handling
3 * Copyright (C) 2002 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/slab.h>
17 #include <linux/pagemap.h>
18 #include <linux/ctype.h>
21 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
22 struct nameidata
*nd
);
23 static int afs_dir_open(struct inode
*inode
, struct file
*file
);
24 static int afs_readdir(struct file
*file
, void *dirent
, filldir_t filldir
);
25 static int afs_d_revalidate(struct dentry
*dentry
, struct nameidata
*nd
);
26 static int afs_d_delete(struct dentry
*dentry
);
27 static void afs_d_release(struct dentry
*dentry
);
28 static int afs_lookup_filldir(void *_cookie
, const char *name
, int nlen
,
29 loff_t fpos
, u64 ino
, unsigned dtype
);
30 static int afs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
31 struct nameidata
*nd
);
32 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
);
33 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
);
34 static int afs_unlink(struct inode
*dir
, struct dentry
*dentry
);
35 static int afs_link(struct dentry
*from
, struct inode
*dir
,
36 struct dentry
*dentry
);
37 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
39 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
40 struct inode
*new_dir
, struct dentry
*new_dentry
);
42 const struct file_operations afs_dir_file_operations
= {
44 .release
= afs_release
,
45 .readdir
= afs_readdir
,
48 const struct inode_operations afs_dir_inode_operations
= {
53 .symlink
= afs_symlink
,
57 .permission
= afs_permission
,
58 .getattr
= afs_inode_getattr
,
61 static struct dentry_operations afs_fs_dentry_operations
= {
62 .d_revalidate
= afs_d_revalidate
,
63 .d_delete
= afs_d_delete
,
64 .d_release
= afs_d_release
,
67 #define AFS_DIR_HASHTBL_SIZE 128
68 #define AFS_DIR_DIRENT_SIZE 32
69 #define AFS_DIRENT_PER_BLOCK 64
79 uint8_t overflow
[4]; /* if any char of the name (inc
80 * NUL) reaches here, consume
81 * the next dirent too */
83 uint8_t extended_name
[32];
86 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
87 struct afs_dir_pagehdr
{
90 #define AFS_DIR_MAGIC htons(1234)
96 /* directory block layout */
99 struct afs_dir_pagehdr pagehdr
;
102 struct afs_dir_pagehdr pagehdr
;
103 uint8_t alloc_ctrs
[128];
105 uint16_t hashtable
[AFS_DIR_HASHTBL_SIZE
];
108 union afs_dirent dirents
[AFS_DIRENT_PER_BLOCK
];
111 /* layout on a linux VM page */
112 struct afs_dir_page
{
113 union afs_dir_block blocks
[PAGE_SIZE
/ sizeof(union afs_dir_block
)];
116 struct afs_lookup_cookie
{
124 * check that a directory page is valid
126 static inline void afs_dir_check_page(struct inode
*dir
, struct page
*page
)
128 struct afs_dir_page
*dbuf
;
133 /* check the page count */
134 qty
= desc
.size
/ sizeof(dbuf
->blocks
[0]);
138 if (page
->index
== 0 && qty
!= ntohs(dbuf
->blocks
[0].pagehdr
.npages
)) {
139 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
140 __FUNCTION__
, dir
->i_ino
, qty
,
141 ntohs(dbuf
->blocks
[0].pagehdr
.npages
));
146 /* determine how many magic numbers there should be in this page */
147 latter
= dir
->i_size
- page_offset(page
);
148 if (latter
>= PAGE_SIZE
)
152 qty
/= sizeof(union afs_dir_block
);
155 dbuf
= page_address(page
);
156 for (tmp
= 0; tmp
< qty
; tmp
++) {
157 if (dbuf
->blocks
[tmp
].pagehdr
.magic
!= AFS_DIR_MAGIC
) {
158 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
159 __FUNCTION__
, dir
->i_ino
, tmp
, qty
,
160 ntohs(dbuf
->blocks
[tmp
].pagehdr
.magic
));
165 SetPageChecked(page
);
169 SetPageChecked(page
);
174 * discard a page cached in the pagecache
176 static inline void afs_dir_put_page(struct page
*page
)
179 page_cache_release(page
);
183 * get a page into the pagecache
185 static struct page
*afs_dir_get_page(struct inode
*dir
, unsigned long index
,
193 _enter("{%lu},%lu", dir
->i_ino
, index
);
195 page
= read_mapping_page(dir
->i_mapping
, index
, &file
);
197 wait_on_page_locked(page
);
199 if (!PageUptodate(page
))
201 if (!PageChecked(page
))
202 afs_dir_check_page(dir
, page
);
209 afs_dir_put_page(page
);
211 return ERR_PTR(-EIO
);
215 * open an AFS directory file
217 static int afs_dir_open(struct inode
*inode
, struct file
*file
)
219 _enter("{%lu}", inode
->i_ino
);
221 BUILD_BUG_ON(sizeof(union afs_dir_block
) != 2048);
222 BUILD_BUG_ON(sizeof(union afs_dirent
) != 32);
224 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(inode
)->flags
))
227 return afs_open(inode
, file
);
231 * deal with one block in an AFS directory
233 static int afs_dir_iterate_block(unsigned *fpos
,
234 union afs_dir_block
*block
,
239 union afs_dirent
*dire
;
240 unsigned offset
, next
, curr
;
244 _enter("%u,%x,%p,,",*fpos
,blkoff
,block
);
246 curr
= (*fpos
- blkoff
) / sizeof(union afs_dirent
);
248 /* walk through the block, an entry at a time */
249 for (offset
= AFS_DIRENT_PER_BLOCK
- block
->pagehdr
.nentries
;
250 offset
< AFS_DIRENT_PER_BLOCK
;
255 /* skip entries marked unused in the bitmap */
256 if (!(block
->pagehdr
.bitmap
[offset
/ 8] &
257 (1 << (offset
% 8)))) {
258 _debug("ENT[%Zu.%u]: unused",
259 blkoff
/ sizeof(union afs_dir_block
), offset
);
262 next
* sizeof(union afs_dirent
);
266 /* got a valid entry */
267 dire
= &block
->dirents
[offset
];
268 nlen
= strnlen(dire
->u
.name
,
270 offset
* sizeof(union afs_dirent
));
272 _debug("ENT[%Zu.%u]: %s %Zu \"%s\"",
273 blkoff
/ sizeof(union afs_dir_block
), offset
,
274 (offset
< curr
? "skip" : "fill"),
277 /* work out where the next possible entry is */
278 for (tmp
= nlen
; tmp
> 15; tmp
-= sizeof(union afs_dirent
)) {
279 if (next
>= AFS_DIRENT_PER_BLOCK
) {
280 _debug("ENT[%Zu.%u]:"
281 " %u travelled beyond end dir block"
283 blkoff
/ sizeof(union afs_dir_block
),
284 offset
, next
, tmp
, nlen
);
287 if (!(block
->pagehdr
.bitmap
[next
/ 8] &
288 (1 << (next
% 8)))) {
289 _debug("ENT[%Zu.%u]:"
290 " %u unmarked extension (len %u/%Zu)",
291 blkoff
/ sizeof(union afs_dir_block
),
292 offset
, next
, tmp
, nlen
);
296 _debug("ENT[%Zu.%u]: ext %u/%Zu",
297 blkoff
/ sizeof(union afs_dir_block
),
302 /* skip if starts before the current position */
306 /* found the next entry */
307 ret
= filldir(cookie
,
310 blkoff
+ offset
* sizeof(union afs_dirent
),
311 ntohl(dire
->u
.vnode
),
312 filldir
== afs_lookup_filldir
?
313 ntohl(dire
->u
.unique
) : DT_UNKNOWN
);
315 _leave(" = 0 [full]");
319 *fpos
= blkoff
+ next
* sizeof(union afs_dirent
);
322 _leave(" = 1 [more]");
327 * iterate through the data blob that lists the contents of an AFS directory
329 static int afs_dir_iterate(struct inode
*dir
, unsigned *fpos
, void *cookie
,
330 filldir_t filldir
, struct key
*key
)
332 union afs_dir_block
*dblock
;
333 struct afs_dir_page
*dbuf
;
335 unsigned blkoff
, limit
;
338 _enter("{%lu},%u,,", dir
->i_ino
, *fpos
);
340 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dir
)->flags
)) {
341 _leave(" = -ESTALE");
345 /* round the file position up to the next entry boundary */
346 *fpos
+= sizeof(union afs_dirent
) - 1;
347 *fpos
&= ~(sizeof(union afs_dirent
) - 1);
349 /* walk through the blocks in sequence */
351 while (*fpos
< dir
->i_size
) {
352 blkoff
= *fpos
& ~(sizeof(union afs_dir_block
) - 1);
354 /* fetch the appropriate page from the directory */
355 page
= afs_dir_get_page(dir
, blkoff
/ PAGE_SIZE
, key
);
361 limit
= blkoff
& ~(PAGE_SIZE
- 1);
363 dbuf
= page_address(page
);
365 /* deal with the individual blocks stashed on this page */
367 dblock
= &dbuf
->blocks
[(blkoff
% PAGE_SIZE
) /
368 sizeof(union afs_dir_block
)];
369 ret
= afs_dir_iterate_block(fpos
, dblock
, blkoff
,
372 afs_dir_put_page(page
);
376 blkoff
+= sizeof(union afs_dir_block
);
378 } while (*fpos
< dir
->i_size
&& blkoff
< limit
);
380 afs_dir_put_page(page
);
385 _leave(" = %d", ret
);
390 * read an AFS directory
392 static int afs_readdir(struct file
*file
, void *cookie
, filldir_t filldir
)
397 _enter("{%Ld,{%lu}}",
398 file
->f_pos
, file
->f_path
.dentry
->d_inode
->i_ino
);
400 ASSERT(file
->private_data
!= NULL
);
403 ret
= afs_dir_iterate(file
->f_path
.dentry
->d_inode
, &fpos
,
404 cookie
, filldir
, file
->private_data
);
407 _leave(" = %d", ret
);
412 * search the directory for a name
413 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
414 * uniquifier through dtype
416 static int afs_lookup_filldir(void *_cookie
, const char *name
, int nlen
,
417 loff_t fpos
, u64 ino
, unsigned dtype
)
419 struct afs_lookup_cookie
*cookie
= _cookie
;
421 _enter("{%s,%Zu},%s,%u,,%llu,%u",
422 cookie
->name
, cookie
->nlen
, name
, nlen
,
423 (unsigned long long) ino
, dtype
);
425 /* insanity checks first */
426 BUILD_BUG_ON(sizeof(union afs_dir_block
) != 2048);
427 BUILD_BUG_ON(sizeof(union afs_dirent
) != 32);
429 if (cookie
->nlen
!= nlen
|| memcmp(cookie
->name
, name
, nlen
) != 0) {
434 cookie
->fid
.vnode
= ino
;
435 cookie
->fid
.unique
= dtype
;
438 _leave(" = -1 [found]");
443 * do a lookup in a directory
444 * - just returns the FID the dentry name maps to if found
446 static int afs_do_lookup(struct inode
*dir
, struct dentry
*dentry
,
447 struct afs_fid
*fid
, struct key
*key
)
449 struct afs_lookup_cookie cookie
;
450 struct afs_super_info
*as
;
454 _enter("{%lu},%p{%s},", dir
->i_ino
, dentry
, dentry
->d_name
.name
);
456 as
= dir
->i_sb
->s_fs_info
;
458 /* search the directory */
459 cookie
.name
= dentry
->d_name
.name
;
460 cookie
.nlen
= dentry
->d_name
.len
;
461 cookie
.fid
.vid
= as
->volume
->vid
;
465 ret
= afs_dir_iterate(dir
, &fpos
, &cookie
, afs_lookup_filldir
,
468 _leave(" = %d [iter]", ret
);
474 _leave(" = -ENOENT [not found]");
479 _leave(" = 0 { vn=%u u=%u }", fid
->vnode
, fid
->unique
);
484 * look up an entry in a directory
486 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
487 struct nameidata
*nd
)
489 struct afs_vnode
*vnode
;
495 vnode
= AFS_FS_I(dir
);
497 _enter("{%x:%d},%p{%s},",
498 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
, dentry
->d_name
.name
);
500 ASSERTCMP(dentry
->d_inode
, ==, NULL
);
502 if (dentry
->d_name
.len
> 255) {
503 _leave(" = -ENAMETOOLONG");
504 return ERR_PTR(-ENAMETOOLONG
);
507 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
)) {
508 _leave(" = -ESTALE");
509 return ERR_PTR(-ESTALE
);
512 key
= afs_request_key(vnode
->volume
->cell
);
514 _leave(" = %ld [key]", PTR_ERR(key
));
515 return ERR_PTR(PTR_ERR(key
));
518 ret
= afs_validate(vnode
, key
);
521 _leave(" = %d [val]", ret
);
525 ret
= afs_do_lookup(dir
, dentry
, &fid
, key
);
528 if (ret
== -ENOENT
) {
530 _leave(" = NULL [negative]");
533 _leave(" = %d [do]", ret
);
536 dentry
->d_fsdata
= (void *)(unsigned long) vnode
->status
.data_version
;
538 /* instantiate the dentry */
539 inode
= afs_iget(dir
->i_sb
, key
, &fid
, NULL
, NULL
);
542 _leave(" = %ld", PTR_ERR(inode
));
543 return ERR_PTR(PTR_ERR(inode
));
546 dentry
->d_op
= &afs_fs_dentry_operations
;
548 d_add(dentry
, inode
);
549 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%lu }",
552 dentry
->d_inode
->i_ino
,
553 dentry
->d_inode
->i_version
);
559 * check that a dentry lookup hit has found a valid entry
560 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
563 static int afs_d_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
565 struct afs_vnode
*vnode
, *dir
;
567 struct dentry
*parent
;
572 vnode
= AFS_FS_I(dentry
->d_inode
);
575 _enter("{v={%x:%u} n=%s fl=%lx},",
576 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
->d_name
.name
,
579 _enter("{neg n=%s}", dentry
->d_name
.name
);
581 key
= afs_request_key(AFS_FS_S(dentry
->d_sb
)->volume
->cell
);
585 /* lock down the parent dentry so we can peer at it */
586 parent
= dget_parent(dentry
);
587 if (!parent
->d_inode
)
590 dir
= AFS_FS_I(parent
->d_inode
);
592 /* validate the parent directory */
593 if (test_bit(AFS_VNODE_MODIFIED
, &dir
->flags
))
594 afs_validate(dir
, key
);
596 if (test_bit(AFS_VNODE_DELETED
, &dir
->flags
)) {
597 _debug("%s: parent dir deleted", dentry
->d_name
.name
);
601 dir_version
= (void *) (unsigned long) dir
->status
.data_version
;
602 if (dentry
->d_fsdata
== dir_version
)
603 goto out_valid
; /* the dir contents are unchanged */
605 _debug("dir modified");
607 /* search the directory for this vnode */
608 ret
= afs_do_lookup(&dir
->vfs_inode
, dentry
, &fid
, key
);
611 /* the filename maps to something */
612 if (!dentry
->d_inode
)
614 if (is_bad_inode(dentry
->d_inode
)) {
615 printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
616 parent
->d_name
.name
, dentry
->d_name
.name
);
620 /* if the vnode ID has changed, then the dirent points to a
622 if (fid
.vnode
!= vnode
->fid
.vnode
) {
623 _debug("%s: dirent changed [%u != %u]",
624 dentry
->d_name
.name
, fid
.vnode
,
629 /* if the vnode ID uniqifier has changed, then the file has
630 * been deleted and replaced, and the original vnode ID has
632 if (fid
.unique
!= vnode
->fid
.unique
) {
633 _debug("%s: file deleted (uq %u -> %u I:%lu)",
634 dentry
->d_name
.name
, fid
.unique
,
635 vnode
->fid
.unique
, dentry
->d_inode
->i_version
);
636 spin_lock(&vnode
->lock
);
637 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
638 spin_unlock(&vnode
->lock
);
644 /* the filename is unknown */
645 _debug("%s: dirent not found", dentry
->d_name
.name
);
651 _debug("failed to iterate dir %s: %d",
652 parent
->d_name
.name
, ret
);
657 dentry
->d_fsdata
= dir_version
;
661 _leave(" = 1 [valid]");
664 /* the dirent, if it exists, now points to a different vnode */
666 spin_lock(&dentry
->d_lock
);
667 dentry
->d_flags
|= DCACHE_NFSFS_RENAMED
;
668 spin_unlock(&dentry
->d_lock
);
671 if (dentry
->d_inode
) {
672 /* don't unhash if we have submounts */
673 if (have_submounts(dentry
))
677 _debug("dropping dentry %s/%s",
678 parent
->d_name
.name
, dentry
->d_name
.name
);
679 shrink_dcache_parent(dentry
);
684 _leave(" = 0 [bad]");
689 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
691 * - called from dput() when d_count is going to 0.
692 * - return 1 to request dentry be unhashed, 0 otherwise
694 static int afs_d_delete(struct dentry
*dentry
)
696 _enter("%s", dentry
->d_name
.name
);
698 if (dentry
->d_flags
& DCACHE_NFSFS_RENAMED
)
701 if (dentry
->d_inode
&&
702 test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dentry
->d_inode
)->flags
))
705 _leave(" = 0 [keep]");
709 _leave(" = 1 [zap]");
714 * handle dentry release
716 static void afs_d_release(struct dentry
*dentry
)
718 _enter("%s", dentry
->d_name
.name
);
722 * create a directory on an AFS filesystem
724 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
726 struct afs_file_status status
;
727 struct afs_callback cb
;
728 struct afs_server
*server
;
729 struct afs_vnode
*dvnode
, *vnode
;
735 dvnode
= AFS_FS_I(dir
);
737 _enter("{%x:%d},{%s},%o",
738 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
, mode
);
741 if (dentry
->d_name
.len
> 255)
744 key
= afs_request_key(dvnode
->volume
->cell
);
751 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
752 mode
, &fid
, &status
, &cb
, &server
);
756 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
758 /* ENOMEM at a really inconvenient time - just abandon the new
759 * directory on the server */
760 ret
= PTR_ERR(inode
);
764 /* apply the status report we've got for the new vnode */
765 vnode
= AFS_FS_I(inode
);
766 spin_lock(&vnode
->lock
);
768 spin_unlock(&vnode
->lock
);
769 afs_vnode_finalise_status_update(vnode
, server
);
770 afs_put_server(server
);
772 d_instantiate(dentry
, inode
);
773 if (d_unhashed(dentry
)) {
774 _debug("not hashed");
782 afs_put_server(server
);
787 _leave(" = %d", ret
);
792 * remove a directory from an AFS filesystem
794 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
796 struct afs_vnode
*dvnode
, *vnode
;
800 dvnode
= AFS_FS_I(dir
);
802 _enter("{%x:%d},{%s}",
803 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
);
806 if (dentry
->d_name
.len
> 255)
809 key
= afs_request_key(dvnode
->volume
->cell
);
815 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, true);
819 if (dentry
->d_inode
) {
820 vnode
= AFS_FS_I(dentry
->d_inode
);
821 clear_nlink(&vnode
->vfs_inode
);
822 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
823 afs_discard_callback_on_delete(vnode
);
833 _leave(" = %d", ret
);
838 * remove a file from an AFS filesystem
840 static int afs_unlink(struct inode
*dir
, struct dentry
*dentry
)
842 struct afs_vnode
*dvnode
, *vnode
;
846 dvnode
= AFS_FS_I(dir
);
848 _enter("{%x:%d},{%s}",
849 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
);
852 if (dentry
->d_name
.len
> 255)
855 key
= afs_request_key(dvnode
->volume
->cell
);
861 if (dentry
->d_inode
) {
862 vnode
= AFS_FS_I(dentry
->d_inode
);
864 /* make sure we have a callback promise on the victim */
865 ret
= afs_validate(vnode
, key
);
870 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, false);
874 if (dentry
->d_inode
) {
875 /* if the file wasn't deleted due to excess hard links, the
876 * fileserver will break the callback promise on the file - if
877 * it had one - before it returns to us, and if it was deleted,
880 * however, if we didn't have a callback promise outstanding,
881 * or it was outstanding on a different server, then it won't
884 vnode
= AFS_FS_I(dentry
->d_inode
);
885 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
))
886 _debug("AFS_VNODE_DELETED");
887 if (test_bit(AFS_VNODE_CB_BROKEN
, &vnode
->flags
))
888 _debug("AFS_VNODE_CB_BROKEN");
889 set_bit(AFS_VNODE_CB_BROKEN
, &vnode
->flags
);
890 ret
= afs_validate(vnode
, key
);
891 _debug("nlink %d [val %d]", vnode
->vfs_inode
.i_nlink
, ret
);
901 _leave(" = %d", ret
);
906 * create a regular file on an AFS filesystem
908 static int afs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
909 struct nameidata
*nd
)
911 struct afs_file_status status
;
912 struct afs_callback cb
;
913 struct afs_server
*server
;
914 struct afs_vnode
*dvnode
, *vnode
;
920 dvnode
= AFS_FS_I(dir
);
922 _enter("{%x:%d},{%s},%o,",
923 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
, mode
);
926 if (dentry
->d_name
.len
> 255)
929 key
= afs_request_key(dvnode
->volume
->cell
);
936 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
937 mode
, &fid
, &status
, &cb
, &server
);
941 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
943 /* ENOMEM at a really inconvenient time - just abandon the new
944 * directory on the server */
945 ret
= PTR_ERR(inode
);
949 /* apply the status report we've got for the new vnode */
950 vnode
= AFS_FS_I(inode
);
951 spin_lock(&vnode
->lock
);
953 spin_unlock(&vnode
->lock
);
954 afs_vnode_finalise_status_update(vnode
, server
);
955 afs_put_server(server
);
957 d_instantiate(dentry
, inode
);
958 if (d_unhashed(dentry
)) {
959 _debug("not hashed");
967 afs_put_server(server
);
972 _leave(" = %d", ret
);
977 * create a hard link between files in an AFS filesystem
979 static int afs_link(struct dentry
*from
, struct inode
*dir
,
980 struct dentry
*dentry
)
982 struct afs_vnode
*dvnode
, *vnode
;
986 vnode
= AFS_FS_I(from
->d_inode
);
987 dvnode
= AFS_FS_I(dir
);
989 _enter("{%x:%d},{%x:%d},{%s}",
990 vnode
->fid
.vid
, vnode
->fid
.vnode
,
991 dvnode
->fid
.vid
, dvnode
->fid
.vnode
,
992 dentry
->d_name
.name
);
995 if (dentry
->d_name
.len
> 255)
998 key
= afs_request_key(dvnode
->volume
->cell
);
1004 ret
= afs_vnode_link(dvnode
, vnode
, key
, dentry
->d_name
.name
);
1008 atomic_inc(&vnode
->vfs_inode
.i_count
);
1009 d_instantiate(dentry
, &vnode
->vfs_inode
);
1018 _leave(" = %d", ret
);
1023 * create a symlink in an AFS filesystem
1025 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
1026 const char *content
)
1028 struct afs_file_status status
;
1029 struct afs_server
*server
;
1030 struct afs_vnode
*dvnode
, *vnode
;
1032 struct inode
*inode
;
1036 dvnode
= AFS_FS_I(dir
);
1038 _enter("{%x:%d},{%s},%s",
1039 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
,
1042 ret
= -ENAMETOOLONG
;
1043 if (dentry
->d_name
.len
> 255)
1047 if (strlen(content
) > 1023)
1050 key
= afs_request_key(dvnode
->volume
->cell
);
1056 ret
= afs_vnode_symlink(dvnode
, key
, dentry
->d_name
.name
, content
,
1057 &fid
, &status
, &server
);
1061 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, NULL
);
1062 if (IS_ERR(inode
)) {
1063 /* ENOMEM at a really inconvenient time - just abandon the new
1064 * directory on the server */
1065 ret
= PTR_ERR(inode
);
1069 /* apply the status report we've got for the new vnode */
1070 vnode
= AFS_FS_I(inode
);
1071 spin_lock(&vnode
->lock
);
1072 vnode
->update_cnt
++;
1073 spin_unlock(&vnode
->lock
);
1074 afs_vnode_finalise_status_update(vnode
, server
);
1075 afs_put_server(server
);
1077 d_instantiate(dentry
, inode
);
1078 if (d_unhashed(dentry
)) {
1079 _debug("not hashed");
1087 afs_put_server(server
);
1092 _leave(" = %d", ret
);
1097 * rename a file in an AFS filesystem and/or move it between directories
1099 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1100 struct inode
*new_dir
, struct dentry
*new_dentry
)
1102 struct afs_vnode
*orig_dvnode
, *new_dvnode
, *vnode
;
1106 vnode
= AFS_FS_I(old_dentry
->d_inode
);
1107 orig_dvnode
= AFS_FS_I(old_dir
);
1108 new_dvnode
= AFS_FS_I(new_dir
);
1110 _enter("{%x:%d},{%x:%d},{%x:%d},{%s}",
1111 orig_dvnode
->fid
.vid
, orig_dvnode
->fid
.vnode
,
1112 vnode
->fid
.vid
, vnode
->fid
.vnode
,
1113 new_dvnode
->fid
.vid
, new_dvnode
->fid
.vnode
,
1114 new_dentry
->d_name
.name
);
1116 ret
= -ENAMETOOLONG
;
1117 if (new_dentry
->d_name
.len
> 255)
1120 key
= afs_request_key(orig_dvnode
->volume
->cell
);
1126 ret
= afs_vnode_rename(orig_dvnode
, new_dvnode
, key
,
1127 old_dentry
->d_name
.name
,
1128 new_dentry
->d_name
.name
);
1139 _leave(" = %d", ret
);