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
,
64 .listxattr
= afs_listxattr
,
67 const struct dentry_operations afs_fs_dentry_operations
= {
68 .d_revalidate
= afs_d_revalidate
,
69 .d_delete
= afs_d_delete
,
70 .d_release
= afs_d_release
,
71 .d_automount
= afs_d_automount
,
74 #define AFS_DIR_HASHTBL_SIZE 128
75 #define AFS_DIR_DIRENT_SIZE 32
76 #define AFS_DIRENT_PER_BLOCK 64
86 uint8_t overflow
[4]; /* if any char of the name (inc
87 * NUL) reaches here, consume
88 * the next dirent too */
90 uint8_t extended_name
[32];
93 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
94 struct afs_dir_pagehdr
{
97 #define AFS_DIR_MAGIC htons(1234)
103 /* directory block layout */
104 union afs_dir_block
{
106 struct afs_dir_pagehdr pagehdr
;
109 struct afs_dir_pagehdr pagehdr
;
110 uint8_t alloc_ctrs
[128];
112 uint16_t hashtable
[AFS_DIR_HASHTBL_SIZE
];
115 union afs_dirent dirents
[AFS_DIRENT_PER_BLOCK
];
118 /* layout on a linux VM page */
119 struct afs_dir_page
{
120 union afs_dir_block blocks
[PAGE_SIZE
/ sizeof(union afs_dir_block
)];
123 struct afs_lookup_cookie
{
124 struct dir_context ctx
;
131 * check that a directory page is valid
133 static inline bool afs_dir_check_page(struct inode
*dir
, struct page
*page
)
135 struct afs_dir_page
*dbuf
;
140 /* check the page count */
141 qty
= desc
.size
/ sizeof(dbuf
->blocks
[0]);
145 if (page
->index
== 0 && qty
!= ntohs(dbuf
->blocks
[0].pagehdr
.npages
)) {
146 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
147 __func__
, dir
->i_ino
, qty
,
148 ntohs(dbuf
->blocks
[0].pagehdr
.npages
));
153 /* determine how many magic numbers there should be in this page */
154 latter
= dir
->i_size
- page_offset(page
);
155 if (latter
>= PAGE_SIZE
)
159 qty
/= sizeof(union afs_dir_block
);
162 dbuf
= page_address(page
);
163 for (tmp
= 0; tmp
< qty
; tmp
++) {
164 if (dbuf
->blocks
[tmp
].pagehdr
.magic
!= AFS_DIR_MAGIC
) {
165 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
166 __func__
, dir
->i_ino
, tmp
, qty
,
167 ntohs(dbuf
->blocks
[tmp
].pagehdr
.magic
));
172 SetPageChecked(page
);
181 * discard a page cached in the pagecache
183 static inline void afs_dir_put_page(struct page
*page
)
190 * get a page into the pagecache
192 static struct page
*afs_dir_get_page(struct inode
*dir
, unsigned long index
,
196 _enter("{%lu},%lu", dir
->i_ino
, index
);
198 page
= read_cache_page(dir
->i_mapping
, index
, afs_page_filler
, key
);
201 if (unlikely(!PageChecked(page
))) {
202 if (PageError(page
) || !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(struct dir_context
*ctx
,
234 union afs_dir_block
*block
,
237 union afs_dirent
*dire
;
238 unsigned offset
, next
, curr
;
242 _enter("%u,%x,%p,,",(unsigned)ctx
->pos
,blkoff
,block
);
244 curr
= (ctx
->pos
- 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 if (!dir_emit(ctx
, dire
->u
.name
, nlen
,
306 ntohl(dire
->u
.vnode
),
307 ctx
->actor
== afs_lookup_filldir
?
308 ntohl(dire
->u
.unique
) : DT_UNKNOWN
)) {
309 _leave(" = 0 [full]");
313 ctx
->pos
= blkoff
+ next
* sizeof(union afs_dirent
);
316 _leave(" = 1 [more]");
321 * iterate through the data blob that lists the contents of an AFS directory
323 static int afs_dir_iterate(struct inode
*dir
, struct dir_context
*ctx
,
326 union afs_dir_block
*dblock
;
327 struct afs_dir_page
*dbuf
;
329 unsigned blkoff
, limit
;
332 _enter("{%lu},%u,,", dir
->i_ino
, (unsigned)ctx
->pos
);
334 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dir
)->flags
)) {
335 _leave(" = -ESTALE");
339 /* round the file position up to the next entry boundary */
340 ctx
->pos
+= sizeof(union afs_dirent
) - 1;
341 ctx
->pos
&= ~(sizeof(union afs_dirent
) - 1);
343 /* walk through the blocks in sequence */
345 while (ctx
->pos
< dir
->i_size
) {
346 blkoff
= ctx
->pos
& ~(sizeof(union afs_dir_block
) - 1);
348 /* fetch the appropriate page from the directory */
349 page
= afs_dir_get_page(dir
, blkoff
/ PAGE_SIZE
, key
);
355 limit
= blkoff
& ~(PAGE_SIZE
- 1);
357 dbuf
= page_address(page
);
359 /* deal with the individual blocks stashed on this page */
361 dblock
= &dbuf
->blocks
[(blkoff
% PAGE_SIZE
) /
362 sizeof(union afs_dir_block
)];
363 ret
= afs_dir_iterate_block(ctx
, dblock
, blkoff
);
365 afs_dir_put_page(page
);
369 blkoff
+= sizeof(union afs_dir_block
);
371 } while (ctx
->pos
< dir
->i_size
&& blkoff
< limit
);
373 afs_dir_put_page(page
);
378 _leave(" = %d", ret
);
383 * read an AFS directory
385 static int afs_readdir(struct file
*file
, struct dir_context
*ctx
)
387 return afs_dir_iterate(file_inode(file
),
388 ctx
, file
->private_data
);
392 * search the directory for a name
393 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
394 * uniquifier through dtype
396 static int afs_lookup_filldir(struct dir_context
*ctx
, const char *name
,
397 int nlen
, loff_t fpos
, u64 ino
, unsigned dtype
)
399 struct afs_lookup_cookie
*cookie
=
400 container_of(ctx
, struct afs_lookup_cookie
, ctx
);
402 _enter("{%s,%u},%s,%u,,%llu,%u",
403 cookie
->name
.name
, cookie
->name
.len
, name
, nlen
,
404 (unsigned long long) ino
, dtype
);
406 /* insanity checks first */
407 BUILD_BUG_ON(sizeof(union afs_dir_block
) != 2048);
408 BUILD_BUG_ON(sizeof(union afs_dirent
) != 32);
410 if (cookie
->name
.len
!= nlen
||
411 memcmp(cookie
->name
.name
, name
, nlen
) != 0) {
416 cookie
->fid
.vnode
= ino
;
417 cookie
->fid
.unique
= dtype
;
420 _leave(" = -1 [found]");
425 * do a lookup in a directory
426 * - just returns the FID the dentry name maps to if found
428 static int afs_do_lookup(struct inode
*dir
, struct dentry
*dentry
,
429 struct afs_fid
*fid
, struct key
*key
)
431 struct afs_super_info
*as
= dir
->i_sb
->s_fs_info
;
432 struct afs_lookup_cookie cookie
= {
433 .ctx
.actor
= afs_lookup_filldir
,
434 .name
= dentry
->d_name
,
435 .fid
.vid
= as
->volume
->vid
439 _enter("{%lu},%p{%pd},", dir
->i_ino
, dentry
, dentry
);
441 /* search the directory */
442 ret
= afs_dir_iterate(dir
, &cookie
.ctx
, key
);
444 _leave(" = %d [iter]", ret
);
450 _leave(" = -ENOENT [not found]");
455 _leave(" = 0 { vn=%u u=%u }", fid
->vnode
, fid
->unique
);
460 * Try to auto mount the mountpoint with pseudo directory, if the autocell
461 * operation is setted.
463 static struct inode
*afs_try_auto_mntpt(
464 int ret
, struct dentry
*dentry
, struct inode
*dir
, struct key
*key
,
467 const char *devname
= dentry
->d_name
.name
;
468 struct afs_vnode
*vnode
= AFS_FS_I(dir
);
471 _enter("%d, %p{%pd}, {%x:%u}, %p",
472 ret
, dentry
, dentry
, vnode
->fid
.vid
, vnode
->fid
.vnode
, key
);
474 if (ret
!= -ENOENT
||
475 !test_bit(AFS_VNODE_AUTOCELL
, &vnode
->flags
))
478 inode
= afs_iget_autocell(dir
, devname
, strlen(devname
), key
);
480 ret
= PTR_ERR(inode
);
484 *fid
= AFS_FS_I(inode
)->fid
;
485 _leave("= %p", inode
);
494 * look up an entry in a directory
496 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
499 struct afs_vnode
*vnode
;
505 vnode
= AFS_FS_I(dir
);
507 _enter("{%x:%u},%p{%pd},",
508 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
, dentry
);
510 ASSERTCMP(d_inode(dentry
), ==, NULL
);
512 if (dentry
->d_name
.len
>= AFSNAMEMAX
) {
513 _leave(" = -ENAMETOOLONG");
514 return ERR_PTR(-ENAMETOOLONG
);
517 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
)) {
518 _leave(" = -ESTALE");
519 return ERR_PTR(-ESTALE
);
522 key
= afs_request_key(vnode
->volume
->cell
);
524 _leave(" = %ld [key]", PTR_ERR(key
));
525 return ERR_CAST(key
);
528 ret
= afs_validate(vnode
, key
);
531 _leave(" = %d [val]", ret
);
535 ret
= afs_do_lookup(dir
, dentry
, &fid
, key
);
537 inode
= afs_try_auto_mntpt(ret
, dentry
, dir
, key
, &fid
);
538 if (!IS_ERR(inode
)) {
543 ret
= PTR_ERR(inode
);
545 if (ret
== -ENOENT
) {
547 _leave(" = NULL [negative]");
550 _leave(" = %d [do]", ret
);
553 dentry
->d_fsdata
= (void *)(unsigned long) vnode
->status
.data_version
;
555 /* instantiate the dentry */
556 inode
= afs_iget(dir
->i_sb
, key
, &fid
, NULL
, NULL
);
559 _leave(" = %ld", PTR_ERR(inode
));
560 return ERR_CAST(inode
);
564 d_add(dentry
, inode
);
565 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%u }",
568 d_inode(dentry
)->i_ino
,
569 d_inode(dentry
)->i_generation
);
575 * check that a dentry lookup hit has found a valid entry
576 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
579 static int afs_d_revalidate(struct dentry
*dentry
, unsigned int flags
)
581 struct afs_vnode
*vnode
, *dir
;
582 struct afs_fid
uninitialized_var(fid
);
583 struct dentry
*parent
;
588 if (flags
& LOOKUP_RCU
)
591 vnode
= AFS_FS_I(d_inode(dentry
));
593 if (d_really_is_positive(dentry
))
594 _enter("{v={%x:%u} n=%pd fl=%lx},",
595 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
,
598 _enter("{neg n=%pd}", dentry
);
600 key
= afs_request_key(AFS_FS_S(dentry
->d_sb
)->volume
->cell
);
604 /* lock down the parent dentry so we can peer at it */
605 parent
= dget_parent(dentry
);
606 dir
= AFS_FS_I(d_inode(parent
));
608 /* validate the parent directory */
609 if (test_bit(AFS_VNODE_MODIFIED
, &dir
->flags
))
610 afs_validate(dir
, key
);
612 if (test_bit(AFS_VNODE_DELETED
, &dir
->flags
)) {
613 _debug("%pd: parent dir deleted", dentry
);
617 dir_version
= (void *) (unsigned long) dir
->status
.data_version
;
618 if (dentry
->d_fsdata
== dir_version
)
619 goto out_valid
; /* the dir contents are unchanged */
621 _debug("dir modified");
623 /* search the directory for this vnode */
624 ret
= afs_do_lookup(&dir
->vfs_inode
, dentry
, &fid
, key
);
627 /* the filename maps to something */
628 if (d_really_is_negative(dentry
))
630 if (is_bad_inode(d_inode(dentry
))) {
631 printk("kAFS: afs_d_revalidate: %pd2 has bad inode\n",
636 /* if the vnode ID has changed, then the dirent points to a
638 if (fid
.vnode
!= vnode
->fid
.vnode
) {
639 _debug("%pd: dirent changed [%u != %u]",
645 /* if the vnode ID uniqifier has changed, then the file has
646 * been deleted and replaced, and the original vnode ID has
648 if (fid
.unique
!= vnode
->fid
.unique
) {
649 _debug("%pd: file deleted (uq %u -> %u I:%u)",
652 d_inode(dentry
)->i_generation
);
653 spin_lock(&vnode
->lock
);
654 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
655 spin_unlock(&vnode
->lock
);
661 /* the filename is unknown */
662 _debug("%pd: dirent not found", dentry
);
663 if (d_really_is_positive(dentry
))
668 _debug("failed to iterate dir %pd: %d",
674 dentry
->d_fsdata
= dir_version
;
677 _leave(" = 1 [valid]");
680 /* the dirent, if it exists, now points to a different vnode */
682 spin_lock(&dentry
->d_lock
);
683 dentry
->d_flags
|= DCACHE_NFSFS_RENAMED
;
684 spin_unlock(&dentry
->d_lock
);
687 _debug("dropping dentry %pd2", dentry
);
691 _leave(" = 0 [bad]");
696 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
698 * - called from dput() when d_count is going to 0.
699 * - return 1 to request dentry be unhashed, 0 otherwise
701 static int afs_d_delete(const struct dentry
*dentry
)
703 _enter("%pd", dentry
);
705 if (dentry
->d_flags
& DCACHE_NFSFS_RENAMED
)
708 if (d_really_is_positive(dentry
) &&
709 (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(d_inode(dentry
))->flags
) ||
710 test_bit(AFS_VNODE_PSEUDODIR
, &AFS_FS_I(d_inode(dentry
))->flags
)))
713 _leave(" = 0 [keep]");
717 _leave(" = 1 [zap]");
722 * handle dentry release
724 static void afs_d_release(struct dentry
*dentry
)
726 _enter("%pd", dentry
);
730 * create a directory on an AFS filesystem
732 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
734 struct afs_file_status status
;
735 struct afs_callback cb
;
736 struct afs_server
*server
;
737 struct afs_vnode
*dvnode
, *vnode
;
743 dvnode
= AFS_FS_I(dir
);
745 _enter("{%x:%u},{%pd},%ho",
746 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, mode
);
748 key
= afs_request_key(dvnode
->volume
->cell
);
755 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
756 mode
, &fid
, &status
, &cb
, &server
);
760 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
762 /* ENOMEM at a really inconvenient time - just abandon the new
763 * directory on the server */
764 ret
= PTR_ERR(inode
);
768 /* apply the status report we've got for the new vnode */
769 vnode
= AFS_FS_I(inode
);
770 spin_lock(&vnode
->lock
);
772 spin_unlock(&vnode
->lock
);
773 afs_vnode_finalise_status_update(vnode
, server
);
774 afs_put_server(server
);
776 d_instantiate(dentry
, inode
);
777 if (d_unhashed(dentry
)) {
778 _debug("not hashed");
786 afs_put_server(server
);
791 _leave(" = %d", ret
);
796 * remove a directory from an AFS filesystem
798 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
800 struct afs_vnode
*dvnode
, *vnode
;
804 dvnode
= AFS_FS_I(dir
);
806 _enter("{%x:%u},{%pd}",
807 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
);
809 key
= afs_request_key(dvnode
->volume
->cell
);
815 ret
= afs_vnode_remove(dvnode
, key
, dentry
->d_name
.name
, true);
819 if (d_really_is_positive(dentry
)) {
820 vnode
= AFS_FS_I(d_inode(dentry
));
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:%u},{%pd}",
849 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
);
852 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
855 key
= afs_request_key(dvnode
->volume
->cell
);
861 if (d_really_is_positive(dentry
)) {
862 vnode
= AFS_FS_I(d_inode(dentry
));
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 (d_really_is_positive(dentry
)) {
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(d_inode(dentry
));
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
, umode_t mode
,
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:%u},{%pd},%ho,",
923 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, mode
);
925 key
= afs_request_key(dvnode
->volume
->cell
);
932 ret
= afs_vnode_create(dvnode
, key
, dentry
->d_name
.name
,
933 mode
, &fid
, &status
, &cb
, &server
);
937 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, &cb
);
939 /* ENOMEM at a really inconvenient time - just abandon the new
940 * directory on the server */
941 ret
= PTR_ERR(inode
);
945 /* apply the status report we've got for the new vnode */
946 vnode
= AFS_FS_I(inode
);
947 spin_lock(&vnode
->lock
);
949 spin_unlock(&vnode
->lock
);
950 afs_vnode_finalise_status_update(vnode
, server
);
951 afs_put_server(server
);
953 d_instantiate(dentry
, inode
);
954 if (d_unhashed(dentry
)) {
955 _debug("not hashed");
963 afs_put_server(server
);
968 _leave(" = %d", ret
);
973 * create a hard link between files in an AFS filesystem
975 static int afs_link(struct dentry
*from
, struct inode
*dir
,
976 struct dentry
*dentry
)
978 struct afs_vnode
*dvnode
, *vnode
;
982 vnode
= AFS_FS_I(d_inode(from
));
983 dvnode
= AFS_FS_I(dir
);
985 _enter("{%x:%u},{%x:%u},{%pd}",
986 vnode
->fid
.vid
, vnode
->fid
.vnode
,
987 dvnode
->fid
.vid
, dvnode
->fid
.vnode
,
990 key
= afs_request_key(dvnode
->volume
->cell
);
996 ret
= afs_vnode_link(dvnode
, vnode
, key
, dentry
->d_name
.name
);
1000 ihold(&vnode
->vfs_inode
);
1001 d_instantiate(dentry
, &vnode
->vfs_inode
);
1010 _leave(" = %d", ret
);
1015 * create a symlink in an AFS filesystem
1017 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
1018 const char *content
)
1020 struct afs_file_status status
;
1021 struct afs_server
*server
;
1022 struct afs_vnode
*dvnode
, *vnode
;
1024 struct inode
*inode
;
1028 dvnode
= AFS_FS_I(dir
);
1030 _enter("{%x:%u},{%pd},%s",
1031 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
,
1035 if (strlen(content
) >= AFSPATHMAX
)
1038 key
= afs_request_key(dvnode
->volume
->cell
);
1044 ret
= afs_vnode_symlink(dvnode
, key
, dentry
->d_name
.name
, content
,
1045 &fid
, &status
, &server
);
1049 inode
= afs_iget(dir
->i_sb
, key
, &fid
, &status
, NULL
);
1050 if (IS_ERR(inode
)) {
1051 /* ENOMEM at a really inconvenient time - just abandon the new
1052 * directory on the server */
1053 ret
= PTR_ERR(inode
);
1057 /* apply the status report we've got for the new vnode */
1058 vnode
= AFS_FS_I(inode
);
1059 spin_lock(&vnode
->lock
);
1060 vnode
->update_cnt
++;
1061 spin_unlock(&vnode
->lock
);
1062 afs_vnode_finalise_status_update(vnode
, server
);
1063 afs_put_server(server
);
1065 d_instantiate(dentry
, inode
);
1066 if (d_unhashed(dentry
)) {
1067 _debug("not hashed");
1075 afs_put_server(server
);
1080 _leave(" = %d", ret
);
1085 * rename a file in an AFS filesystem and/or move it between directories
1087 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1088 struct inode
*new_dir
, struct dentry
*new_dentry
,
1091 struct afs_vnode
*orig_dvnode
, *new_dvnode
, *vnode
;
1098 vnode
= AFS_FS_I(d_inode(old_dentry
));
1099 orig_dvnode
= AFS_FS_I(old_dir
);
1100 new_dvnode
= AFS_FS_I(new_dir
);
1102 _enter("{%x:%u},{%x:%u},{%x:%u},{%pd}",
1103 orig_dvnode
->fid
.vid
, orig_dvnode
->fid
.vnode
,
1104 vnode
->fid
.vid
, vnode
->fid
.vnode
,
1105 new_dvnode
->fid
.vid
, new_dvnode
->fid
.vnode
,
1108 key
= afs_request_key(orig_dvnode
->volume
->cell
);
1114 ret
= afs_vnode_rename(orig_dvnode
, new_dvnode
, key
,
1115 old_dentry
->d_name
.name
,
1116 new_dentry
->d_name
.name
);
1127 _leave(" = %d", ret
);