1 /* dir.c: AFS filesystem directory handling
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
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/pagemap.h>
17 #include <linux/ctype.h>
18 #include <linux/sched.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,
47 .llseek = generic_file_llseek,
50 const struct inode_operations afs_dir_inode_operations = {
55 .symlink = afs_symlink,
59 .permission = afs_permission,
60 .getattr = afs_getattr,
61 .setattr = afs_setattr,
64 static const struct dentry_operations afs_fs_dentry_operations = {
65 .d_revalidate = afs_d_revalidate,
66 .d_delete = afs_d_delete,
67 .d_release = afs_d_release,
70 #define AFS_DIR_HASHTBL_SIZE 128
71 #define AFS_DIR_DIRENT_SIZE 32
72 #define AFS_DIRENT_PER_BLOCK 64
82 uint8_t overflow[4]; /* if any char of the name (inc
83 * NUL) reaches here, consume
84 * the next dirent too */
86 uint8_t extended_name[32];
89 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
90 struct afs_dir_pagehdr {
93 #define AFS_DIR_MAGIC htons(1234)
99 /* directory block layout */
100 union afs_dir_block {
102 struct afs_dir_pagehdr pagehdr;
105 struct afs_dir_pagehdr pagehdr;
106 uint8_t alloc_ctrs[128];
108 uint16_t hashtable[AFS_DIR_HASHTBL_SIZE];
111 union afs_dirent dirents[AFS_DIRENT_PER_BLOCK];
114 /* layout on a linux VM page */
115 struct afs_dir_page {
116 union afs_dir_block blocks[PAGE_SIZE / sizeof(union afs_dir_block)];
119 struct afs_lookup_cookie {
127 * check that a directory page is valid
129 static inline void afs_dir_check_page(struct inode *dir, struct page *page)
131 struct afs_dir_page *dbuf;
136 /* check the page count */
137 qty = desc.size / sizeof(dbuf->blocks[0]);
141 if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) {
142 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
143 __func__, dir->i_ino, qty,
144 ntohs(dbuf->blocks[0].pagehdr.npages));
149 /* determine how many magic numbers there should be in this page */
150 latter = dir->i_size - page_offset(page);
151 if (latter >= PAGE_SIZE)
155 qty /= sizeof(union afs_dir_block);
158 dbuf = page_address(page);
159 for (tmp = 0; tmp < qty; tmp++) {
160 if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) {
161 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
162 __func__, dir->i_ino, tmp, qty,
163 ntohs(dbuf->blocks[tmp].pagehdr.magic));
168 SetPageChecked(page);
172 SetPageChecked(page);
177 * discard a page cached in the pagecache
179 static inline void afs_dir_put_page(struct page *page)
182 page_cache_release(page);
186 * get a page into the pagecache
188 static struct page *afs_dir_get_page(struct inode *dir, unsigned long index,
192 _enter("{%lu},%lu", dir->i_ino, index);
194 page = read_cache_page(dir->i_mapping, index, afs_page_filler, key);
197 if (!PageChecked(page))
198 afs_dir_check_page(dir, page);
205 afs_dir_put_page(page);
207 return ERR_PTR(-EIO);
211 * open an AFS directory file
213 static int afs_dir_open(struct inode *inode, struct file *file)
215 _enter("{%lu}", inode->i_ino);
217 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
218 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
220 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags))
223 return afs_open(inode, file);
227 * deal with one block in an AFS directory
229 static int afs_dir_iterate_block(unsigned *fpos,
230 union afs_dir_block *block,
235 union afs_dirent *dire;
236 unsigned offset, next, curr;
240 _enter("%u,%x,%p,,",*fpos,blkoff,block);
242 curr = (*fpos - blkoff) / sizeof(union afs_dirent);
244 /* walk through the block, an entry at a time */
245 for (offset = AFS_DIRENT_PER_BLOCK - block->pagehdr.nentries;
246 offset < AFS_DIRENT_PER_BLOCK;
251 /* skip entries marked unused in the bitmap */
252 if (!(block->pagehdr.bitmap[offset / 8] &
253 (1 << (offset % 8)))) {
254 _debug("ENT[%Zu.%u]: unused",
255 blkoff / sizeof(union afs_dir_block), offset);
258 next * sizeof(union afs_dirent);
262 /* got a valid entry */
263 dire = &block->dirents[offset];
264 nlen = strnlen(dire->u.name,
266 offset * sizeof(union afs_dirent));
268 _debug("ENT[%Zu.%u]: %s %Zu \"%s\"",
269 blkoff / sizeof(union afs_dir_block), offset,
270 (offset < curr ? "skip" : "fill"),
273 /* work out where the next possible entry is */
274 for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) {
275 if (next >= AFS_DIRENT_PER_BLOCK) {
276 _debug("ENT[%Zu.%u]:"
277 " %u travelled beyond end dir block"
279 blkoff / sizeof(union afs_dir_block),
280 offset, next, tmp, nlen);
283 if (!(block->pagehdr.bitmap[next / 8] &
284 (1 << (next % 8)))) {
285 _debug("ENT[%Zu.%u]:"
286 " %u unmarked extension (len %u/%Zu)",
287 blkoff / sizeof(union afs_dir_block),
288 offset, next, tmp, nlen);
292 _debug("ENT[%Zu.%u]: ext %u/%Zu",
293 blkoff / sizeof(union afs_dir_block),
298 /* skip if starts before the current position */
302 /* found the next entry */
303 ret = filldir(cookie,
306 blkoff + offset * sizeof(union afs_dirent),
307 ntohl(dire->u.vnode),
308 filldir == afs_lookup_filldir ?
309 ntohl(dire->u.unique) : DT_UNKNOWN);
311 _leave(" = 0 [full]");
315 *fpos = blkoff + next * sizeof(union afs_dirent);
318 _leave(" = 1 [more]");
323 * iterate through the data blob that lists the contents of an AFS directory
325 static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
326 filldir_t filldir, struct key *key)
328 union afs_dir_block *dblock;
329 struct afs_dir_page *dbuf;
331 unsigned blkoff, limit;
334 _enter("{%lu},%u,,", dir->i_ino, *fpos);
336 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
337 _leave(" = -ESTALE");
341 /* round the file position up to the next entry boundary */
342 *fpos += sizeof(union afs_dirent) - 1;
343 *fpos &= ~(sizeof(union afs_dirent) - 1);
345 /* walk through the blocks in sequence */
347 while (*fpos < dir->i_size) {
348 blkoff = *fpos & ~(sizeof(union afs_dir_block) - 1);
350 /* fetch the appropriate page from the directory */
351 page = afs_dir_get_page(dir, blkoff / PAGE_SIZE, key);
357 limit = blkoff & ~(PAGE_SIZE - 1);
359 dbuf = page_address(page);
361 /* deal with the individual blocks stashed on this page */
363 dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) /
364 sizeof(union afs_dir_block)];
365 ret = afs_dir_iterate_block(fpos, dblock, blkoff,
368 afs_dir_put_page(page);
372 blkoff += sizeof(union afs_dir_block);
374 } while (*fpos < dir->i_size && blkoff < limit);
376 afs_dir_put_page(page);
381 _leave(" = %d", ret);
386 * read an AFS directory
388 static int afs_readdir(struct file *file, void *cookie, filldir_t filldir)
393 _enter("{%Ld,{%lu}}",
394 file->f_pos, file->f_path.dentry->d_inode->i_ino);
396 ASSERT(file->private_data != NULL);
399 ret = afs_dir_iterate(file->f_path.dentry->d_inode, &fpos,
400 cookie, filldir, file->private_data);
403 _leave(" = %d", ret);
408 * search the directory for a name
409 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
410 * uniquifier through dtype
412 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
413 loff_t fpos, u64 ino, unsigned dtype)
415 struct afs_lookup_cookie *cookie = _cookie;
417 _enter("{%s,%Zu},%s,%u,,%llu,%u",
418 cookie->name, cookie->nlen, name, nlen,
419 (unsigned long long) ino, dtype);
421 /* insanity checks first */
422 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
423 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
425 if (cookie->nlen != nlen || memcmp(cookie->name, name, nlen) != 0) {
430 cookie->fid.vnode = ino;
431 cookie->fid.unique = dtype;
434 _leave(" = -1 [found]");
439 * do a lookup in a directory
440 * - just returns the FID the dentry name maps to if found
442 static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
443 struct afs_fid *fid, struct key *key)
445 struct afs_lookup_cookie cookie;
446 struct afs_super_info *as;
450 _enter("{%lu},%p{%s},", dir->i_ino, dentry, dentry->d_name.name);
452 as = dir->i_sb->s_fs_info;
454 /* search the directory */
455 cookie.name = dentry->d_name.name;
456 cookie.nlen = dentry->d_name.len;
457 cookie.fid.vid = as->volume->vid;
461 ret = afs_dir_iterate(dir, &fpos, &cookie, afs_lookup_filldir,
464 _leave(" = %d [iter]", ret);
470 _leave(" = -ENOENT [not found]");
475 _leave(" = 0 { vn=%u u=%u }", fid->vnode, fid->unique);
480 * Try to auto mount the mountpoint with pseudo directory, if the autocell
481 * operation is setted.
483 static struct inode *afs_try_auto_mntpt(
484 int ret, struct dentry *dentry, struct inode *dir, struct key *key,
487 const char *devname = dentry->d_name.name;
488 struct afs_vnode *vnode = AFS_FS_I(dir);
491 _enter("%d, %p{%s}, {%x:%u}, %p",
492 ret, dentry, devname, vnode->fid.vid, vnode->fid.vnode, key);
494 if (ret != -ENOENT ||
495 !test_bit(AFS_VNODE_AUTOCELL, &vnode->flags))
498 inode = afs_iget_autocell(dir, devname, strlen(devname), key);
500 ret = PTR_ERR(inode);
504 *fid = AFS_FS_I(inode)->fid;
505 _leave("= %p", inode);
514 * look up an entry in a directory
516 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
517 struct nameidata *nd)
519 struct afs_vnode *vnode;
525 vnode = AFS_FS_I(dir);
527 _enter("{%x:%u},%p{%s},",
528 vnode->fid.vid, vnode->fid.vnode, dentry, dentry->d_name.name);
530 ASSERTCMP(dentry->d_inode, ==, NULL);
532 if (dentry->d_name.len >= AFSNAMEMAX) {
533 _leave(" = -ENAMETOOLONG");
534 return ERR_PTR(-ENAMETOOLONG);
537 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
538 _leave(" = -ESTALE");
539 return ERR_PTR(-ESTALE);
542 key = afs_request_key(vnode->volume->cell);
544 _leave(" = %ld [key]", PTR_ERR(key));
545 return ERR_CAST(key);
548 ret = afs_validate(vnode, key);
551 _leave(" = %d [val]", ret);
555 ret = afs_do_lookup(dir, dentry, &fid, key);
557 inode = afs_try_auto_mntpt(ret, dentry, dir, key, &fid);
558 if (!IS_ERR(inode)) {
563 ret = PTR_ERR(inode);
565 if (ret == -ENOENT) {
567 _leave(" = NULL [negative]");
570 _leave(" = %d [do]", ret);
573 dentry->d_fsdata = (void *)(unsigned long) vnode->status.data_version;
575 /* instantiate the dentry */
576 inode = afs_iget(dir->i_sb, key, &fid, NULL, NULL);
579 _leave(" = %ld", PTR_ERR(inode));
580 return ERR_CAST(inode);
584 dentry->d_op = &afs_fs_dentry_operations;
586 d_add(dentry, inode);
587 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }",
590 dentry->d_inode->i_ino,
591 (unsigned long long)dentry->d_inode->i_version);
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, struct nameidata *nd)
603 struct afs_vnode *vnode, *dir;
604 struct afs_fid uninitialized_var(fid);
605 struct dentry *parent;
610 vnode = AFS_FS_I(dentry->d_inode);
613 _enter("{v={%x:%u} n=%s fl=%lx},",
614 vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name,
617 _enter("{neg n=%s}", dentry->d_name.name);
619 key = afs_request_key(AFS_FS_S(dentry->d_sb)->volume->cell);
623 /* lock down the parent dentry so we can peer at it */
624 parent = dget_parent(dentry);
625 if (!parent->d_inode)
628 dir = AFS_FS_I(parent->d_inode);
630 /* validate the parent directory */
631 if (test_bit(AFS_VNODE_MODIFIED, &dir->flags))
632 afs_validate(dir, key);
634 if (test_bit(AFS_VNODE_DELETED, &dir->flags)) {
635 _debug("%s: parent dir deleted", dentry->d_name.name);
639 dir_version = (void *) (unsigned long) dir->status.data_version;
640 if (dentry->d_fsdata == dir_version)
641 goto out_valid; /* the dir contents are unchanged */
643 _debug("dir modified");
645 /* search the directory for this vnode */
646 ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
649 /* the filename maps to something */
650 if (!dentry->d_inode)
652 if (is_bad_inode(dentry->d_inode)) {
653 printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
654 parent->d_name.name, dentry->d_name.name);
658 /* if the vnode ID has changed, then the dirent points to a
660 if (fid.vnode != vnode->fid.vnode) {
661 _debug("%s: dirent changed [%u != %u]",
662 dentry->d_name.name, fid.vnode,
667 /* if the vnode ID uniqifier has changed, then the file has
668 * been deleted and replaced, and the original vnode ID has
670 if (fid.unique != vnode->fid.unique) {
671 _debug("%s: file deleted (uq %u -> %u I:%llu)",
672 dentry->d_name.name, fid.unique,
674 (unsigned long long)dentry->d_inode->i_version);
675 spin_lock(&vnode->lock);
676 set_bit(AFS_VNODE_DELETED, &vnode->flags);
677 spin_unlock(&vnode->lock);
683 /* the filename is unknown */
684 _debug("%s: dirent not found", dentry->d_name.name);
690 _debug("failed to iterate dir %s: %d",
691 parent->d_name.name, ret);
696 dentry->d_fsdata = dir_version;
700 _leave(" = 1 [valid]");
703 /* the dirent, if it exists, now points to a different vnode */
705 spin_lock(&dentry->d_lock);
706 dentry->d_flags |= DCACHE_NFSFS_RENAMED;
707 spin_unlock(&dentry->d_lock);
710 if (dentry->d_inode) {
711 /* don't unhash if we have submounts */
712 if (have_submounts(dentry))
716 _debug("dropping dentry %s/%s",
717 parent->d_name.name, dentry->d_name.name);
718 shrink_dcache_parent(dentry);
723 _leave(" = 0 [bad]");
728 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
730 * - called from dput() when d_count is going to 0.
731 * - return 1 to request dentry be unhashed, 0 otherwise
733 static int afs_d_delete(struct dentry *dentry)
735 _enter("%s", dentry->d_name.name);
737 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
740 if (dentry->d_inode &&
741 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags) ||
742 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(dentry->d_inode)->flags)))
745 _leave(" = 0 [keep]");
749 _leave(" = 1 [zap]");
754 * handle dentry release
756 static void afs_d_release(struct dentry *dentry)
758 _enter("%s", dentry->d_name.name);
762 * create a directory on an AFS filesystem
764 static int afs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
766 struct afs_file_status status;
767 struct afs_callback cb;
768 struct afs_server *server;
769 struct afs_vnode *dvnode, *vnode;
775 dvnode = AFS_FS_I(dir);
777 _enter("{%x:%u},{%s},%o",
778 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
781 if (dentry->d_name.len >= AFSNAMEMAX)
784 key = afs_request_key(dvnode->volume->cell);
791 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
792 mode, &fid, &status, &cb, &server);
796 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
798 /* ENOMEM at a really inconvenient time - just abandon the new
799 * directory on the server */
800 ret = PTR_ERR(inode);
804 /* apply the status report we've got for the new vnode */
805 vnode = AFS_FS_I(inode);
806 spin_lock(&vnode->lock);
808 spin_unlock(&vnode->lock);
809 afs_vnode_finalise_status_update(vnode, server);
810 afs_put_server(server);
812 d_instantiate(dentry, inode);
813 if (d_unhashed(dentry)) {
814 _debug("not hashed");
822 afs_put_server(server);
827 _leave(" = %d", ret);
832 * remove a directory from an AFS filesystem
834 static int afs_rmdir(struct inode *dir, struct dentry *dentry)
836 struct afs_vnode *dvnode, *vnode;
840 dvnode = AFS_FS_I(dir);
842 _enter("{%x:%u},{%s}",
843 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
846 if (dentry->d_name.len >= AFSNAMEMAX)
849 key = afs_request_key(dvnode->volume->cell);
855 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, true);
859 if (dentry->d_inode) {
860 vnode = AFS_FS_I(dentry->d_inode);
861 clear_nlink(&vnode->vfs_inode);
862 set_bit(AFS_VNODE_DELETED, &vnode->flags);
863 afs_discard_callback_on_delete(vnode);
873 _leave(" = %d", ret);
878 * remove a file from an AFS filesystem
880 static int afs_unlink(struct inode *dir, struct dentry *dentry)
882 struct afs_vnode *dvnode, *vnode;
886 dvnode = AFS_FS_I(dir);
888 _enter("{%x:%u},{%s}",
889 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
892 if (dentry->d_name.len >= AFSNAMEMAX)
895 key = afs_request_key(dvnode->volume->cell);
901 if (dentry->d_inode) {
902 vnode = AFS_FS_I(dentry->d_inode);
904 /* make sure we have a callback promise on the victim */
905 ret = afs_validate(vnode, key);
910 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, false);
914 if (dentry->d_inode) {
915 /* if the file wasn't deleted due to excess hard links, the
916 * fileserver will break the callback promise on the file - if
917 * it had one - before it returns to us, and if it was deleted,
920 * however, if we didn't have a callback promise outstanding,
921 * or it was outstanding on a different server, then it won't
924 vnode = AFS_FS_I(dentry->d_inode);
925 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
926 _debug("AFS_VNODE_DELETED");
927 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
928 _debug("AFS_VNODE_CB_BROKEN");
929 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
930 ret = afs_validate(vnode, key);
931 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
941 _leave(" = %d", ret);
946 * create a regular file on an AFS filesystem
948 static int afs_create(struct inode *dir, struct dentry *dentry, int mode,
949 struct nameidata *nd)
951 struct afs_file_status status;
952 struct afs_callback cb;
953 struct afs_server *server;
954 struct afs_vnode *dvnode, *vnode;
960 dvnode = AFS_FS_I(dir);
962 _enter("{%x:%u},{%s},%o,",
963 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
966 if (dentry->d_name.len >= AFSNAMEMAX)
969 key = afs_request_key(dvnode->volume->cell);
976 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
977 mode, &fid, &status, &cb, &server);
981 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
983 /* ENOMEM at a really inconvenient time - just abandon the new
984 * directory on the server */
985 ret = PTR_ERR(inode);
989 /* apply the status report we've got for the new vnode */
990 vnode = AFS_FS_I(inode);
991 spin_lock(&vnode->lock);
993 spin_unlock(&vnode->lock);
994 afs_vnode_finalise_status_update(vnode, server);
995 afs_put_server(server);
997 d_instantiate(dentry, inode);
998 if (d_unhashed(dentry)) {
999 _debug("not hashed");
1007 afs_put_server(server);
1012 _leave(" = %d", ret);
1017 * create a hard link between files in an AFS filesystem
1019 static int afs_link(struct dentry *from, struct inode *dir,
1020 struct dentry *dentry)
1022 struct afs_vnode *dvnode, *vnode;
1026 vnode = AFS_FS_I(from->d_inode);
1027 dvnode = AFS_FS_I(dir);
1029 _enter("{%x:%u},{%x:%u},{%s}",
1030 vnode->fid.vid, vnode->fid.vnode,
1031 dvnode->fid.vid, dvnode->fid.vnode,
1032 dentry->d_name.name);
1034 ret = -ENAMETOOLONG;
1035 if (dentry->d_name.len >= AFSNAMEMAX)
1038 key = afs_request_key(dvnode->volume->cell);
1044 ret = afs_vnode_link(dvnode, vnode, key, dentry->d_name.name);
1048 atomic_inc(&vnode->vfs_inode.i_count);
1049 d_instantiate(dentry, &vnode->vfs_inode);
1058 _leave(" = %d", ret);
1063 * create a symlink in an AFS filesystem
1065 static int afs_symlink(struct inode *dir, struct dentry *dentry,
1066 const char *content)
1068 struct afs_file_status status;
1069 struct afs_server *server;
1070 struct afs_vnode *dvnode, *vnode;
1072 struct inode *inode;
1076 dvnode = AFS_FS_I(dir);
1078 _enter("{%x:%u},{%s},%s",
1079 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name,
1082 ret = -ENAMETOOLONG;
1083 if (dentry->d_name.len >= AFSNAMEMAX)
1087 if (strlen(content) >= AFSPATHMAX)
1090 key = afs_request_key(dvnode->volume->cell);
1096 ret = afs_vnode_symlink(dvnode, key, dentry->d_name.name, content,
1097 &fid, &status, &server);
1101 inode = afs_iget(dir->i_sb, key, &fid, &status, NULL);
1102 if (IS_ERR(inode)) {
1103 /* ENOMEM at a really inconvenient time - just abandon the new
1104 * directory on the server */
1105 ret = PTR_ERR(inode);
1109 /* apply the status report we've got for the new vnode */
1110 vnode = AFS_FS_I(inode);
1111 spin_lock(&vnode->lock);
1112 vnode->update_cnt++;
1113 spin_unlock(&vnode->lock);
1114 afs_vnode_finalise_status_update(vnode, server);
1115 afs_put_server(server);
1117 d_instantiate(dentry, inode);
1118 if (d_unhashed(dentry)) {
1119 _debug("not hashed");
1127 afs_put_server(server);
1132 _leave(" = %d", ret);
1137 * rename a file in an AFS filesystem and/or move it between directories
1139 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1140 struct inode *new_dir, struct dentry *new_dentry)
1142 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
1146 vnode = AFS_FS_I(old_dentry->d_inode);
1147 orig_dvnode = AFS_FS_I(old_dir);
1148 new_dvnode = AFS_FS_I(new_dir);
1150 _enter("{%x:%u},{%x:%u},{%x:%u},{%s}",
1151 orig_dvnode->fid.vid, orig_dvnode->fid.vnode,
1152 vnode->fid.vid, vnode->fid.vnode,
1153 new_dvnode->fid.vid, new_dvnode->fid.vnode,
1154 new_dentry->d_name.name);
1156 ret = -ENAMETOOLONG;
1157 if (new_dentry->d_name.len >= AFSNAMEMAX)
1160 key = afs_request_key(orig_dvnode->volume->cell);
1166 ret = afs_vnode_rename(orig_dvnode, new_dvnode, key,
1167 old_dentry->d_name.name,
1168 new_dentry->d_name.name);
1179 _leave(" = %d", ret);