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
, struct dir_context
*ctx
);
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(struct dir_context
*ctx
, 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
,
44 const struct file_operations afs_dir_file_operations
= {
46 .release
= afs_release
,
47 .iterate_shared
= afs_readdir
,
49 .llseek
= generic_file_llseek
,
52 const struct inode_operations afs_dir_inode_operations
= {
57 .symlink
= afs_symlink
,
61 .permission
= afs_permission
,
62 .getattr
= afs_getattr
,
63 .setattr
= afs_setattr
,
66 const struct dentry_operations afs_fs_dentry_operations
= {
67 .d_revalidate
= afs_d_revalidate
,
68 .d_delete
= afs_d_delete
,
69 .d_release
= afs_d_release
,
70 .d_automount
= afs_d_automount
,
73 #define AFS_DIR_HASHTBL_SIZE 128
74 #define AFS_DIR_DIRENT_SIZE 32
75 #define AFS_DIRENT_PER_BLOCK 64
85 uint8_t overflow
[4]; /* if any char of the name (inc
86 * NUL) reaches here, consume
87 * the next dirent too */
89 uint8_t extended_name
[32];
92 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
93 struct afs_dir_pagehdr
{
96 #define AFS_DIR_MAGIC htons(1234)
102 /* directory block layout */
103 union afs_dir_block
{
105 struct afs_dir_pagehdr pagehdr
;
108 struct afs_dir_pagehdr pagehdr
;
109 uint8_t alloc_ctrs
[128];
111 uint16_t hashtable
[AFS_DIR_HASHTBL_SIZE
];
114 union afs_dirent dirents
[AFS_DIRENT_PER_BLOCK
];
117 /* layout on a linux VM page */
118 struct afs_dir_page
{
119 union afs_dir_block blocks
[PAGE_SIZE
/ sizeof(union afs_dir_block
)];
122 struct afs_lookup_cookie
{
123 struct dir_context ctx
;
130 * check that a directory page is valid
132 static inline bool afs_dir_check_page(struct inode
*dir
, struct page
*page
)
134 struct afs_dir_page
*dbuf
;
139 /* check the page count */
140 qty
= desc
.size
/ sizeof(dbuf
->blocks
[0]);
144 if (page
->index
== 0 && qty
!= ntohs(dbuf
->blocks
[0].pagehdr
.npages
)) {
145 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
146 __func__
, dir
->i_ino
, qty
,
147 ntohs(dbuf
->blocks
[0].pagehdr
.npages
));
152 /* determine how many magic numbers there should be in this page */
153 latter
= dir
->i_size
- page_offset(page
);
154 if (latter
>= PAGE_SIZE
)
158 qty
/= sizeof(union afs_dir_block
);
161 dbuf
= page_address(page
);
162 for (tmp
= 0; tmp
< qty
; tmp
++) {
163 if (dbuf
->blocks
[tmp
].pagehdr
.magic
!= AFS_DIR_MAGIC
) {
164 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
165 __func__
, dir
->i_ino
, tmp
, qty
,
166 ntohs(dbuf
->blocks
[tmp
].pagehdr
.magic
));
171 SetPageChecked(page
);
180 * discard a page cached in the pagecache
182 static inline void afs_dir_put_page(struct page
*page
)
189 * get a page into the pagecache
191 static struct page
*afs_dir_get_page(struct inode
*dir
, unsigned long index
,
195 _enter("{%lu},%lu", dir
->i_ino
, index
);
197 page
= read_cache_page(dir
->i_mapping
, index
, afs_page_filler
, key
);
200 if (unlikely(!PageChecked(page
))) {
201 if (PageError(page
) || !afs_dir_check_page(dir
, page
))
208 afs_dir_put_page(page
);
210 return ERR_PTR(-EIO
);
214 * open an AFS directory file
216 static int afs_dir_open(struct inode
*inode
, struct file
*file
)
218 _enter("{%lu}", inode
->i_ino
);
220 BUILD_BUG_ON(sizeof(union afs_dir_block
) != 2048);
221 BUILD_BUG_ON(sizeof(union afs_dirent
) != 32);
223 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(inode
)->flags
))
226 return afs_open(inode
, file
);
230 * deal with one block in an AFS directory
232 static int afs_dir_iterate_block(struct dir_context
*ctx
,
233 union afs_dir_block
*block
,
236 union afs_dirent
*dire
;
237 unsigned offset
, next
, curr
;
241 _enter("%u,%x,%p,,",(unsigned)ctx
->pos
,blkoff
,block
);
243 curr
= (ctx
->pos
- blkoff
) / sizeof(union afs_dirent
);
245 /* walk through the block, an entry at a time */
246 for (offset
= AFS_DIRENT_PER_BLOCK
- block
->pagehdr
.nentries
;
247 offset
< AFS_DIRENT_PER_BLOCK
;
252 /* skip entries marked unused in the bitmap */
253 if (!(block
->pagehdr
.bitmap
[offset
/ 8] &
254 (1 << (offset
% 8)))) {
255 _debug("ENT[%zu.%u]: unused",
256 blkoff
/ sizeof(union afs_dir_block
), offset
);
259 next
* sizeof(union afs_dirent
);
263 /* got a valid entry */
264 dire
= &block
->dirents
[offset
];
265 nlen
= strnlen(dire
->u
.name
,
267 offset
* sizeof(union afs_dirent
));
269 _debug("ENT[%zu.%u]: %s %zu \"%s\"",
270 blkoff
/ sizeof(union afs_dir_block
), offset
,
271 (offset
< curr
? "skip" : "fill"),
274 /* work out where the next possible entry is */
275 for (tmp
= nlen
; tmp
> 15; tmp
-= sizeof(union afs_dirent
)) {
276 if (next
>= AFS_DIRENT_PER_BLOCK
) {
277 _debug("ENT[%zu.%u]:"
278 " %u travelled beyond end dir block"
280 blkoff
/ sizeof(union afs_dir_block
),
281 offset
, next
, tmp
, nlen
);
284 if (!(block
->pagehdr
.bitmap
[next
/ 8] &
285 (1 << (next
% 8)))) {
286 _debug("ENT[%zu.%u]:"
287 " %u unmarked extension (len %u/%zu)",
288 blkoff
/ sizeof(union afs_dir_block
),
289 offset
, next
, tmp
, nlen
);
293 _debug("ENT[%zu.%u]: ext %u/%zu",
294 blkoff
/ sizeof(union afs_dir_block
),
299 /* skip if starts before the current position */
303 /* found the next entry */
304 if (!dir_emit(ctx
, dire
->u
.name
, nlen
,
305 ntohl(dire
->u
.vnode
),
306 ctx
->actor
== afs_lookup_filldir
?
307 ntohl(dire
->u
.unique
) : DT_UNKNOWN
)) {
308 _leave(" = 0 [full]");
312 ctx
->pos
= blkoff
+ next
* sizeof(union afs_dirent
);
315 _leave(" = 1 [more]");
320 * iterate through the data blob that lists the contents of an AFS directory
322 static int afs_dir_iterate(struct inode
*dir
, struct dir_context
*ctx
,
325 union afs_dir_block
*dblock
;
326 struct afs_dir_page
*dbuf
;
328 unsigned blkoff
, limit
;
331 _enter("{%lu},%u,,", dir
->i_ino
, (unsigned)ctx
->pos
);
333 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dir
)->flags
)) {
334 _leave(" = -ESTALE");
338 /* round the file position up to the next entry boundary */
339 ctx
->pos
+= sizeof(union afs_dirent
) - 1;
340 ctx
->pos
&= ~(sizeof(union afs_dirent
) - 1);
342 /* walk through the blocks in sequence */
344 while (ctx
->pos
< dir
->i_size
) {
345 blkoff
= ctx
->pos
& ~(sizeof(union afs_dir_block
) - 1);
347 /* fetch the appropriate page from the directory */
348 page
= afs_dir_get_page(dir
, blkoff
/ PAGE_SIZE
, key
);
354 limit
= blkoff
& ~(PAGE_SIZE
- 1);
356 dbuf
= page_address(page
);
358 /* deal with the individual blocks stashed on this page */
360 dblock
= &dbuf
->blocks
[(blkoff
% PAGE_SIZE
) /
361 sizeof(union afs_dir_block
)];
362 ret
= afs_dir_iterate_block(ctx
, dblock
, blkoff
);
364 afs_dir_put_page(page
);
368 blkoff
+= sizeof(union afs_dir_block
);
370 } while (ctx
->pos
< dir
->i_size
&& blkoff
< limit
);
372 afs_dir_put_page(page
);
377 _leave(" = %d", ret
);
382 * read an AFS directory
384 static int afs_readdir(struct file
*file
, struct dir_context
*ctx
)
386 return afs_dir_iterate(file_inode(file
),
387 ctx
, file
->private_data
);
391 * search the directory for a name
392 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
393 * uniquifier through dtype
395 static int afs_lookup_filldir(struct dir_context
*ctx
, const char *name
,
396 int nlen
, loff_t fpos
, u64 ino
, unsigned dtype
)
398 struct afs_lookup_cookie
*cookie
=
399 container_of(ctx
, struct afs_lookup_cookie
, ctx
);
401 _enter("{%s,%u},%s,%u,,%llu,%u",
402 cookie
->name
.name
, cookie
->name
.len
, name
, nlen
,
403 (unsigned long long) ino
, dtype
);
405 /* insanity checks first */
406 BUILD_BUG_ON(sizeof(union afs_dir_block
) != 2048);
407 BUILD_BUG_ON(sizeof(union afs_dirent
) != 32);
409 if (cookie
->name
.len
!= nlen
||
410 memcmp(cookie
->name
.name
, name
, nlen
) != 0) {
415 cookie
->fid
.vnode
= ino
;
416 cookie
->fid
.unique
= dtype
;
419 _leave(" = -1 [found]");
424 * do a lookup in a directory
425 * - just returns the FID the dentry name maps to if found
427 static int afs_do_lookup(struct inode
*dir
, struct dentry
*dentry
,
428 struct afs_fid
*fid
, struct key
*key
)
430 struct afs_super_info
*as
= dir
->i_sb
->s_fs_info
;
431 struct afs_lookup_cookie cookie
= {
432 .ctx
.actor
= afs_lookup_filldir
,
433 .name
= dentry
->d_name
,
434 .fid
.vid
= as
->volume
->vid
438 _enter("{%lu},%p{%pd},", dir
->i_ino
, dentry
, dentry
);
440 /* search the directory */
441 ret
= afs_dir_iterate(dir
, &cookie
.ctx
, key
);
443 _leave(" = %d [iter]", ret
);
449 _leave(" = -ENOENT [not found]");
454 _leave(" = 0 { vn=%u u=%u }", fid
->vnode
, fid
->unique
);
459 * Try to auto mount the mountpoint with pseudo directory, if the autocell
460 * operation is setted.
462 static struct inode
*afs_try_auto_mntpt(
463 int ret
, struct dentry
*dentry
, struct inode
*dir
, struct key
*key
,
466 const char *devname
= dentry
->d_name
.name
;
467 struct afs_vnode
*vnode
= AFS_FS_I(dir
);
470 _enter("%d, %p{%pd}, {%x:%u}, %p",
471 ret
, dentry
, dentry
, vnode
->fid
.vid
, vnode
->fid
.vnode
, key
);
473 if (ret
!= -ENOENT
||
474 !test_bit(AFS_VNODE_AUTOCELL
, &vnode
->flags
))
477 inode
= afs_iget_autocell(dir
, devname
, strlen(devname
), key
);
479 ret
= PTR_ERR(inode
);
483 *fid
= AFS_FS_I(inode
)->fid
;
484 _leave("= %p", inode
);
493 * look up an entry in a directory
495 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
498 struct afs_vnode
*vnode
;
504 vnode
= AFS_FS_I(dir
);
506 _enter("{%x:%u},%p{%pd},",
507 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
, dentry
);
509 ASSERTCMP(d_inode(dentry
), ==, NULL
);
511 if (dentry
->d_name
.len
>= AFSNAMEMAX
) {
512 _leave(" = -ENAMETOOLONG");
513 return ERR_PTR(-ENAMETOOLONG
);
516 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
)) {
517 _leave(" = -ESTALE");
518 return ERR_PTR(-ESTALE
);
521 key
= afs_request_key(vnode
->volume
->cell
);
523 _leave(" = %ld [key]", PTR_ERR(key
));
524 return ERR_CAST(key
);
527 ret
= afs_validate(vnode
, key
);
530 _leave(" = %d [val]", ret
);
534 ret
= afs_do_lookup(dir
, dentry
, &fid
, key
);
536 inode
= afs_try_auto_mntpt(ret
, dentry
, dir
, key
, &fid
);
537 if (!IS_ERR(inode
)) {
542 ret
= PTR_ERR(inode
);
544 if (ret
== -ENOENT
) {
546 _leave(" = NULL [negative]");
549 _leave(" = %d [do]", ret
);
552 dentry
->d_fsdata
= (void *)(unsigned long) vnode
->status
.data_version
;
554 /* instantiate the dentry */
555 inode
= afs_iget(dir
->i_sb
, key
, &fid
, NULL
, NULL
);
558 _leave(" = %ld", PTR_ERR(inode
));
559 return ERR_CAST(inode
);
563 d_add(dentry
, inode
);
564 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%u }",
567 d_inode(dentry
)->i_ino
,
568 d_inode(dentry
)->i_generation
);
574 * check that a dentry lookup hit has found a valid entry
575 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
578 static int afs_d_revalidate(struct dentry
*dentry
, unsigned int flags
)
580 struct afs_vnode
*vnode
, *dir
;
581 struct afs_fid
uninitialized_var(fid
);
582 struct dentry
*parent
;
587 if (flags
& LOOKUP_RCU
)
590 vnode
= AFS_FS_I(d_inode(dentry
));
592 if (d_really_is_positive(dentry
))
593 _enter("{v={%x:%u} n=%pd fl=%lx},",
594 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
,
597 _enter("{neg n=%pd}", dentry
);
599 key
= afs_request_key(AFS_FS_S(dentry
->d_sb
)->volume
->cell
);
603 /* lock down the parent dentry so we can peer at it */
604 parent
= dget_parent(dentry
);
605 dir
= AFS_FS_I(d_inode(parent
));
607 /* validate the parent directory */
608 if (test_bit(AFS_VNODE_MODIFIED
, &dir
->flags
))
609 afs_validate(dir
, key
);
611 if (test_bit(AFS_VNODE_DELETED
, &dir
->flags
)) {
612 _debug("%pd: parent dir deleted", dentry
);
616 dir_version
= (void *) (unsigned long) dir
->status
.data_version
;
617 if (dentry
->d_fsdata
== dir_version
)
618 goto out_valid
; /* the dir contents are unchanged */
620 _debug("dir modified");
622 /* search the directory for this vnode */
623 ret
= afs_do_lookup(&dir
->vfs_inode
, dentry
, &fid
, key
);
626 /* the filename maps to something */
627 if (d_really_is_negative(dentry
))
629 if (is_bad_inode(d_inode(dentry
))) {
630 printk("kAFS: afs_d_revalidate: %pd2 has bad inode\n",
635 /* if the vnode ID has changed, then the dirent points to a
637 if (fid
.vnode
!= vnode
->fid
.vnode
) {
638 _debug("%pd: dirent changed [%u != %u]",
644 /* if the vnode ID uniqifier has changed, then the file has
645 * been deleted and replaced, and the original vnode ID has
647 if (fid
.unique
!= vnode
->fid
.unique
) {
648 _debug("%pd: file deleted (uq %u -> %u I:%u)",
651 d_inode(dentry
)->i_generation
);
652 spin_lock(&vnode
->lock
);
653 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
654 spin_unlock(&vnode
->lock
);
660 /* the filename is unknown */
661 _debug("%pd: dirent not found", dentry
);
662 if (d_really_is_positive(dentry
))
667 _debug("failed to iterate dir %pd: %d",
673 dentry
->d_fsdata
= dir_version
;
676 _leave(" = 1 [valid]");
679 /* the dirent, if it exists, now points to a different vnode */
681 spin_lock(&dentry
->d_lock
);
682 dentry
->d_flags
|= DCACHE_NFSFS_RENAMED
;
683 spin_unlock(&dentry
->d_lock
);
686 _debug("dropping dentry %pd2", dentry
);
690 _leave(" = 0 [bad]");
695 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
697 * - called from dput() when d_count is going to 0.
698 * - return 1 to request dentry be unhashed, 0 otherwise
700 static int afs_d_delete(const struct dentry
*dentry
)
702 _enter("%pd", dentry
);
704 if (dentry
->d_flags
& DCACHE_NFSFS_RENAMED
)
707 if (d_really_is_positive(dentry
) &&
708 (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(d_inode(dentry
))->flags
) ||
709 test_bit(AFS_VNODE_PSEUDODIR
, &AFS_FS_I(d_inode(dentry
))->flags
)))
712 _leave(" = 0 [keep]");
716 _leave(" = 1 [zap]");
721 * handle dentry release
723 static void afs_d_release(struct dentry
*dentry
)
725 _enter("%pd", dentry
);
729 * create a directory on an AFS filesystem
731 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
733 struct afs_file_status status
;
734 struct afs_callback cb
;
735 struct afs_server
*server
;
736 struct afs_vnode
*dvnode
, *vnode
;
742 dvnode
= AFS_FS_I(dir
);
744 _enter("{%x:%u},{%pd},%ho",
745 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, mode
);
747 key
= afs_request_key(dvnode
->volume
->cell
);
754 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
755 mode
, &fid
, &status
, &cb
, &server
);
759 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
761 /* ENOMEM at a really inconvenient time - just abandon the new
762 * directory on the server */
763 ret
= PTR_ERR(inode
);
767 /* apply the status report we've got for the new vnode */
768 vnode
= AFS_FS_I(inode
);
769 spin_lock(&vnode
->lock
);
771 spin_unlock(&vnode
->lock
);
772 afs_vnode_finalise_status_update(vnode
, server
);
773 afs_put_server(server
);
775 d_instantiate(dentry
, inode
);
776 if (d_unhashed(dentry
)) {
777 _debug("not hashed");
785 afs_put_server(server
);
790 _leave(" = %d", ret
);
795 * remove a directory from an AFS filesystem
797 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
799 struct afs_vnode
*dvnode
, *vnode
;
803 dvnode
= AFS_FS_I(dir
);
805 _enter("{%x:%u},{%pd}",
806 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
);
808 key
= afs_request_key(dvnode
->volume
->cell
);
814 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, true);
818 if (d_really_is_positive(dentry
)) {
819 vnode
= AFS_FS_I(d_inode(dentry
));
820 clear_nlink(&vnode
->vfs_inode
);
821 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
822 afs_discard_callback_on_delete(vnode
);
832 _leave(" = %d", ret
);
837 * remove a file from an AFS filesystem
839 static int afs_unlink(struct inode
*dir
, struct dentry
*dentry
)
841 struct afs_vnode
*dvnode
, *vnode
;
845 dvnode
= AFS_FS_I(dir
);
847 _enter("{%x:%u},{%pd}",
848 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
);
851 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
854 key
= afs_request_key(dvnode
->volume
->cell
);
860 if (d_really_is_positive(dentry
)) {
861 vnode
= AFS_FS_I(d_inode(dentry
));
863 /* make sure we have a callback promise on the victim */
864 ret
= afs_validate(vnode
, key
);
869 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, false);
873 if (d_really_is_positive(dentry
)) {
874 /* if the file wasn't deleted due to excess hard links, the
875 * fileserver will break the callback promise on the file - if
876 * it had one - before it returns to us, and if it was deleted,
879 * however, if we didn't have a callback promise outstanding,
880 * or it was outstanding on a different server, then it won't
883 vnode
= AFS_FS_I(d_inode(dentry
));
884 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
))
885 _debug("AFS_VNODE_DELETED");
886 if (test_bit(AFS_VNODE_CB_BROKEN
, &vnode
->flags
))
887 _debug("AFS_VNODE_CB_BROKEN");
888 set_bit(AFS_VNODE_CB_BROKEN
, &vnode
->flags
);
889 ret
= afs_validate(vnode
, key
);
890 _debug("nlink %d [val %d]", vnode
->vfs_inode
.i_nlink
, ret
);
900 _leave(" = %d", ret
);
905 * create a regular file on an AFS filesystem
907 static int afs_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
910 struct afs_file_status status
;
911 struct afs_callback cb
;
912 struct afs_server
*server
;
913 struct afs_vnode
*dvnode
, *vnode
;
919 dvnode
= AFS_FS_I(dir
);
921 _enter("{%x:%u},{%pd},%ho,",
922 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, mode
);
924 key
= afs_request_key(dvnode
->volume
->cell
);
931 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
932 mode
, &fid
, &status
, &cb
, &server
);
936 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
938 /* ENOMEM at a really inconvenient time - just abandon the new
939 * directory on the server */
940 ret
= PTR_ERR(inode
);
944 /* apply the status report we've got for the new vnode */
945 vnode
= AFS_FS_I(inode
);
946 spin_lock(&vnode
->lock
);
948 spin_unlock(&vnode
->lock
);
949 afs_vnode_finalise_status_update(vnode
, server
);
950 afs_put_server(server
);
952 d_instantiate(dentry
, inode
);
953 if (d_unhashed(dentry
)) {
954 _debug("not hashed");
962 afs_put_server(server
);
967 _leave(" = %d", ret
);
972 * create a hard link between files in an AFS filesystem
974 static int afs_link(struct dentry
*from
, struct inode
*dir
,
975 struct dentry
*dentry
)
977 struct afs_vnode
*dvnode
, *vnode
;
981 vnode
= AFS_FS_I(d_inode(from
));
982 dvnode
= AFS_FS_I(dir
);
984 _enter("{%x:%u},{%x:%u},{%pd}",
985 vnode
->fid
.vid
, vnode
->fid
.vnode
,
986 dvnode
->fid
.vid
, dvnode
->fid
.vnode
,
989 key
= afs_request_key(dvnode
->volume
->cell
);
995 ret
= afs_vnode_link(dvnode
, vnode
, key
, dentry
->d_name
.name
);
999 ihold(&vnode
->vfs_inode
);
1000 d_instantiate(dentry
, &vnode
->vfs_inode
);
1009 _leave(" = %d", ret
);
1014 * create a symlink in an AFS filesystem
1016 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
1017 const char *content
)
1019 struct afs_file_status status
;
1020 struct afs_server
*server
;
1021 struct afs_vnode
*dvnode
, *vnode
;
1023 struct inode
*inode
;
1027 dvnode
= AFS_FS_I(dir
);
1029 _enter("{%x:%u},{%pd},%s",
1030 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
,
1034 if (strlen(content
) >= AFSPATHMAX
)
1037 key
= afs_request_key(dvnode
->volume
->cell
);
1043 ret
= afs_vnode_symlink(dvnode
, key
, dentry
->d_name
.name
, content
,
1044 &fid
, &status
, &server
);
1048 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, NULL
);
1049 if (IS_ERR(inode
)) {
1050 /* ENOMEM at a really inconvenient time - just abandon the new
1051 * directory on the server */
1052 ret
= PTR_ERR(inode
);
1056 /* apply the status report we've got for the new vnode */
1057 vnode
= AFS_FS_I(inode
);
1058 spin_lock(&vnode
->lock
);
1059 vnode
->update_cnt
++;
1060 spin_unlock(&vnode
->lock
);
1061 afs_vnode_finalise_status_update(vnode
, server
);
1062 afs_put_server(server
);
1064 d_instantiate(dentry
, inode
);
1065 if (d_unhashed(dentry
)) {
1066 _debug("not hashed");
1074 afs_put_server(server
);
1079 _leave(" = %d", ret
);
1084 * rename a file in an AFS filesystem and/or move it between directories
1086 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1087 struct inode
*new_dir
, struct dentry
*new_dentry
,
1090 struct afs_vnode
*orig_dvnode
, *new_dvnode
, *vnode
;
1097 vnode
= AFS_FS_I(d_inode(old_dentry
));
1098 orig_dvnode
= AFS_FS_I(old_dir
);
1099 new_dvnode
= AFS_FS_I(new_dir
);
1101 _enter("{%x:%u},{%x:%u},{%x:%u},{%pd}",
1102 orig_dvnode
->fid
.vid
, orig_dvnode
->fid
.vnode
,
1103 vnode
->fid
.vid
, vnode
->fid
.vnode
,
1104 new_dvnode
->fid
.vid
, new_dvnode
->fid
.vnode
,
1107 key
= afs_request_key(orig_dvnode
->volume
->cell
);
1113 ret
= afs_vnode_rename(orig_dvnode
, new_dvnode
, key
,
1114 old_dentry
->d_name
.name
,
1115 new_dentry
->d_name
.name
);
1126 _leave(" = %d", ret
);