1 /* dir.c: AFS filesystem directory handling
3 * Copyright (C) 2002, 2018 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>
14 #include <linux/namei.h>
15 #include <linux/pagemap.h>
16 #include <linux/swap.h>
17 #include <linux/ctype.h>
18 #include <linux/sched.h>
19 #include <linux/task_io_accounting_ops.h>
23 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
25 static int afs_dir_open(struct inode
*inode
, struct file
*file
);
26 static int afs_readdir(struct file
*file
, struct dir_context
*ctx
);
27 static int afs_d_revalidate(struct dentry
*dentry
, unsigned int flags
);
28 static int afs_d_delete(const struct dentry
*dentry
);
29 static int afs_lookup_one_filldir(struct dir_context
*ctx
, const char *name
, int nlen
,
30 loff_t fpos
, u64 ino
, unsigned dtype
);
31 static int afs_lookup_filldir(struct dir_context
*ctx
, const char *name
, int nlen
,
32 loff_t fpos
, u64 ino
, unsigned dtype
);
33 static int afs_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
35 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
);
36 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
);
37 static int afs_unlink(struct inode
*dir
, struct dentry
*dentry
);
38 static int afs_link(struct dentry
*from
, struct inode
*dir
,
39 struct dentry
*dentry
);
40 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
42 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
43 struct inode
*new_dir
, struct dentry
*new_dentry
,
45 static int afs_dir_releasepage(struct page
*page
, gfp_t gfp_flags
);
46 static void afs_dir_invalidatepage(struct page
*page
, unsigned int offset
,
49 static int afs_dir_set_page_dirty(struct page
*page
)
51 BUG(); /* This should never happen. */
54 const struct file_operations afs_dir_file_operations
= {
56 .release
= afs_release
,
57 .iterate_shared
= afs_readdir
,
59 .llseek
= generic_file_llseek
,
62 const struct inode_operations afs_dir_inode_operations
= {
67 .symlink
= afs_symlink
,
71 .permission
= afs_permission
,
72 .getattr
= afs_getattr
,
73 .setattr
= afs_setattr
,
74 .listxattr
= afs_listxattr
,
77 const struct address_space_operations afs_dir_aops
= {
78 .set_page_dirty
= afs_dir_set_page_dirty
,
79 .releasepage
= afs_dir_releasepage
,
80 .invalidatepage
= afs_dir_invalidatepage
,
83 const struct dentry_operations afs_fs_dentry_operations
= {
84 .d_revalidate
= afs_d_revalidate
,
85 .d_delete
= afs_d_delete
,
86 .d_release
= afs_d_release
,
87 .d_automount
= afs_d_automount
,
90 struct afs_lookup_one_cookie
{
91 struct dir_context ctx
;
97 struct afs_lookup_cookie
{
98 struct dir_context ctx
;
102 unsigned short nr_fids
;
103 struct afs_file_status
*statuses
;
104 struct afs_callback
*callbacks
;
105 struct afs_fid fids
[50];
109 * check that a directory page is valid
111 static bool afs_dir_check_page(struct afs_vnode
*dvnode
, struct page
*page
,
114 struct afs_xdr_dir_page
*dbuf
;
118 /* Determine how many magic numbers there should be in this page, but
119 * we must take care because the directory may change size under us.
121 off
= page_offset(page
);
125 latter
= i_size
- off
;
126 if (latter
>= PAGE_SIZE
)
130 qty
/= sizeof(union afs_xdr_dir_block
);
134 for (tmp
= 0; tmp
< qty
; tmp
++) {
135 if (dbuf
->blocks
[tmp
].hdr
.magic
!= AFS_DIR_MAGIC
) {
136 printk("kAFS: %s(%lx): bad magic %d/%d is %04hx\n",
137 __func__
, dvnode
->vfs_inode
.i_ino
, tmp
, qty
,
138 ntohs(dbuf
->blocks
[tmp
].hdr
.magic
));
139 trace_afs_dir_check_failed(dvnode
, off
, i_size
);
144 /* Make sure each block is NUL terminated so we can reasonably
145 * use string functions on it. The filenames in the page
146 * *should* be NUL-terminated anyway.
148 ((u8
*)&dbuf
->blocks
[tmp
])[AFS_DIR_BLOCK_SIZE
- 1] = 0;
154 afs_stat_v(dvnode
, n_read_dir
);
162 * open an AFS directory file
164 static int afs_dir_open(struct inode
*inode
, struct file
*file
)
166 _enter("{%lu}", inode
->i_ino
);
168 BUILD_BUG_ON(sizeof(union afs_xdr_dir_block
) != 2048);
169 BUILD_BUG_ON(sizeof(union afs_xdr_dirent
) != 32);
171 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(inode
)->flags
))
174 return afs_open(inode
, file
);
178 * Read the directory into the pagecache in one go, scrubbing the previous
179 * contents. The list of pages is returned, pinning them so that they don't
180 * get reclaimed during the iteration.
182 static struct afs_read
*afs_read_dir(struct afs_vnode
*dvnode
, struct key
*key
)
184 struct afs_read
*req
;
186 int nr_pages
, nr_inline
, i
, n
;
190 i_size
= i_size_read(&dvnode
->vfs_inode
);
192 return ERR_PTR(-EIO
);
193 if (i_size
> 2048 * 1024)
194 return ERR_PTR(-EFBIG
);
196 _enter("%llu", i_size
);
198 /* Get a request record to hold the page list. We want to hold it
199 * inline if we can, but we don't want to make an order 1 allocation.
201 nr_pages
= (i_size
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
202 nr_inline
= nr_pages
;
203 if (nr_inline
> (PAGE_SIZE
- sizeof(*req
)) / sizeof(struct page
*))
206 req
= kzalloc(sizeof(*req
) + sizeof(struct page
*) * nr_inline
,
209 return ERR_PTR(-ENOMEM
);
211 refcount_set(&req
->usage
, 1);
212 req
->nr_pages
= nr_pages
;
213 req
->actual_len
= i_size
; /* May change */
214 req
->len
= nr_pages
* PAGE_SIZE
; /* We can ask for more than there is */
215 req
->data_version
= dvnode
->status
.data_version
; /* May change */
217 req
->pages
= req
->array
;
219 req
->pages
= kcalloc(nr_pages
, sizeof(struct page
*),
225 /* Get a list of all the pages that hold or will hold the directory
226 * content. We need to fill in any gaps that we might find where the
227 * memory reclaimer has been at work. If there are any gaps, we will
228 * need to reread the entire directory contents.
232 n
= find_get_pages_contig(dvnode
->vfs_inode
.i_mapping
, i
,
235 _debug("find %u at %u/%u", n
, i
, req
->nr_pages
);
237 gfp_t gfp
= dvnode
->vfs_inode
.i_mapping
->gfp_mask
;
239 if (test_and_clear_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
240 afs_stat_v(dvnode
, n_inval
);
243 req
->pages
[i
] = __page_cache_alloc(gfp
);
246 ret
= add_to_page_cache_lru(req
->pages
[i
],
247 dvnode
->vfs_inode
.i_mapping
,
252 set_page_private(req
->pages
[i
], 1);
253 SetPagePrivate(req
->pages
[i
]);
254 unlock_page(req
->pages
[i
]);
259 } while (i
< req
->nr_pages
);
261 /* If we're going to reload, we need to lock all the pages to prevent
264 if (!test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
)) {
266 for (i
= 0; i
< req
->nr_pages
; i
++)
267 if (lock_page_killable(req
->pages
[i
]) < 0)
270 if (test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
273 ret
= afs_fetch_data(dvnode
, key
, req
);
275 goto error_unlock_all
;
277 task_io_account_read(PAGE_SIZE
* req
->nr_pages
);
279 if (req
->len
< req
->file_size
)
280 goto content_has_grown
;
282 /* Validate the data we just read. */
284 for (i
= 0; i
< req
->nr_pages
; i
++)
285 if (!afs_dir_check_page(dvnode
, req
->pages
[i
],
287 goto error_unlock_all
;
289 // TODO: Trim excess pages
291 set_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
);
297 unlock_page(req
->pages
[--i
]);
304 unlock_page(req
->pages
[--i
]);
307 _leave(" = %d", ret
);
313 unlock_page(req
->pages
[--i
]);
319 * deal with one block in an AFS directory
321 static int afs_dir_iterate_block(struct dir_context
*ctx
,
322 union afs_xdr_dir_block
*block
,
325 union afs_xdr_dirent
*dire
;
326 unsigned offset
, next
, curr
;
330 _enter("%u,%x,%p,,",(unsigned)ctx
->pos
,blkoff
,block
);
332 curr
= (ctx
->pos
- blkoff
) / sizeof(union afs_xdr_dirent
);
334 /* walk through the block, an entry at a time */
335 for (offset
= (blkoff
== 0 ? AFS_DIR_RESV_BLOCKS0
: AFS_DIR_RESV_BLOCKS
);
336 offset
< AFS_DIR_SLOTS_PER_BLOCK
;
341 /* skip entries marked unused in the bitmap */
342 if (!(block
->hdr
.bitmap
[offset
/ 8] &
343 (1 << (offset
% 8)))) {
344 _debug("ENT[%zu.%u]: unused",
345 blkoff
/ sizeof(union afs_xdr_dir_block
), offset
);
348 next
* sizeof(union afs_xdr_dirent
);
352 /* got a valid entry */
353 dire
= &block
->dirents
[offset
];
354 nlen
= strnlen(dire
->u
.name
,
356 offset
* sizeof(union afs_xdr_dirent
));
358 _debug("ENT[%zu.%u]: %s %zu \"%s\"",
359 blkoff
/ sizeof(union afs_xdr_dir_block
), offset
,
360 (offset
< curr
? "skip" : "fill"),
363 /* work out where the next possible entry is */
364 for (tmp
= nlen
; tmp
> 15; tmp
-= sizeof(union afs_xdr_dirent
)) {
365 if (next
>= AFS_DIR_SLOTS_PER_BLOCK
) {
366 _debug("ENT[%zu.%u]:"
367 " %u travelled beyond end dir block"
369 blkoff
/ sizeof(union afs_xdr_dir_block
),
370 offset
, next
, tmp
, nlen
);
373 if (!(block
->hdr
.bitmap
[next
/ 8] &
374 (1 << (next
% 8)))) {
375 _debug("ENT[%zu.%u]:"
376 " %u unmarked extension (len %u/%zu)",
377 blkoff
/ sizeof(union afs_xdr_dir_block
),
378 offset
, next
, tmp
, nlen
);
382 _debug("ENT[%zu.%u]: ext %u/%zu",
383 blkoff
/ sizeof(union afs_xdr_dir_block
),
388 /* skip if starts before the current position */
392 /* found the next entry */
393 if (!dir_emit(ctx
, dire
->u
.name
, nlen
,
394 ntohl(dire
->u
.vnode
),
395 (ctx
->actor
== afs_lookup_filldir
||
396 ctx
->actor
== afs_lookup_one_filldir
)?
397 ntohl(dire
->u
.unique
) : DT_UNKNOWN
)) {
398 _leave(" = 0 [full]");
402 ctx
->pos
= blkoff
+ next
* sizeof(union afs_xdr_dirent
);
405 _leave(" = 1 [more]");
410 * iterate through the data blob that lists the contents of an AFS directory
412 static int afs_dir_iterate(struct inode
*dir
, struct dir_context
*ctx
,
415 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
416 struct afs_xdr_dir_page
*dbuf
;
417 union afs_xdr_dir_block
*dblock
;
418 struct afs_read
*req
;
420 unsigned blkoff
, limit
;
423 _enter("{%lu},%u,,", dir
->i_ino
, (unsigned)ctx
->pos
);
425 if (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(dir
)->flags
)) {
426 _leave(" = -ESTALE");
430 req
= afs_read_dir(dvnode
, key
);
434 /* round the file position up to the next entry boundary */
435 ctx
->pos
+= sizeof(union afs_xdr_dirent
) - 1;
436 ctx
->pos
&= ~(sizeof(union afs_xdr_dirent
) - 1);
438 /* walk through the blocks in sequence */
440 while (ctx
->pos
< req
->actual_len
) {
441 blkoff
= ctx
->pos
& ~(sizeof(union afs_xdr_dir_block
) - 1);
443 /* Fetch the appropriate page from the directory and re-add it
446 page
= req
->pages
[blkoff
/ PAGE_SIZE
];
451 mark_page_accessed(page
);
453 limit
= blkoff
& ~(PAGE_SIZE
- 1);
457 /* deal with the individual blocks stashed on this page */
459 dblock
= &dbuf
->blocks
[(blkoff
% PAGE_SIZE
) /
460 sizeof(union afs_xdr_dir_block
)];
461 ret
= afs_dir_iterate_block(ctx
, dblock
, blkoff
);
467 blkoff
+= sizeof(union afs_xdr_dir_block
);
469 } while (ctx
->pos
< dir
->i_size
&& blkoff
< limit
);
477 _leave(" = %d", ret
);
482 * read an AFS directory
484 static int afs_readdir(struct file
*file
, struct dir_context
*ctx
)
486 return afs_dir_iterate(file_inode(file
), ctx
, afs_file_key(file
));
490 * Search the directory for a single name
491 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
492 * uniquifier through dtype
494 static int afs_lookup_one_filldir(struct dir_context
*ctx
, const char *name
,
495 int nlen
, loff_t fpos
, u64 ino
, unsigned dtype
)
497 struct afs_lookup_one_cookie
*cookie
=
498 container_of(ctx
, struct afs_lookup_one_cookie
, ctx
);
500 _enter("{%s,%u},%s,%u,,%llu,%u",
501 cookie
->name
.name
, cookie
->name
.len
, name
, nlen
,
502 (unsigned long long) ino
, dtype
);
504 /* insanity checks first */
505 BUILD_BUG_ON(sizeof(union afs_xdr_dir_block
) != 2048);
506 BUILD_BUG_ON(sizeof(union afs_xdr_dirent
) != 32);
508 if (cookie
->name
.len
!= nlen
||
509 memcmp(cookie
->name
.name
, name
, nlen
) != 0) {
514 cookie
->fid
.vnode
= ino
;
515 cookie
->fid
.unique
= dtype
;
518 _leave(" = -1 [found]");
523 * Do a lookup of a single name in a directory
524 * - just returns the FID the dentry name maps to if found
526 static int afs_do_lookup_one(struct inode
*dir
, struct dentry
*dentry
,
527 struct afs_fid
*fid
, struct key
*key
)
529 struct afs_super_info
*as
= dir
->i_sb
->s_fs_info
;
530 struct afs_lookup_one_cookie cookie
= {
531 .ctx
.actor
= afs_lookup_one_filldir
,
532 .name
= dentry
->d_name
,
533 .fid
.vid
= as
->volume
->vid
537 _enter("{%lu},%p{%pd},", dir
->i_ino
, dentry
, dentry
);
539 /* search the directory */
540 ret
= afs_dir_iterate(dir
, &cookie
.ctx
, key
);
542 _leave(" = %d [iter]", ret
);
548 _leave(" = -ENOENT [not found]");
553 _leave(" = 0 { vn=%u u=%u }", fid
->vnode
, fid
->unique
);
558 * search the directory for a name
559 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
560 * uniquifier through dtype
562 static int afs_lookup_filldir(struct dir_context
*ctx
, const char *name
,
563 int nlen
, loff_t fpos
, u64 ino
, unsigned dtype
)
565 struct afs_lookup_cookie
*cookie
=
566 container_of(ctx
, struct afs_lookup_cookie
, ctx
);
569 _enter("{%s,%u},%s,%u,,%llu,%u",
570 cookie
->name
.name
, cookie
->name
.len
, name
, nlen
,
571 (unsigned long long) ino
, dtype
);
573 /* insanity checks first */
574 BUILD_BUG_ON(sizeof(union afs_xdr_dir_block
) != 2048);
575 BUILD_BUG_ON(sizeof(union afs_xdr_dirent
) != 32);
578 if (cookie
->nr_fids
< 50) {
579 cookie
->fids
[cookie
->nr_fids
].vnode
= ino
;
580 cookie
->fids
[cookie
->nr_fids
].unique
= dtype
;
583 } else if (cookie
->name
.len
== nlen
&&
584 memcmp(cookie
->name
.name
, name
, nlen
) == 0) {
585 cookie
->fids
[0].vnode
= ino
;
586 cookie
->fids
[0].unique
= dtype
;
588 if (cookie
->one_only
)
592 ret
= cookie
->nr_fids
>= 50 ? -1 : 0;
593 _leave(" = %d", ret
);
598 * Do a lookup in a directory. We make use of bulk lookup to query a slew of
599 * files in one go and create inodes for them. The inode of the file we were
600 * asked for is returned.
602 static struct inode
*afs_do_lookup(struct inode
*dir
, struct dentry
*dentry
,
605 struct afs_lookup_cookie
*cookie
;
606 struct afs_cb_interest
*cbi
= NULL
;
607 struct afs_super_info
*as
= dir
->i_sb
->s_fs_info
;
608 struct afs_iget_data data
;
609 struct afs_fs_cursor fc
;
610 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
611 struct inode
*inode
= NULL
;
614 _enter("{%lu},%p{%pd},", dir
->i_ino
, dentry
, dentry
);
616 cookie
= kzalloc(sizeof(struct afs_lookup_cookie
), GFP_KERNEL
);
618 return ERR_PTR(-ENOMEM
);
620 cookie
->ctx
.actor
= afs_lookup_filldir
;
621 cookie
->name
= dentry
->d_name
;
622 cookie
->nr_fids
= 1; /* slot 0 is saved for the fid we actually want */
624 read_seqlock_excl(&dvnode
->cb_lock
);
625 if (dvnode
->cb_interest
&&
626 dvnode
->cb_interest
->server
&&
627 test_bit(AFS_SERVER_FL_NO_IBULK
, &dvnode
->cb_interest
->server
->flags
))
628 cookie
->one_only
= true;
629 read_sequnlock_excl(&dvnode
->cb_lock
);
631 for (i
= 0; i
< 50; i
++)
632 cookie
->fids
[i
].vid
= as
->volume
->vid
;
634 /* search the directory */
635 ret
= afs_dir_iterate(dir
, &cookie
->ctx
, key
);
637 inode
= ERR_PTR(ret
);
641 inode
= ERR_PTR(-ENOENT
);
645 /* Check to see if we already have an inode for the primary fid. */
646 data
.volume
= dvnode
->volume
;
647 data
.fid
= cookie
->fids
[0];
648 inode
= ilookup5(dir
->i_sb
, cookie
->fids
[0].vnode
, afs_iget5_test
, &data
);
652 /* Need space for examining all the selected files */
653 inode
= ERR_PTR(-ENOMEM
);
654 cookie
->statuses
= kcalloc(cookie
->nr_fids
, sizeof(struct afs_file_status
),
656 if (!cookie
->statuses
)
659 cookie
->callbacks
= kcalloc(cookie
->nr_fids
, sizeof(struct afs_callback
),
661 if (!cookie
->callbacks
)
664 /* Try FS.InlineBulkStatus first. Abort codes for the individual
665 * lookups contained therein are stored in the reply without aborting
666 * the whole operation.
668 if (cookie
->one_only
)
669 goto no_inline_bulk_status
;
671 inode
= ERR_PTR(-ERESTARTSYS
);
672 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
673 while (afs_select_fileserver(&fc
)) {
674 if (test_bit(AFS_SERVER_FL_NO_IBULK
,
675 &fc
.cbi
->server
->flags
)) {
676 fc
.ac
.abort_code
= RX_INVALID_OPERATION
;
677 fc
.ac
.error
= -ECONNABORTED
;
680 afs_fs_inline_bulk_status(&fc
,
685 cookie
->nr_fids
, NULL
);
688 if (fc
.ac
.error
== 0)
689 cbi
= afs_get_cb_interest(fc
.cbi
);
690 if (fc
.ac
.abort_code
== RX_INVALID_OPERATION
)
691 set_bit(AFS_SERVER_FL_NO_IBULK
, &fc
.cbi
->server
->flags
);
692 inode
= ERR_PTR(afs_end_vnode_operation(&fc
));
697 if (fc
.ac
.abort_code
!= RX_INVALID_OPERATION
)
700 no_inline_bulk_status
:
701 /* We could try FS.BulkStatus next, but this aborts the entire op if
702 * any of the lookups fails - so, for the moment, revert to
703 * FS.FetchStatus for just the primary fid.
706 inode
= ERR_PTR(-ERESTARTSYS
);
707 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
708 while (afs_select_fileserver(&fc
)) {
709 afs_fs_fetch_status(&fc
,
717 if (fc
.ac
.error
== 0)
718 cbi
= afs_get_cb_interest(fc
.cbi
);
719 inode
= ERR_PTR(afs_end_vnode_operation(&fc
));
725 for (i
= 0; i
< cookie
->nr_fids
; i
++)
726 cookie
->statuses
[i
].abort_code
= 0;
729 /* Turn all the files into inodes and save the first one - which is the
730 * one we actually want.
732 if (cookie
->statuses
[0].abort_code
!= 0)
733 inode
= ERR_PTR(afs_abort_to_error(cookie
->statuses
[0].abort_code
));
735 for (i
= 0; i
< cookie
->nr_fids
; i
++) {
738 if (cookie
->statuses
[i
].abort_code
!= 0)
741 ti
= afs_iget(dir
->i_sb
, key
, &cookie
->fids
[i
],
742 &cookie
->statuses
[i
],
743 &cookie
->callbacks
[i
],
754 afs_put_cb_interest(afs_v2net(dvnode
), cbi
);
755 kfree(cookie
->callbacks
);
757 kfree(cookie
->statuses
);
764 * Look up an entry in a directory with @sys substitution.
766 static struct dentry
*afs_lookup_atsys(struct inode
*dir
, struct dentry
*dentry
,
769 struct afs_sysnames
*subs
;
770 struct afs_net
*net
= afs_i2net(dir
);
772 char *buf
, *p
, *name
;
777 ret
= ERR_PTR(-ENOMEM
);
778 p
= buf
= kmalloc(AFSNAMEMAX
, GFP_KERNEL
);
781 if (dentry
->d_name
.len
> 4) {
782 memcpy(p
, dentry
->d_name
.name
, dentry
->d_name
.len
- 4);
783 p
+= dentry
->d_name
.len
- 4;
786 /* There is an ordered list of substitutes that we have to try. */
787 read_lock(&net
->sysnames_lock
);
788 subs
= net
->sysnames
;
789 refcount_inc(&subs
->usage
);
790 read_unlock(&net
->sysnames_lock
);
792 for (i
= 0; i
< subs
->nr
; i
++) {
793 name
= subs
->subs
[i
];
794 len
= dentry
->d_name
.len
- 4 + strlen(name
);
795 if (len
>= AFSNAMEMAX
) {
796 ret
= ERR_PTR(-ENAMETOOLONG
);
801 ret
= lookup_one_len(buf
, dentry
->d_parent
, len
);
802 if (IS_ERR(ret
) || d_is_positive(ret
))
807 /* We don't want to d_add() the @sys dentry here as we don't want to
808 * the cached dentry to hide changes to the sysnames list.
812 afs_put_sysnames(subs
);
820 * look up an entry in a directory
822 static struct dentry
*afs_lookup(struct inode
*dir
, struct dentry
*dentry
,
825 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
830 _enter("{%x:%u},%p{%pd},",
831 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, dentry
);
833 ASSERTCMP(d_inode(dentry
), ==, NULL
);
835 if (dentry
->d_name
.len
>= AFSNAMEMAX
) {
836 _leave(" = -ENAMETOOLONG");
837 return ERR_PTR(-ENAMETOOLONG
);
840 if (test_bit(AFS_VNODE_DELETED
, &dvnode
->flags
)) {
841 _leave(" = -ESTALE");
842 return ERR_PTR(-ESTALE
);
845 key
= afs_request_key(dvnode
->volume
->cell
);
847 _leave(" = %ld [key]", PTR_ERR(key
));
848 return ERR_CAST(key
);
851 ret
= afs_validate(dvnode
, key
);
854 _leave(" = %d [val]", ret
);
858 if (dentry
->d_name
.len
>= 4 &&
859 dentry
->d_name
.name
[dentry
->d_name
.len
- 4] == '@' &&
860 dentry
->d_name
.name
[dentry
->d_name
.len
- 3] == 's' &&
861 dentry
->d_name
.name
[dentry
->d_name
.len
- 2] == 'y' &&
862 dentry
->d_name
.name
[dentry
->d_name
.len
- 1] == 's')
863 return afs_lookup_atsys(dir
, dentry
, key
);
865 afs_stat_v(dvnode
, n_lookup
);
866 inode
= afs_do_lookup(dir
, dentry
, key
);
868 ret
= PTR_ERR(inode
);
869 if (ret
== -ENOENT
) {
870 inode
= afs_try_auto_mntpt(dentry
, dir
);
871 if (!IS_ERR(inode
)) {
876 ret
= PTR_ERR(inode
);
880 if (ret
== -ENOENT
) {
882 _leave(" = NULL [negative]");
885 _leave(" = %d [do]", ret
);
888 dentry
->d_fsdata
= (void *)(unsigned long)dvnode
->status
.data_version
;
890 /* instantiate the dentry */
893 _leave(" = %ld", PTR_ERR(inode
));
894 return ERR_CAST(inode
);
898 d_add(dentry
, inode
);
899 _leave(" = 0 { ino=%lu v=%u }",
900 d_inode(dentry
)->i_ino
,
901 d_inode(dentry
)->i_generation
);
907 * check that a dentry lookup hit has found a valid entry
908 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
911 static int afs_d_revalidate(struct dentry
*dentry
, unsigned int flags
)
913 struct afs_vnode
*vnode
, *dir
;
914 struct afs_fid
uninitialized_var(fid
);
915 struct dentry
*parent
;
918 long dir_version
, de_version
;
921 if (flags
& LOOKUP_RCU
)
924 if (d_really_is_positive(dentry
)) {
925 vnode
= AFS_FS_I(d_inode(dentry
));
926 _enter("{v={%x:%u} n=%pd fl=%lx},",
927 vnode
->fid
.vid
, vnode
->fid
.vnode
, dentry
,
930 _enter("{neg n=%pd}", dentry
);
933 key
= afs_request_key(AFS_FS_S(dentry
->d_sb
)->volume
->cell
);
937 if (d_really_is_positive(dentry
)) {
938 inode
= d_inode(dentry
);
940 vnode
= AFS_FS_I(inode
);
941 afs_validate(vnode
, key
);
942 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
))
947 /* lock down the parent dentry so we can peer at it */
948 parent
= dget_parent(dentry
);
949 dir
= AFS_FS_I(d_inode(parent
));
951 /* validate the parent directory */
952 afs_validate(dir
, key
);
954 if (test_bit(AFS_VNODE_DELETED
, &dir
->flags
)) {
955 _debug("%pd: parent dir deleted", dentry
);
959 /* We only need to invalidate a dentry if the server's copy changed
960 * behind our back. If we made the change, it's no problem. Note that
961 * on a 32-bit system, we only have 32 bits in the dentry to store the
964 dir_version
= (long)dir
->status
.data_version
;
965 de_version
= (long)dentry
->d_fsdata
;
966 if (de_version
== dir_version
)
969 dir_version
= (long)dir
->invalid_before
;
970 if (de_version
- dir_version
>= 0)
973 _debug("dir modified");
974 afs_stat_v(dir
, n_reval
);
976 /* search the directory for this vnode */
977 ret
= afs_do_lookup_one(&dir
->vfs_inode
, dentry
, &fid
, key
);
980 /* the filename maps to something */
981 if (d_really_is_negative(dentry
))
983 inode
= d_inode(dentry
);
984 if (is_bad_inode(inode
)) {
985 printk("kAFS: afs_d_revalidate: %pd2 has bad inode\n",
990 vnode
= AFS_FS_I(inode
);
992 /* if the vnode ID has changed, then the dirent points to a
994 if (fid
.vnode
!= vnode
->fid
.vnode
) {
995 _debug("%pd: dirent changed [%u != %u]",
1001 /* if the vnode ID uniqifier has changed, then the file has
1002 * been deleted and replaced, and the original vnode ID has
1004 if (fid
.unique
!= vnode
->fid
.unique
) {
1005 _debug("%pd: file deleted (uq %u -> %u I:%u)",
1008 vnode
->vfs_inode
.i_generation
);
1009 write_seqlock(&vnode
->cb_lock
);
1010 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
1011 write_sequnlock(&vnode
->cb_lock
);
1017 /* the filename is unknown */
1018 _debug("%pd: dirent not found", dentry
);
1019 if (d_really_is_positive(dentry
))
1024 _debug("failed to iterate dir %pd: %d",
1026 goto out_bad_parent
;
1030 dentry
->d_fsdata
= (void *)dir_version
;
1033 _leave(" = 1 [valid]");
1036 /* the dirent, if it exists, now points to a different vnode */
1038 spin_lock(&dentry
->d_lock
);
1039 dentry
->d_flags
|= DCACHE_NFSFS_RENAMED
;
1040 spin_unlock(&dentry
->d_lock
);
1043 _debug("dropping dentry %pd2", dentry
);
1048 _leave(" = 0 [bad]");
1053 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
1055 * - called from dput() when d_count is going to 0.
1056 * - return 1 to request dentry be unhashed, 0 otherwise
1058 static int afs_d_delete(const struct dentry
*dentry
)
1060 _enter("%pd", dentry
);
1062 if (dentry
->d_flags
& DCACHE_NFSFS_RENAMED
)
1065 if (d_really_is_positive(dentry
) &&
1066 (test_bit(AFS_VNODE_DELETED
, &AFS_FS_I(d_inode(dentry
))->flags
) ||
1067 test_bit(AFS_VNODE_PSEUDODIR
, &AFS_FS_I(d_inode(dentry
))->flags
)))
1070 _leave(" = 0 [keep]");
1074 _leave(" = 1 [zap]");
1079 * handle dentry release
1081 void afs_d_release(struct dentry
*dentry
)
1083 _enter("%pd", dentry
);
1087 * Create a new inode for create/mkdir/symlink
1089 static void afs_vnode_new_inode(struct afs_fs_cursor
*fc
,
1090 struct dentry
*new_dentry
,
1091 struct afs_fid
*newfid
,
1092 struct afs_file_status
*newstatus
,
1093 struct afs_callback
*newcb
)
1095 struct afs_vnode
*vnode
;
1096 struct inode
*inode
;
1098 if (fc
->ac
.error
< 0)
1103 inode
= afs_iget(fc
->vnode
->vfs_inode
.i_sb
, fc
->key
,
1104 newfid
, newstatus
, newcb
, fc
->cbi
);
1105 if (IS_ERR(inode
)) {
1106 /* ENOMEM or EINTR at a really inconvenient time - just abandon
1107 * the new directory on the server.
1109 fc
->ac
.error
= PTR_ERR(inode
);
1113 vnode
= AFS_FS_I(inode
);
1114 set_bit(AFS_VNODE_NEW_CONTENT
, &vnode
->flags
);
1115 d_add(new_dentry
, inode
);
1119 * create a directory on an AFS filesystem
1121 static int afs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1123 struct afs_file_status newstatus
;
1124 struct afs_fs_cursor fc
;
1125 struct afs_callback newcb
;
1126 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
1127 struct afs_fid newfid
;
1129 u64 data_version
= dvnode
->status
.data_version
;
1134 _enter("{%x:%u},{%pd},%ho",
1135 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, mode
);
1137 key
= afs_request_key(dvnode
->volume
->cell
);
1144 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
1145 while (afs_select_fileserver(&fc
)) {
1146 fc
.cb_break
= dvnode
->cb_break
+ dvnode
->cb_s_break
;
1147 afs_fs_create(&fc
, dentry
->d_name
.name
, mode
, data_version
,
1148 &newfid
, &newstatus
, &newcb
);
1151 afs_check_for_remote_deletion(&fc
, fc
.vnode
);
1152 afs_vnode_commit_status(&fc
, dvnode
, fc
.cb_break
);
1153 afs_vnode_new_inode(&fc
, dentry
, &newfid
, &newstatus
, &newcb
);
1154 ret
= afs_end_vnode_operation(&fc
);
1162 test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1163 afs_edit_dir_add(dvnode
, &dentry
->d_name
, &newfid
,
1164 afs_edit_dir_for_create
);
1174 _leave(" = %d", ret
);
1179 * Remove a subdir from a directory.
1181 static void afs_dir_remove_subdir(struct dentry
*dentry
)
1183 if (d_really_is_positive(dentry
)) {
1184 struct afs_vnode
*vnode
= AFS_FS_I(d_inode(dentry
));
1186 clear_nlink(&vnode
->vfs_inode
);
1187 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
1188 clear_bit(AFS_VNODE_CB_PROMISED
, &vnode
->flags
);
1189 clear_bit(AFS_VNODE_DIR_VALID
, &vnode
->flags
);
1194 * remove a directory from an AFS filesystem
1196 static int afs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
1198 struct afs_fs_cursor fc
;
1199 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
1201 u64 data_version
= dvnode
->status
.data_version
;
1204 _enter("{%x:%u},{%pd}",
1205 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
);
1207 key
= afs_request_key(dvnode
->volume
->cell
);
1214 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
1215 while (afs_select_fileserver(&fc
)) {
1216 fc
.cb_break
= dvnode
->cb_break
+ dvnode
->cb_s_break
;
1217 afs_fs_remove(&fc
, dentry
->d_name
.name
, true,
1221 afs_vnode_commit_status(&fc
, dvnode
, fc
.cb_break
);
1222 ret
= afs_end_vnode_operation(&fc
);
1224 afs_dir_remove_subdir(dentry
);
1225 if (test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1226 afs_edit_dir_remove(dvnode
, &dentry
->d_name
,
1227 afs_edit_dir_for_rmdir
);
1237 * Remove a link to a file or symlink from a directory.
1239 * If the file was not deleted due to excess hard links, the fileserver will
1240 * break the callback promise on the file - if it had one - before it returns
1241 * to us, and if it was deleted, it won't
1243 * However, if we didn't have a callback promise outstanding, or it was
1244 * outstanding on a different server, then it won't break it either...
1246 static int afs_dir_remove_link(struct dentry
*dentry
, struct key
*key
,
1247 unsigned long d_version_before
,
1248 unsigned long d_version_after
)
1253 /* There were no intervening changes on the server if the version
1254 * number we got back was incremented by exactly 1.
1256 dir_valid
= (d_version_after
== d_version_before
+ 1);
1258 if (d_really_is_positive(dentry
)) {
1259 struct afs_vnode
*vnode
= AFS_FS_I(d_inode(dentry
));
1262 drop_nlink(&vnode
->vfs_inode
);
1263 if (vnode
->vfs_inode
.i_nlink
== 0) {
1264 set_bit(AFS_VNODE_DELETED
, &vnode
->flags
);
1265 clear_bit(AFS_VNODE_CB_PROMISED
, &vnode
->flags
);
1269 clear_bit(AFS_VNODE_CB_PROMISED
, &vnode
->flags
);
1271 if (test_bit(AFS_VNODE_DELETED
, &vnode
->flags
))
1272 kdebug("AFS_VNODE_DELETED");
1274 ret
= afs_validate(vnode
, key
);
1278 _debug("nlink %d [val %d]", vnode
->vfs_inode
.i_nlink
, ret
);
1285 * Remove a file or symlink from an AFS filesystem.
1287 static int afs_unlink(struct inode
*dir
, struct dentry
*dentry
)
1289 struct afs_fs_cursor fc
;
1290 struct afs_vnode
*dvnode
= AFS_FS_I(dir
), *vnode
;
1292 unsigned long d_version
= (unsigned long)dentry
->d_fsdata
;
1293 u64 data_version
= dvnode
->status
.data_version
;
1296 _enter("{%x:%u},{%pd}",
1297 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
);
1299 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
1300 return -ENAMETOOLONG
;
1302 key
= afs_request_key(dvnode
->volume
->cell
);
1308 /* Try to make sure we have a callback promise on the victim. */
1309 if (d_really_is_positive(dentry
)) {
1310 vnode
= AFS_FS_I(d_inode(dentry
));
1311 ret
= afs_validate(vnode
, key
);
1317 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
1318 while (afs_select_fileserver(&fc
)) {
1319 fc
.cb_break
= dvnode
->cb_break
+ dvnode
->cb_s_break
;
1320 afs_fs_remove(&fc
, dentry
->d_name
.name
, false,
1324 afs_vnode_commit_status(&fc
, dvnode
, fc
.cb_break
);
1325 ret
= afs_end_vnode_operation(&fc
);
1327 ret
= afs_dir_remove_link(
1328 dentry
, key
, d_version
,
1329 (unsigned long)dvnode
->status
.data_version
);
1331 test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1332 afs_edit_dir_remove(dvnode
, &dentry
->d_name
,
1333 afs_edit_dir_for_unlink
);
1339 _leave(" = %d", ret
);
1344 * create a regular file on an AFS filesystem
1346 static int afs_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
1349 struct afs_fs_cursor fc
;
1350 struct afs_file_status newstatus
;
1351 struct afs_callback newcb
;
1352 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
1353 struct afs_fid newfid
;
1355 u64 data_version
= dvnode
->status
.data_version
;
1360 _enter("{%x:%u},{%pd},%ho,",
1361 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
, mode
);
1363 ret
= -ENAMETOOLONG
;
1364 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
1367 key
= afs_request_key(dvnode
->volume
->cell
);
1374 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
1375 while (afs_select_fileserver(&fc
)) {
1376 fc
.cb_break
= dvnode
->cb_break
+ dvnode
->cb_s_break
;
1377 afs_fs_create(&fc
, dentry
->d_name
.name
, mode
, data_version
,
1378 &newfid
, &newstatus
, &newcb
);
1381 afs_check_for_remote_deletion(&fc
, fc
.vnode
);
1382 afs_vnode_commit_status(&fc
, dvnode
, fc
.cb_break
);
1383 afs_vnode_new_inode(&fc
, dentry
, &newfid
, &newstatus
, &newcb
);
1384 ret
= afs_end_vnode_operation(&fc
);
1391 if (test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1392 afs_edit_dir_add(dvnode
, &dentry
->d_name
, &newfid
,
1393 afs_edit_dir_for_create
);
1403 _leave(" = %d", ret
);
1408 * create a hard link between files in an AFS filesystem
1410 static int afs_link(struct dentry
*from
, struct inode
*dir
,
1411 struct dentry
*dentry
)
1413 struct afs_fs_cursor fc
;
1414 struct afs_vnode
*dvnode
, *vnode
;
1419 vnode
= AFS_FS_I(d_inode(from
));
1420 dvnode
= AFS_FS_I(dir
);
1421 data_version
= dvnode
->status
.data_version
;
1423 _enter("{%x:%u},{%x:%u},{%pd}",
1424 vnode
->fid
.vid
, vnode
->fid
.vnode
,
1425 dvnode
->fid
.vid
, dvnode
->fid
.vnode
,
1428 ret
= -ENAMETOOLONG
;
1429 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
1432 key
= afs_request_key(dvnode
->volume
->cell
);
1439 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
1440 if (mutex_lock_interruptible_nested(&vnode
->io_lock
, 1) < 0) {
1441 afs_end_vnode_operation(&fc
);
1445 while (afs_select_fileserver(&fc
)) {
1446 fc
.cb_break
= dvnode
->cb_break
+ dvnode
->cb_s_break
;
1447 fc
.cb_break_2
= vnode
->cb_break
+ vnode
->cb_s_break
;
1448 afs_fs_link(&fc
, vnode
, dentry
->d_name
.name
, data_version
);
1451 afs_vnode_commit_status(&fc
, dvnode
, fc
.cb_break
);
1452 afs_vnode_commit_status(&fc
, vnode
, fc
.cb_break_2
);
1453 ihold(&vnode
->vfs_inode
);
1454 d_instantiate(dentry
, &vnode
->vfs_inode
);
1456 mutex_unlock(&vnode
->io_lock
);
1457 ret
= afs_end_vnode_operation(&fc
);
1464 if (test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1465 afs_edit_dir_add(dvnode
, &dentry
->d_name
, &vnode
->fid
,
1466 afs_edit_dir_for_link
);
1476 _leave(" = %d", ret
);
1481 * create a symlink in an AFS filesystem
1483 static int afs_symlink(struct inode
*dir
, struct dentry
*dentry
,
1484 const char *content
)
1486 struct afs_fs_cursor fc
;
1487 struct afs_file_status newstatus
;
1488 struct afs_vnode
*dvnode
= AFS_FS_I(dir
);
1489 struct afs_fid newfid
;
1491 u64 data_version
= dvnode
->status
.data_version
;
1494 _enter("{%x:%u},{%pd},%s",
1495 dvnode
->fid
.vid
, dvnode
->fid
.vnode
, dentry
,
1498 ret
= -ENAMETOOLONG
;
1499 if (dentry
->d_name
.len
>= AFSNAMEMAX
)
1503 if (strlen(content
) >= AFSPATHMAX
)
1506 key
= afs_request_key(dvnode
->volume
->cell
);
1513 if (afs_begin_vnode_operation(&fc
, dvnode
, key
)) {
1514 while (afs_select_fileserver(&fc
)) {
1515 fc
.cb_break
= dvnode
->cb_break
+ dvnode
->cb_s_break
;
1516 afs_fs_symlink(&fc
, dentry
->d_name
.name
,
1517 content
, data_version
,
1518 &newfid
, &newstatus
);
1521 afs_check_for_remote_deletion(&fc
, fc
.vnode
);
1522 afs_vnode_commit_status(&fc
, dvnode
, fc
.cb_break
);
1523 afs_vnode_new_inode(&fc
, dentry
, &newfid
, &newstatus
, NULL
);
1524 ret
= afs_end_vnode_operation(&fc
);
1531 if (test_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1532 afs_edit_dir_add(dvnode
, &dentry
->d_name
, &newfid
,
1533 afs_edit_dir_for_symlink
);
1543 _leave(" = %d", ret
);
1548 * rename a file in an AFS filesystem and/or move it between directories
1550 static int afs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1551 struct inode
*new_dir
, struct dentry
*new_dentry
,
1554 struct afs_fs_cursor fc
;
1555 struct afs_vnode
*orig_dvnode
, *new_dvnode
, *vnode
;
1557 u64 orig_data_version
, new_data_version
;
1558 bool new_negative
= d_is_negative(new_dentry
);
1564 vnode
= AFS_FS_I(d_inode(old_dentry
));
1565 orig_dvnode
= AFS_FS_I(old_dir
);
1566 new_dvnode
= AFS_FS_I(new_dir
);
1567 orig_data_version
= orig_dvnode
->status
.data_version
;
1568 new_data_version
= new_dvnode
->status
.data_version
;
1570 _enter("{%x:%u},{%x:%u},{%x:%u},{%pd}",
1571 orig_dvnode
->fid
.vid
, orig_dvnode
->fid
.vnode
,
1572 vnode
->fid
.vid
, vnode
->fid
.vnode
,
1573 new_dvnode
->fid
.vid
, new_dvnode
->fid
.vnode
,
1576 key
= afs_request_key(orig_dvnode
->volume
->cell
);
1583 if (afs_begin_vnode_operation(&fc
, orig_dvnode
, key
)) {
1584 if (orig_dvnode
!= new_dvnode
) {
1585 if (mutex_lock_interruptible_nested(&new_dvnode
->io_lock
, 1) < 0) {
1586 afs_end_vnode_operation(&fc
);
1590 while (afs_select_fileserver(&fc
)) {
1591 fc
.cb_break
= orig_dvnode
->cb_break
+ orig_dvnode
->cb_s_break
;
1592 fc
.cb_break_2
= new_dvnode
->cb_break
+ new_dvnode
->cb_s_break
;
1593 afs_fs_rename(&fc
, old_dentry
->d_name
.name
,
1594 new_dvnode
, new_dentry
->d_name
.name
,
1595 orig_data_version
, new_data_version
);
1598 afs_vnode_commit_status(&fc
, orig_dvnode
, fc
.cb_break
);
1599 afs_vnode_commit_status(&fc
, new_dvnode
, fc
.cb_break_2
);
1600 if (orig_dvnode
!= new_dvnode
)
1601 mutex_unlock(&new_dvnode
->io_lock
);
1602 ret
= afs_end_vnode_operation(&fc
);
1608 if (test_bit(AFS_VNODE_DIR_VALID
, &orig_dvnode
->flags
))
1609 afs_edit_dir_remove(orig_dvnode
, &old_dentry
->d_name
,
1610 afs_edit_dir_for_rename
);
1612 if (!new_negative
&&
1613 test_bit(AFS_VNODE_DIR_VALID
, &new_dvnode
->flags
))
1614 afs_edit_dir_remove(new_dvnode
, &new_dentry
->d_name
,
1615 afs_edit_dir_for_rename
);
1617 if (test_bit(AFS_VNODE_DIR_VALID
, &new_dvnode
->flags
))
1618 afs_edit_dir_add(new_dvnode
, &new_dentry
->d_name
,
1619 &vnode
->fid
, afs_edit_dir_for_rename
);
1625 _leave(" = %d", ret
);
1630 * Release a directory page and clean up its private state if it's not busy
1631 * - return true if the page can now be released, false if not
1633 static int afs_dir_releasepage(struct page
*page
, gfp_t gfp_flags
)
1635 struct afs_vnode
*dvnode
= AFS_FS_I(page
->mapping
->host
);
1637 _enter("{{%x:%u}[%lu]}", dvnode
->fid
.vid
, dvnode
->fid
.vnode
, page
->index
);
1639 set_page_private(page
, 0);
1640 ClearPagePrivate(page
);
1642 /* The directory will need reloading. */
1643 if (test_and_clear_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1644 afs_stat_v(dvnode
, n_relpg
);
1649 * invalidate part or all of a page
1650 * - release a page and clean up its private data if offset is 0 (indicating
1653 static void afs_dir_invalidatepage(struct page
*page
, unsigned int offset
,
1654 unsigned int length
)
1656 struct afs_vnode
*dvnode
= AFS_FS_I(page
->mapping
->host
);
1658 _enter("{%lu},%u,%u", page
->index
, offset
, length
);
1660 BUG_ON(!PageLocked(page
));
1662 /* The directory will need reloading. */
1663 if (test_and_clear_bit(AFS_VNODE_DIR_VALID
, &dvnode
->flags
))
1664 afs_stat_v(dvnode
, n_inval
);
1666 /* we clean up only if the entire page is being invalidated */
1667 if (offset
== 0 && length
== PAGE_SIZE
) {
1668 set_page_private(page
, 0);
1669 ClearPagePrivate(page
);