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>
16 #include <linux/namei.h>
17 #include <linux/pagemap.h>
18 #include <linux/ctype.h>
19 #include <linux/sched.h>
22 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
24 static int afs_dir_open(struct inode *inode, struct file *file);
25 static int afs_readdir(struct file *file, void *dirent, filldir_t filldir);
26 static int afs_d_revalidate(struct dentry *dentry, unsigned int flags);
27 static int afs_d_delete(const struct dentry *dentry);
28 static void afs_d_release(struct dentry *dentry);
29 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
30 loff_t fpos, u64 ino, unsigned dtype);
31 static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
33 static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
34 static int afs_rmdir(struct inode *dir, struct dentry *dentry);
35 static int afs_unlink(struct inode *dir, struct dentry *dentry);
36 static int afs_link(struct dentry *from, struct inode *dir,
37 struct dentry *dentry);
38 static int afs_symlink(struct inode *dir, struct dentry *dentry,
40 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
41 struct inode *new_dir, struct dentry *new_dentry);
43 const struct file_operations afs_dir_file_operations = {
45 .release = afs_release,
46 .readdir = afs_readdir,
48 .llseek = generic_file_llseek,
51 const struct inode_operations afs_dir_inode_operations = {
56 .symlink = afs_symlink,
60 .permission = afs_permission,
61 .getattr = afs_getattr,
62 .setattr = afs_setattr,
65 const struct dentry_operations afs_fs_dentry_operations = {
66 .d_revalidate = afs_d_revalidate,
67 .d_delete = afs_d_delete,
68 .d_release = afs_d_release,
69 .d_automount = afs_d_automount,
72 #define AFS_DIR_HASHTBL_SIZE 128
73 #define AFS_DIR_DIRENT_SIZE 32
74 #define AFS_DIRENT_PER_BLOCK 64
84 uint8_t overflow[4]; /* if any char of the name (inc
85 * NUL) reaches here, consume
86 * the next dirent too */
88 uint8_t extended_name[32];
91 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
92 struct afs_dir_pagehdr {
95 #define AFS_DIR_MAGIC htons(1234)
101 /* directory block layout */
102 union afs_dir_block {
104 struct afs_dir_pagehdr pagehdr;
107 struct afs_dir_pagehdr pagehdr;
108 uint8_t alloc_ctrs[128];
110 uint16_t hashtable[AFS_DIR_HASHTBL_SIZE];
113 union afs_dirent dirents[AFS_DIRENT_PER_BLOCK];
116 /* layout on a linux VM page */
117 struct afs_dir_page {
118 union afs_dir_block blocks[PAGE_SIZE / sizeof(union afs_dir_block)];
121 struct afs_lookup_cookie {
129 * check that a directory page is valid
131 static inline void afs_dir_check_page(struct inode *dir, struct page *page)
133 struct afs_dir_page *dbuf;
138 /* check the page count */
139 qty = desc.size / sizeof(dbuf->blocks[0]);
143 if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) {
144 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
145 __func__, dir->i_ino, qty,
146 ntohs(dbuf->blocks[0].pagehdr.npages));
151 /* determine how many magic numbers there should be in this page */
152 latter = dir->i_size - page_offset(page);
153 if (latter >= PAGE_SIZE)
157 qty /= sizeof(union afs_dir_block);
160 dbuf = page_address(page);
161 for (tmp = 0; tmp < qty; tmp++) {
162 if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) {
163 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
164 __func__, dir->i_ino, tmp, qty,
165 ntohs(dbuf->blocks[tmp].pagehdr.magic));
170 SetPageChecked(page);
174 SetPageChecked(page);
179 * discard a page cached in the pagecache
181 static inline void afs_dir_put_page(struct page *page)
184 page_cache_release(page);
188 * get a page into the pagecache
190 static struct page *afs_dir_get_page(struct inode *dir, unsigned long index,
194 _enter("{%lu},%lu", dir->i_ino, index);
196 page = read_cache_page(dir->i_mapping, index, afs_page_filler, key);
199 if (!PageChecked(page))
200 afs_dir_check_page(dir, page);
207 afs_dir_put_page(page);
209 return ERR_PTR(-EIO);
213 * open an AFS directory file
215 static int afs_dir_open(struct inode *inode, struct file *file)
217 _enter("{%lu}", inode->i_ino);
219 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
220 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
222 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags))
225 return afs_open(inode, file);
229 * deal with one block in an AFS directory
231 static int afs_dir_iterate_block(unsigned *fpos,
232 union afs_dir_block *block,
237 union afs_dirent *dire;
238 unsigned offset, next, curr;
242 _enter("%u,%x,%p,,",*fpos,blkoff,block);
244 curr = (*fpos - blkoff) / sizeof(union afs_dirent);
246 /* walk through the block, an entry at a time */
247 for (offset = AFS_DIRENT_PER_BLOCK - block->pagehdr.nentries;
248 offset < AFS_DIRENT_PER_BLOCK;
253 /* skip entries marked unused in the bitmap */
254 if (!(block->pagehdr.bitmap[offset / 8] &
255 (1 << (offset % 8)))) {
256 _debug("ENT[%Zu.%u]: unused",
257 blkoff / sizeof(union afs_dir_block), offset);
260 next * sizeof(union afs_dirent);
264 /* got a valid entry */
265 dire = &block->dirents[offset];
266 nlen = strnlen(dire->u.name,
268 offset * sizeof(union afs_dirent));
270 _debug("ENT[%Zu.%u]: %s %Zu \"%s\"",
271 blkoff / sizeof(union afs_dir_block), offset,
272 (offset < curr ? "skip" : "fill"),
275 /* work out where the next possible entry is */
276 for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) {
277 if (next >= AFS_DIRENT_PER_BLOCK) {
278 _debug("ENT[%Zu.%u]:"
279 " %u travelled beyond end dir block"
281 blkoff / sizeof(union afs_dir_block),
282 offset, next, tmp, nlen);
285 if (!(block->pagehdr.bitmap[next / 8] &
286 (1 << (next % 8)))) {
287 _debug("ENT[%Zu.%u]:"
288 " %u unmarked extension (len %u/%Zu)",
289 blkoff / sizeof(union afs_dir_block),
290 offset, next, tmp, nlen);
294 _debug("ENT[%Zu.%u]: ext %u/%Zu",
295 blkoff / sizeof(union afs_dir_block),
300 /* skip if starts before the current position */
304 /* found the next entry */
305 ret = filldir(cookie,
308 blkoff + offset * sizeof(union afs_dirent),
309 ntohl(dire->u.vnode),
310 filldir == afs_lookup_filldir ?
311 ntohl(dire->u.unique) : DT_UNKNOWN);
313 _leave(" = 0 [full]");
317 *fpos = blkoff + next * sizeof(union afs_dirent);
320 _leave(" = 1 [more]");
325 * iterate through the data blob that lists the contents of an AFS directory
327 static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
328 filldir_t filldir, struct key *key)
330 union afs_dir_block *dblock;
331 struct afs_dir_page *dbuf;
333 unsigned blkoff, limit;
336 _enter("{%lu},%u,,", dir->i_ino, *fpos);
338 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
339 _leave(" = -ESTALE");
343 /* round the file position up to the next entry boundary */
344 *fpos += sizeof(union afs_dirent) - 1;
345 *fpos &= ~(sizeof(union afs_dirent) - 1);
347 /* walk through the blocks in sequence */
349 while (*fpos < dir->i_size) {
350 blkoff = *fpos & ~(sizeof(union afs_dir_block) - 1);
352 /* fetch the appropriate page from the directory */
353 page = afs_dir_get_page(dir, blkoff / PAGE_SIZE, key);
359 limit = blkoff & ~(PAGE_SIZE - 1);
361 dbuf = page_address(page);
363 /* deal with the individual blocks stashed on this page */
365 dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) /
366 sizeof(union afs_dir_block)];
367 ret = afs_dir_iterate_block(fpos, dblock, blkoff,
370 afs_dir_put_page(page);
374 blkoff += sizeof(union afs_dir_block);
376 } while (*fpos < dir->i_size && blkoff < limit);
378 afs_dir_put_page(page);
383 _leave(" = %d", ret);
388 * read an AFS directory
390 static int afs_readdir(struct file *file, void *cookie, filldir_t filldir)
395 _enter("{%Ld,{%lu}}",
396 file->f_pos, file->f_path.dentry->d_inode->i_ino);
398 ASSERT(file->private_data != NULL);
401 ret = afs_dir_iterate(file->f_path.dentry->d_inode, &fpos,
402 cookie, filldir, file->private_data);
405 _leave(" = %d", ret);
410 * search the directory for a name
411 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
412 * uniquifier through dtype
414 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
415 loff_t fpos, u64 ino, unsigned dtype)
417 struct afs_lookup_cookie *cookie = _cookie;
419 _enter("{%s,%Zu},%s,%u,,%llu,%u",
420 cookie->name, cookie->nlen, name, nlen,
421 (unsigned long long) ino, dtype);
423 /* insanity checks first */
424 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
425 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
427 if (cookie->nlen != nlen || memcmp(cookie->name, name, nlen) != 0) {
432 cookie->fid.vnode = ino;
433 cookie->fid.unique = dtype;
436 _leave(" = -1 [found]");
441 * do a lookup in a directory
442 * - just returns the FID the dentry name maps to if found
444 static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
445 struct afs_fid *fid, struct key *key)
447 struct afs_lookup_cookie cookie;
448 struct afs_super_info *as;
452 _enter("{%lu},%p{%s},", dir->i_ino, dentry, dentry->d_name.name);
454 as = dir->i_sb->s_fs_info;
456 /* search the directory */
457 cookie.name = dentry->d_name.name;
458 cookie.nlen = dentry->d_name.len;
459 cookie.fid.vid = as->volume->vid;
463 ret = afs_dir_iterate(dir, &fpos, &cookie, afs_lookup_filldir,
466 _leave(" = %d [iter]", ret);
472 _leave(" = -ENOENT [not found]");
477 _leave(" = 0 { vn=%u u=%u }", fid->vnode, fid->unique);
482 * Try to auto mount the mountpoint with pseudo directory, if the autocell
483 * operation is setted.
485 static struct inode *afs_try_auto_mntpt(
486 int ret, struct dentry *dentry, struct inode *dir, struct key *key,
489 const char *devname = dentry->d_name.name;
490 struct afs_vnode *vnode = AFS_FS_I(dir);
493 _enter("%d, %p{%s}, {%x:%u}, %p",
494 ret, dentry, devname, vnode->fid.vid, vnode->fid.vnode, key);
496 if (ret != -ENOENT ||
497 !test_bit(AFS_VNODE_AUTOCELL, &vnode->flags))
500 inode = afs_iget_autocell(dir, devname, strlen(devname), key);
502 ret = PTR_ERR(inode);
506 *fid = AFS_FS_I(inode)->fid;
507 _leave("= %p", inode);
516 * look up an entry in a directory
518 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
521 struct afs_vnode *vnode;
527 vnode = AFS_FS_I(dir);
529 _enter("{%x:%u},%p{%s},",
530 vnode->fid.vid, vnode->fid.vnode, dentry, dentry->d_name.name);
532 ASSERTCMP(dentry->d_inode, ==, NULL);
534 if (dentry->d_name.len >= AFSNAMEMAX) {
535 _leave(" = -ENAMETOOLONG");
536 return ERR_PTR(-ENAMETOOLONG);
539 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
540 _leave(" = -ESTALE");
541 return ERR_PTR(-ESTALE);
544 key = afs_request_key(vnode->volume->cell);
546 _leave(" = %ld [key]", PTR_ERR(key));
547 return ERR_CAST(key);
550 ret = afs_validate(vnode, key);
553 _leave(" = %d [val]", ret);
557 ret = afs_do_lookup(dir, dentry, &fid, key);
559 inode = afs_try_auto_mntpt(ret, dentry, dir, key, &fid);
560 if (!IS_ERR(inode)) {
565 ret = PTR_ERR(inode);
567 if (ret == -ENOENT) {
569 _leave(" = NULL [negative]");
572 _leave(" = %d [do]", ret);
575 dentry->d_fsdata = (void *)(unsigned long) vnode->status.data_version;
577 /* instantiate the dentry */
578 inode = afs_iget(dir->i_sb, key, &fid, NULL, NULL);
581 _leave(" = %ld", PTR_ERR(inode));
582 return ERR_CAST(inode);
586 d_add(dentry, inode);
587 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%u }",
590 dentry->d_inode->i_ino,
591 dentry->d_inode->i_generation);
597 * check that a dentry lookup hit has found a valid entry
598 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
601 static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
603 struct afs_vnode *vnode, *dir;
604 struct afs_fid uninitialized_var(fid);
605 struct dentry *parent;
610 if (flags & LOOKUP_RCU)
613 vnode = AFS_FS_I(dentry->d_inode);
616 _enter("{v={%x:%u} n=%s fl=%lx},",
617 vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name,
620 _enter("{neg n=%s}", dentry->d_name.name);
622 key = afs_request_key(AFS_FS_S(dentry->d_sb)->volume->cell);
626 /* lock down the parent dentry so we can peer at it */
627 parent = dget_parent(dentry);
628 if (!parent->d_inode)
631 dir = AFS_FS_I(parent->d_inode);
633 /* validate the parent directory */
634 if (test_bit(AFS_VNODE_MODIFIED, &dir->flags))
635 afs_validate(dir, key);
637 if (test_bit(AFS_VNODE_DELETED, &dir->flags)) {
638 _debug("%s: parent dir deleted", dentry->d_name.name);
642 dir_version = (void *) (unsigned long) dir->status.data_version;
643 if (dentry->d_fsdata == dir_version)
644 goto out_valid; /* the dir contents are unchanged */
646 _debug("dir modified");
648 /* search the directory for this vnode */
649 ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
652 /* the filename maps to something */
653 if (!dentry->d_inode)
655 if (is_bad_inode(dentry->d_inode)) {
656 printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
657 parent->d_name.name, dentry->d_name.name);
661 /* if the vnode ID has changed, then the dirent points to a
663 if (fid.vnode != vnode->fid.vnode) {
664 _debug("%s: dirent changed [%u != %u]",
665 dentry->d_name.name, fid.vnode,
670 /* if the vnode ID uniqifier has changed, then the file has
671 * been deleted and replaced, and the original vnode ID has
673 if (fid.unique != vnode->fid.unique) {
674 _debug("%s: file deleted (uq %u -> %u I:%u)",
675 dentry->d_name.name, fid.unique,
677 dentry->d_inode->i_generation);
678 spin_lock(&vnode->lock);
679 set_bit(AFS_VNODE_DELETED, &vnode->flags);
680 spin_unlock(&vnode->lock);
686 /* the filename is unknown */
687 _debug("%s: dirent not found", dentry->d_name.name);
693 _debug("failed to iterate dir %s: %d",
694 parent->d_name.name, ret);
699 dentry->d_fsdata = dir_version;
703 _leave(" = 1 [valid]");
706 /* the dirent, if it exists, now points to a different vnode */
708 spin_lock(&dentry->d_lock);
709 dentry->d_flags |= DCACHE_NFSFS_RENAMED;
710 spin_unlock(&dentry->d_lock);
713 if (dentry->d_inode) {
714 /* don't unhash if we have submounts */
715 if (have_submounts(dentry))
719 _debug("dropping dentry %s/%s",
720 parent->d_name.name, dentry->d_name.name);
721 shrink_dcache_parent(dentry);
726 _leave(" = 0 [bad]");
731 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
733 * - called from dput() when d_count is going to 0.
734 * - return 1 to request dentry be unhashed, 0 otherwise
736 static int afs_d_delete(const struct dentry *dentry)
738 _enter("%s", dentry->d_name.name);
740 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
743 if (dentry->d_inode &&
744 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags) ||
745 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(dentry->d_inode)->flags)))
748 _leave(" = 0 [keep]");
752 _leave(" = 1 [zap]");
757 * handle dentry release
759 static void afs_d_release(struct dentry *dentry)
761 _enter("%s", dentry->d_name.name);
765 * create a directory on an AFS filesystem
767 static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
769 struct afs_file_status status;
770 struct afs_callback cb;
771 struct afs_server *server;
772 struct afs_vnode *dvnode, *vnode;
778 dvnode = AFS_FS_I(dir);
780 _enter("{%x:%u},{%s},%ho",
781 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
784 if (dentry->d_name.len >= AFSNAMEMAX)
787 key = afs_request_key(dvnode->volume->cell);
794 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
795 mode, &fid, &status, &cb, &server);
799 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
801 /* ENOMEM at a really inconvenient time - just abandon the new
802 * directory on the server */
803 ret = PTR_ERR(inode);
807 /* apply the status report we've got for the new vnode */
808 vnode = AFS_FS_I(inode);
809 spin_lock(&vnode->lock);
811 spin_unlock(&vnode->lock);
812 afs_vnode_finalise_status_update(vnode, server);
813 afs_put_server(server);
815 d_instantiate(dentry, inode);
816 if (d_unhashed(dentry)) {
817 _debug("not hashed");
825 afs_put_server(server);
830 _leave(" = %d", ret);
835 * remove a directory from an AFS filesystem
837 static int afs_rmdir(struct inode *dir, struct dentry *dentry)
839 struct afs_vnode *dvnode, *vnode;
843 dvnode = AFS_FS_I(dir);
845 _enter("{%x:%u},{%s}",
846 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
849 if (dentry->d_name.len >= AFSNAMEMAX)
852 key = afs_request_key(dvnode->volume->cell);
858 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, true);
862 if (dentry->d_inode) {
863 vnode = AFS_FS_I(dentry->d_inode);
864 clear_nlink(&vnode->vfs_inode);
865 set_bit(AFS_VNODE_DELETED, &vnode->flags);
866 afs_discard_callback_on_delete(vnode);
876 _leave(" = %d", ret);
881 * remove a file from an AFS filesystem
883 static int afs_unlink(struct inode *dir, struct dentry *dentry)
885 struct afs_vnode *dvnode, *vnode;
889 dvnode = AFS_FS_I(dir);
891 _enter("{%x:%u},{%s}",
892 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
895 if (dentry->d_name.len >= AFSNAMEMAX)
898 key = afs_request_key(dvnode->volume->cell);
904 if (dentry->d_inode) {
905 vnode = AFS_FS_I(dentry->d_inode);
907 /* make sure we have a callback promise on the victim */
908 ret = afs_validate(vnode, key);
913 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, false);
917 if (dentry->d_inode) {
918 /* if the file wasn't deleted due to excess hard links, the
919 * fileserver will break the callback promise on the file - if
920 * it had one - before it returns to us, and if it was deleted,
923 * however, if we didn't have a callback promise outstanding,
924 * or it was outstanding on a different server, then it won't
927 vnode = AFS_FS_I(dentry->d_inode);
928 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
929 _debug("AFS_VNODE_DELETED");
930 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
931 _debug("AFS_VNODE_CB_BROKEN");
932 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
933 ret = afs_validate(vnode, key);
934 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
944 _leave(" = %d", ret);
949 * create a regular file on an AFS filesystem
951 static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
954 struct afs_file_status status;
955 struct afs_callback cb;
956 struct afs_server *server;
957 struct afs_vnode *dvnode, *vnode;
963 dvnode = AFS_FS_I(dir);
965 _enter("{%x:%u},{%s},%ho,",
966 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
969 if (dentry->d_name.len >= AFSNAMEMAX)
972 key = afs_request_key(dvnode->volume->cell);
979 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
980 mode, &fid, &status, &cb, &server);
984 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
986 /* ENOMEM at a really inconvenient time - just abandon the new
987 * directory on the server */
988 ret = PTR_ERR(inode);
992 /* apply the status report we've got for the new vnode */
993 vnode = AFS_FS_I(inode);
994 spin_lock(&vnode->lock);
996 spin_unlock(&vnode->lock);
997 afs_vnode_finalise_status_update(vnode, server);
998 afs_put_server(server);
1000 d_instantiate(dentry, inode);
1001 if (d_unhashed(dentry)) {
1002 _debug("not hashed");
1010 afs_put_server(server);
1015 _leave(" = %d", ret);
1020 * create a hard link between files in an AFS filesystem
1022 static int afs_link(struct dentry *from, struct inode *dir,
1023 struct dentry *dentry)
1025 struct afs_vnode *dvnode, *vnode;
1029 vnode = AFS_FS_I(from->d_inode);
1030 dvnode = AFS_FS_I(dir);
1032 _enter("{%x:%u},{%x:%u},{%s}",
1033 vnode->fid.vid, vnode->fid.vnode,
1034 dvnode->fid.vid, dvnode->fid.vnode,
1035 dentry->d_name.name);
1037 ret = -ENAMETOOLONG;
1038 if (dentry->d_name.len >= AFSNAMEMAX)
1041 key = afs_request_key(dvnode->volume->cell);
1047 ret = afs_vnode_link(dvnode, vnode, key, dentry->d_name.name);
1051 ihold(&vnode->vfs_inode);
1052 d_instantiate(dentry, &vnode->vfs_inode);
1061 _leave(" = %d", ret);
1066 * create a symlink in an AFS filesystem
1068 static int afs_symlink(struct inode *dir, struct dentry *dentry,
1069 const char *content)
1071 struct afs_file_status status;
1072 struct afs_server *server;
1073 struct afs_vnode *dvnode, *vnode;
1075 struct inode *inode;
1079 dvnode = AFS_FS_I(dir);
1081 _enter("{%x:%u},{%s},%s",
1082 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name,
1085 ret = -ENAMETOOLONG;
1086 if (dentry->d_name.len >= AFSNAMEMAX)
1090 if (strlen(content) >= AFSPATHMAX)
1093 key = afs_request_key(dvnode->volume->cell);
1099 ret = afs_vnode_symlink(dvnode, key, dentry->d_name.name, content,
1100 &fid, &status, &server);
1104 inode = afs_iget(dir->i_sb, key, &fid, &status, NULL);
1105 if (IS_ERR(inode)) {
1106 /* ENOMEM at a really inconvenient time - just abandon the new
1107 * directory on the server */
1108 ret = PTR_ERR(inode);
1112 /* apply the status report we've got for the new vnode */
1113 vnode = AFS_FS_I(inode);
1114 spin_lock(&vnode->lock);
1115 vnode->update_cnt++;
1116 spin_unlock(&vnode->lock);
1117 afs_vnode_finalise_status_update(vnode, server);
1118 afs_put_server(server);
1120 d_instantiate(dentry, inode);
1121 if (d_unhashed(dentry)) {
1122 _debug("not hashed");
1130 afs_put_server(server);
1135 _leave(" = %d", ret);
1140 * rename a file in an AFS filesystem and/or move it between directories
1142 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1143 struct inode *new_dir, struct dentry *new_dentry)
1145 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
1149 vnode = AFS_FS_I(old_dentry->d_inode);
1150 orig_dvnode = AFS_FS_I(old_dir);
1151 new_dvnode = AFS_FS_I(new_dir);
1153 _enter("{%x:%u},{%x:%u},{%x:%u},{%s}",
1154 orig_dvnode->fid.vid, orig_dvnode->fid.vnode,
1155 vnode->fid.vid, vnode->fid.vnode,
1156 new_dvnode->fid.vid, new_dvnode->fid.vnode,
1157 new_dentry->d_name.name);
1159 ret = -ENAMETOOLONG;
1160 if (new_dentry->d_name.len >= AFSNAMEMAX)
1163 key = afs_request_key(orig_dvnode->volume->cell);
1169 ret = afs_vnode_rename(orig_dvnode, new_dvnode, key,
1170 old_dentry->d_name.name,
1171 new_dentry->d_name.name);
1182 _leave(" = %d", ret);