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(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 .iterate
= 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
{
122 struct dir_context ctx
;
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(struct dir_context
*ctx
,
232 union afs_dir_block
*block
,
235 union afs_dirent
*dire
;
236 unsigned offset
, next
, curr
;
240 _enter("%u,%x,%p,,",(unsigned)ctx
->pos
,blkoff
,block
);
242 curr
= (ctx
->pos
- 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 if (!dir_emit(ctx
, dire
->u
.name
, nlen
,
304 ntohl(dire
->u
.vnode
),
305 ctx
->actor
== afs_lookup_filldir
?
306 ntohl(dire
->u
.unique
) : DT_UNKNOWN
)) {
307 _leave(" = 0 [full]");
311 ctx
->pos
= blkoff
+ next
* sizeof(union afs_dirent
);
314 _leave(" = 1 [more]");
319 * iterate through the data blob that lists the contents of an AFS directory
321 static int afs_dir_iterate(struct inode
*dir
, struct dir_context
*ctx
,
324 union afs_dir_block
*dblock
;
325 struct afs_dir_page
*dbuf
;
327 unsigned blkoff
, limit
;
330 _enter("{%lu},%u,,", dir
->i_ino
, (unsigned)ctx
->pos
);
332 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dir
)->flags
)) {
333 _leave(" = -ESTALE");
337 /* round the file position up to the next entry boundary */
338 ctx
->pos
+= sizeof(union afs_dirent
) - 1;
339 ctx
->pos
&= ~(sizeof(union afs_dirent
) - 1);
341 /* walk through the blocks in sequence */
343 while (ctx
->pos
< dir
->i_size
) {
344 blkoff
= ctx
->pos
& ~(sizeof(union afs_dir_block
) - 1);
346 /* fetch the appropriate page from the directory */
347 page
= afs_dir_get_page(dir
, blkoff
/ PAGE_SIZE
, key
);
353 limit
= blkoff
& ~(PAGE_SIZE
- 1);
355 dbuf
= page_address(page
);
357 /* deal with the individual blocks stashed on this page */
359 dblock
= &dbuf
->blocks
[(blkoff
% PAGE_SIZE
) /
360 sizeof(union afs_dir_block
)];
361 ret
= afs_dir_iterate_block(ctx
, dblock
, blkoff
);
363 afs_dir_put_page(page
);
367 blkoff
+= sizeof(union afs_dir_block
);
369 } while (ctx
->pos
< dir
->i_size
&& blkoff
< limit
);
371 afs_dir_put_page(page
);
376 _leave(" = %d", ret
);
381 * read an AFS directory
383 static int afs_readdir(struct file
*file
, struct dir_context
*ctx
)
385 return afs_dir_iterate(file_inode(file
),
386 ctx
, file
->private_data
);
390 * search the directory for a name
391 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
392 * uniquifier through dtype
394 static int afs_lookup_filldir(void *_cookie
, const char *name
, int nlen
,
395 loff_t fpos
, u64 ino
, unsigned dtype
)
397 struct afs_lookup_cookie
*cookie
= _cookie
;
399 _enter("{%s,%u},%s,%u,,%llu,%u",
400 cookie
->name
.name
, cookie
->name
.len
, name
, nlen
,
401 (unsigned long long) ino
, dtype
);
403 /* insanity checks first */
404 BUILD_BUG_ON(sizeof(union afs_dir_block
) != 2048);
405 BUILD_BUG_ON(sizeof(union afs_dirent
) != 32);
407 if (cookie
->name
.len
!= nlen
||
408 memcmp(cookie
->name
.name
, name
, nlen
) != 0) {
413 cookie
->fid
.vnode
= ino
;
414 cookie
->fid
.unique
= dtype
;
417 _leave(" = -1 [found]");
422 * do a lookup in a directory
423 * - just returns the FID the dentry name maps to if found
425 static int afs_do_lookup(struct inode
*dir
, struct dentry
*dentry
,
426 struct afs_fid
*fid
, struct key
*key
)
428 struct afs_super_info
*as
= dir
->i_sb
->s_fs_info
;
429 struct afs_lookup_cookie cookie
= {
430 .ctx
.actor
= afs_lookup_filldir
,
431 .name
= dentry
->d_name
,
432 .fid
.vid
= as
->volume
->vid
436 _enter("{%lu},%p{%s},", dir
->i_ino
, dentry
, dentry
->d_name
.name
);
438 /* search the directory */
439 ret
= afs_dir_iterate(dir
, &cookie
.ctx
, key
);
441 _leave(" = %d [iter]", ret
);
447 _leave(" = -ENOENT [not found]");
452 _leave(" = 0 { vn=%u u=%u }", fid
->vnode
, fid
->unique
);
457 * Try to auto mount the mountpoint with pseudo directory, if the autocell
458 * operation is setted.
460 static struct inode
*afs_try_auto_mntpt(
461 int ret
, struct dentry
*dentry
, struct inode
*dir
, struct key
*key
,
464 const char *devname
= dentry
->d_name
.name
;
465 struct afs_vnode
*vnode
= AFS_FS_I(dir
);
468 _enter("%d, %p{%s}, {%x:%u}, %p",
469 ret
, dentry
, devname
, vnode
->fid
.vid
, vnode
->fid
.vnode
, key
);
471 if (ret
!= -ENOENT
||
472 !test_bit(AFS_VNODE_AUTOCELL
, &vnode
->flags
))
475 inode
= afs_iget_autocell(dir
, devname
, strlen(devname
), key
);
477 ret
= PTR_ERR(inode
);
481 *fid
= AFS_FS_I(inode
)->fid
;
482 _leave("= %p", inode
);
491 * look up an entry in a directory
493 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
496 struct afs_vnode
*vnode
;
502 vnode
= AFS_FS_I(dir
);
504 _enter("{%x:%u},%p{%s},",
505 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
, dentry
->d_name
.name
);
507 ASSERTCMP(dentry
->d_inode
, ==, NULL
);
509 if (dentry
->d_name
.len
>= AFSNAMEMAX
) {
510 _leave(" = -ENAMETOOLONG");
511 return ERR_PTR(-ENAMETOOLONG
);
514 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
)) {
515 _leave(" = -ESTALE");
516 return ERR_PTR(-ESTALE
);
519 key
= afs_request_key(vnode
->volume
->cell
);
521 _leave(" = %ld [key]", PTR_ERR(key
));
522 return ERR_CAST(key
);
525 ret
= afs_validate(vnode
, key
);
528 _leave(" = %d [val]", ret
);
532 ret
= afs_do_lookup(dir
, dentry
, &fid
, key
);
534 inode
= afs_try_auto_mntpt(ret
, dentry
, dir
, key
, &fid
);
535 if (!IS_ERR(inode
)) {
540 ret
= PTR_ERR(inode
);
542 if (ret
== -ENOENT
) {
544 _leave(" = NULL [negative]");
547 _leave(" = %d [do]", ret
);
550 dentry
->d_fsdata
= (void *)(unsigned long) vnode
->status
.data_version
;
552 /* instantiate the dentry */
553 inode
= afs_iget(dir
->i_sb
, key
, &fid
, NULL
, NULL
);
556 _leave(" = %ld", PTR_ERR(inode
));
557 return ERR_CAST(inode
);
561 d_add(dentry
, inode
);
562 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%u }",
565 dentry
->d_inode
->i_ino
,
566 dentry
->d_inode
->i_generation
);
572 * check that a dentry lookup hit has found a valid entry
573 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
576 static int afs_d_revalidate(struct dentry
*dentry
, unsigned int flags
)
578 struct afs_vnode
*vnode
, *dir
;
579 struct afs_fid
uninitialized_var(fid
);
580 struct dentry
*parent
;
585 if (flags
& LOOKUP_RCU
)
588 vnode
= AFS_FS_I(dentry
->d_inode
);
591 _enter("{v={%x:%u} n=%s fl=%lx},",
592 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
->d_name
.name
,
595 _enter("{neg n=%s}", dentry
->d_name
.name
);
597 key
= afs_request_key(AFS_FS_S(dentry
->d_sb
)->volume
->cell
);
601 /* lock down the parent dentry so we can peer at it */
602 parent
= dget_parent(dentry
);
603 dir
= AFS_FS_I(parent
->d_inode
);
605 /* validate the parent directory */
606 if (test_bit(AFS_VNODE_MODIFIED
, &dir
->flags
))
607 afs_validate(dir
, key
);
609 if (test_bit(AFS_VNODE_DELETED
, &dir
->flags
)) {
610 _debug("%s: parent dir deleted", dentry
->d_name
.name
);
614 dir_version
= (void *) (unsigned long) dir
->status
.data_version
;
615 if (dentry
->d_fsdata
== dir_version
)
616 goto out_valid
; /* the dir contents are unchanged */
618 _debug("dir modified");
620 /* search the directory for this vnode */
621 ret
= afs_do_lookup(&dir
->vfs_inode
, dentry
, &fid
, key
);
624 /* the filename maps to something */
625 if (!dentry
->d_inode
)
627 if (is_bad_inode(dentry
->d_inode
)) {
628 printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
629 parent
->d_name
.name
, dentry
->d_name
.name
);
633 /* if the vnode ID has changed, then the dirent points to a
635 if (fid
.vnode
!= vnode
->fid
.vnode
) {
636 _debug("%s: dirent changed [%u != %u]",
637 dentry
->d_name
.name
, fid
.vnode
,
642 /* if the vnode ID uniqifier has changed, then the file has
643 * been deleted and replaced, and the original vnode ID has
645 if (fid
.unique
!= vnode
->fid
.unique
) {
646 _debug("%s: file deleted (uq %u -> %u I:%u)",
647 dentry
->d_name
.name
, fid
.unique
,
649 dentry
->d_inode
->i_generation
);
650 spin_lock(&vnode
->lock
);
651 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
652 spin_unlock(&vnode
->lock
);
658 /* the filename is unknown */
659 _debug("%s: dirent not found", dentry
->d_name
.name
);
665 _debug("failed to iterate dir %s: %d",
666 parent
->d_name
.name
, ret
);
671 dentry
->d_fsdata
= dir_version
;
675 _leave(" = 1 [valid]");
678 /* the dirent, if it exists, now points to a different vnode */
680 spin_lock(&dentry
->d_lock
);
681 dentry
->d_flags
|= DCACHE_NFSFS_RENAMED
;
682 spin_unlock(&dentry
->d_lock
);
685 /* don't unhash if we have submounts */
686 if (check_submounts_and_drop(dentry
) != 0)
689 _debug("dropping dentry %s/%s",
690 parent
->d_name
.name
, dentry
->d_name
.name
);
694 _leave(" = 0 [bad]");
699 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
701 * - called from dput() when d_count is going to 0.
702 * - return 1 to request dentry be unhashed, 0 otherwise
704 static int afs_d_delete(const struct dentry
*dentry
)
706 _enter("%s", dentry
->d_name
.name
);
708 if (dentry
->d_flags
& DCACHE_NFSFS_RENAMED
)
711 if (dentry
->d_inode
&&
712 (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dentry
->d_inode
)->flags
) ||
713 test_bit(AFS_VNODE_PSEUDODIR
, &AFS_FS_I(dentry
->d_inode
)->flags
)))
716 _leave(" = 0 [keep]");
720 _leave(" = 1 [zap]");
725 * handle dentry release
727 static void afs_d_release(struct dentry
*dentry
)
729 _enter("%s", dentry
->d_name
.name
);
733 * create a directory on an AFS filesystem
735 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
737 struct afs_file_status status
;
738 struct afs_callback cb
;
739 struct afs_server
*server
;
740 struct afs_vnode
*dvnode
, *vnode
;
746 dvnode
= AFS_FS_I(dir
);
748 _enter("{%x:%u},{%s},%ho",
749 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
, mode
);
751 key
= afs_request_key(dvnode
->volume
->cell
);
758 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
759 mode
, &fid
, &status
, &cb
, &server
);
763 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
765 /* ENOMEM at a really inconvenient time - just abandon the new
766 * directory on the server */
767 ret
= PTR_ERR(inode
);
771 /* apply the status report we've got for the new vnode */
772 vnode
= AFS_FS_I(inode
);
773 spin_lock(&vnode
->lock
);
775 spin_unlock(&vnode
->lock
);
776 afs_vnode_finalise_status_update(vnode
, server
);
777 afs_put_server(server
);
779 d_instantiate(dentry
, inode
);
780 if (d_unhashed(dentry
)) {
781 _debug("not hashed");
789 afs_put_server(server
);
794 _leave(" = %d", ret
);
799 * remove a directory from an AFS filesystem
801 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
803 struct afs_vnode
*dvnode
, *vnode
;
807 dvnode
= AFS_FS_I(dir
);
809 _enter("{%x:%u},{%s}",
810 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
);
812 key
= afs_request_key(dvnode
->volume
->cell
);
818 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, true);
822 if (dentry
->d_inode
) {
823 vnode
= AFS_FS_I(dentry
->d_inode
);
824 clear_nlink(&vnode
->vfs_inode
);
825 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
826 afs_discard_callback_on_delete(vnode
);
836 _leave(" = %d", ret
);
841 * remove a file from an AFS filesystem
843 static int afs_unlink(struct inode
*dir
, struct dentry
*dentry
)
845 struct afs_vnode
*dvnode
, *vnode
;
849 dvnode
= AFS_FS_I(dir
);
851 _enter("{%x:%u},{%s}",
852 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
);
855 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
858 key
= afs_request_key(dvnode
->volume
->cell
);
864 if (dentry
->d_inode
) {
865 vnode
= AFS_FS_I(dentry
->d_inode
);
867 /* make sure we have a callback promise on the victim */
868 ret
= afs_validate(vnode
, key
);
873 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, false);
877 if (dentry
->d_inode
) {
878 /* if the file wasn't deleted due to excess hard links, the
879 * fileserver will break the callback promise on the file - if
880 * it had one - before it returns to us, and if it was deleted,
883 * however, if we didn't have a callback promise outstanding,
884 * or it was outstanding on a different server, then it won't
887 vnode
= AFS_FS_I(dentry
->d_inode
);
888 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
))
889 _debug("AFS_VNODE_DELETED");
890 if (test_bit(AFS_VNODE_CB_BROKEN
, &vnode
->flags
))
891 _debug("AFS_VNODE_CB_BROKEN");
892 set_bit(AFS_VNODE_CB_BROKEN
, &vnode
->flags
);
893 ret
= afs_validate(vnode
, key
);
894 _debug("nlink %d [val %d]", vnode
->vfs_inode
.i_nlink
, ret
);
904 _leave(" = %d", ret
);
909 * create a regular file on an AFS filesystem
911 static int afs_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
914 struct afs_file_status status
;
915 struct afs_callback cb
;
916 struct afs_server
*server
;
917 struct afs_vnode
*dvnode
, *vnode
;
923 dvnode
= AFS_FS_I(dir
);
925 _enter("{%x:%u},{%s},%ho,",
926 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
, mode
);
928 key
= afs_request_key(dvnode
->volume
->cell
);
935 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
936 mode
, &fid
, &status
, &cb
, &server
);
940 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
942 /* ENOMEM at a really inconvenient time - just abandon the new
943 * directory on the server */
944 ret
= PTR_ERR(inode
);
948 /* apply the status report we've got for the new vnode */
949 vnode
= AFS_FS_I(inode
);
950 spin_lock(&vnode
->lock
);
952 spin_unlock(&vnode
->lock
);
953 afs_vnode_finalise_status_update(vnode
, server
);
954 afs_put_server(server
);
956 d_instantiate(dentry
, inode
);
957 if (d_unhashed(dentry
)) {
958 _debug("not hashed");
966 afs_put_server(server
);
971 _leave(" = %d", ret
);
976 * create a hard link between files in an AFS filesystem
978 static int afs_link(struct dentry
*from
, struct inode
*dir
,
979 struct dentry
*dentry
)
981 struct afs_vnode
*dvnode
, *vnode
;
985 vnode
= AFS_FS_I(from
->d_inode
);
986 dvnode
= AFS_FS_I(dir
);
988 _enter("{%x:%u},{%x:%u},{%s}",
989 vnode
->fid
.vid
, vnode
->fid
.vnode
,
990 dvnode
->fid
.vid
, dvnode
->fid
.vnode
,
991 dentry
->d_name
.name
);
993 key
= afs_request_key(dvnode
->volume
->cell
);
999 ret
= afs_vnode_link(dvnode
, vnode
, key
, dentry
->d_name
.name
);
1003 ihold(&vnode
->vfs_inode
);
1004 d_instantiate(dentry
, &vnode
->vfs_inode
);
1013 _leave(" = %d", ret
);
1018 * create a symlink in an AFS filesystem
1020 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
1021 const char *content
)
1023 struct afs_file_status status
;
1024 struct afs_server
*server
;
1025 struct afs_vnode
*dvnode
, *vnode
;
1027 struct inode
*inode
;
1031 dvnode
= AFS_FS_I(dir
);
1033 _enter("{%x:%u},{%s},%s",
1034 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
->d_name
.name
,
1038 if (strlen(content
) >= AFSPATHMAX
)
1041 key
= afs_request_key(dvnode
->volume
->cell
);
1047 ret
= afs_vnode_symlink(dvnode
, key
, dentry
->d_name
.name
, content
,
1048 &fid
, &status
, &server
);
1052 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, NULL
);
1053 if (IS_ERR(inode
)) {
1054 /* ENOMEM at a really inconvenient time - just abandon the new
1055 * directory on the server */
1056 ret
= PTR_ERR(inode
);
1060 /* apply the status report we've got for the new vnode */
1061 vnode
= AFS_FS_I(inode
);
1062 spin_lock(&vnode
->lock
);
1063 vnode
->update_cnt
++;
1064 spin_unlock(&vnode
->lock
);
1065 afs_vnode_finalise_status_update(vnode
, server
);
1066 afs_put_server(server
);
1068 d_instantiate(dentry
, inode
);
1069 if (d_unhashed(dentry
)) {
1070 _debug("not hashed");
1078 afs_put_server(server
);
1083 _leave(" = %d", ret
);
1088 * rename a file in an AFS filesystem and/or move it between directories
1090 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1091 struct inode
*new_dir
, struct dentry
*new_dentry
)
1093 struct afs_vnode
*orig_dvnode
, *new_dvnode
, *vnode
;
1097 vnode
= AFS_FS_I(old_dentry
->d_inode
);
1098 orig_dvnode
= AFS_FS_I(old_dir
);
1099 new_dvnode
= AFS_FS_I(new_dir
);
1101 _enter("{%x:%u},{%x:%u},{%x:%u},{%s}",
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
,
1105 new_dentry
->d_name
.name
);
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
);