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>
24 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
26 static int afs_dir_open(struct inode *inode, struct file *file);
27 static int afs_readdir(struct file *file, struct dir_context *ctx);
28 static int afs_d_revalidate(struct dentry *dentry, unsigned int flags);
29 static int afs_d_delete(const struct dentry *dentry);
30 static void afs_d_iput(struct dentry *dentry, struct inode *inode);
31 static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name, int nlen,
32 loff_t fpos, u64 ino, unsigned dtype);
33 static int afs_lookup_filldir(struct dir_context *ctx, const char *name, int nlen,
34 loff_t fpos, u64 ino, unsigned dtype);
35 static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
37 static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
38 static int afs_rmdir(struct inode *dir, struct dentry *dentry);
39 static int afs_unlink(struct inode *dir, struct dentry *dentry);
40 static int afs_link(struct dentry *from, struct inode *dir,
41 struct dentry *dentry);
42 static int afs_symlink(struct inode *dir, struct dentry *dentry,
44 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
45 struct inode *new_dir, struct dentry *new_dentry,
47 static int afs_dir_releasepage(struct page *page, gfp_t gfp_flags);
48 static void afs_dir_invalidatepage(struct page *page, unsigned int offset,
51 static int afs_dir_set_page_dirty(struct page *page)
53 BUG(); /* This should never happen. */
56 const struct file_operations afs_dir_file_operations = {
58 .release = afs_release,
59 .iterate_shared = afs_readdir,
61 .llseek = generic_file_llseek,
64 const struct inode_operations afs_dir_inode_operations = {
69 .symlink = afs_symlink,
73 .permission = afs_permission,
74 .getattr = afs_getattr,
75 .setattr = afs_setattr,
76 .listxattr = afs_listxattr,
79 const struct address_space_operations afs_dir_aops = {
80 .set_page_dirty = afs_dir_set_page_dirty,
81 .releasepage = afs_dir_releasepage,
82 .invalidatepage = afs_dir_invalidatepage,
85 const struct dentry_operations afs_fs_dentry_operations = {
86 .d_revalidate = afs_d_revalidate,
87 .d_delete = afs_d_delete,
88 .d_release = afs_d_release,
89 .d_automount = afs_d_automount,
93 struct afs_lookup_one_cookie {
94 struct dir_context ctx;
100 struct afs_lookup_cookie {
101 struct dir_context ctx;
105 unsigned short nr_fids;
106 struct afs_status_cb *statuses;
107 struct afs_fid fids[50];
111 * check that a directory page is valid
113 static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page,
116 struct afs_xdr_dir_page *dbuf;
120 /* Determine how many magic numbers there should be in this page, but
121 * we must take care because the directory may change size under us.
123 off = page_offset(page);
127 latter = i_size - off;
128 if (latter >= PAGE_SIZE)
132 qty /= sizeof(union afs_xdr_dir_block);
136 for (tmp = 0; tmp < qty; tmp++) {
137 if (dbuf->blocks[tmp].hdr.magic != AFS_DIR_MAGIC) {
138 printk("kAFS: %s(%lx): bad magic %d/%d is %04hx\n",
139 __func__, dvnode->vfs_inode.i_ino, tmp, qty,
140 ntohs(dbuf->blocks[tmp].hdr.magic));
141 trace_afs_dir_check_failed(dvnode, off, i_size);
143 trace_afs_file_error(dvnode, -EIO, afs_file_error_dir_bad_magic);
147 /* Make sure each block is NUL terminated so we can reasonably
148 * use string functions on it. The filenames in the page
149 * *should* be NUL-terminated anyway.
151 ((u8 *)&dbuf->blocks[tmp])[AFS_DIR_BLOCK_SIZE - 1] = 0;
157 afs_stat_v(dvnode, n_read_dir);
165 * Check the contents of a directory that we've just read.
167 static bool afs_dir_check_pages(struct afs_vnode *dvnode, struct afs_read *req)
169 struct afs_xdr_dir_page *dbuf;
170 unsigned int i, j, qty = PAGE_SIZE / sizeof(union afs_xdr_dir_block);
172 for (i = 0; i < req->nr_pages; i++)
173 if (!afs_dir_check_page(dvnode, req->pages[i], req->actual_len))
178 pr_warn("DIR %llx:%llx f=%llx l=%llx al=%llx r=%llx\n",
179 dvnode->fid.vid, dvnode->fid.vnode,
180 req->file_size, req->len, req->actual_len, req->remain);
181 pr_warn("DIR %llx %x %x %x\n",
182 req->pos, req->index, req->nr_pages, req->offset);
184 for (i = 0; i < req->nr_pages; i++) {
185 dbuf = kmap(req->pages[i]);
186 for (j = 0; j < qty; j++) {
187 union afs_xdr_dir_block *block = &dbuf->blocks[j];
189 pr_warn("[%02x] %32phN\n", i * qty + j, block);
191 kunmap(req->pages[i]);
197 * open an AFS directory file
199 static int afs_dir_open(struct inode *inode, struct file *file)
201 _enter("{%lu}", inode->i_ino);
203 BUILD_BUG_ON(sizeof(union afs_xdr_dir_block) != 2048);
204 BUILD_BUG_ON(sizeof(union afs_xdr_dirent) != 32);
206 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags))
209 return afs_open(inode, file);
213 * Read the directory into the pagecache in one go, scrubbing the previous
214 * contents. The list of pages is returned, pinning them so that they don't
215 * get reclaimed during the iteration.
217 static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)
218 __acquires(&dvnode->validate_lock)
220 struct afs_read *req;
222 int nr_pages, nr_inline, i, n;
226 i_size = i_size_read(&dvnode->vfs_inode);
228 return ERR_PTR(afs_bad(dvnode, afs_file_error_dir_small));
229 if (i_size > 2048 * 1024) {
230 trace_afs_file_error(dvnode, -EFBIG, afs_file_error_dir_big);
231 return ERR_PTR(-EFBIG);
234 _enter("%llu", i_size);
236 /* Get a request record to hold the page list. We want to hold it
237 * inline if we can, but we don't want to make an order 1 allocation.
239 nr_pages = (i_size + PAGE_SIZE - 1) / PAGE_SIZE;
240 nr_inline = nr_pages;
241 if (nr_inline > (PAGE_SIZE - sizeof(*req)) / sizeof(struct page *))
244 req = kzalloc(sizeof(*req) + sizeof(struct page *) * nr_inline,
247 return ERR_PTR(-ENOMEM);
249 refcount_set(&req->usage, 1);
250 req->nr_pages = nr_pages;
251 req->actual_len = i_size; /* May change */
252 req->len = nr_pages * PAGE_SIZE; /* We can ask for more than there is */
253 req->data_version = dvnode->status.data_version; /* May change */
255 req->pages = req->array;
257 req->pages = kcalloc(nr_pages, sizeof(struct page *),
263 /* Get a list of all the pages that hold or will hold the directory
264 * content. We need to fill in any gaps that we might find where the
265 * memory reclaimer has been at work. If there are any gaps, we will
266 * need to reread the entire directory contents.
270 n = find_get_pages_contig(dvnode->vfs_inode.i_mapping, i,
273 _debug("find %u at %u/%u", n, i, req->nr_pages);
275 gfp_t gfp = dvnode->vfs_inode.i_mapping->gfp_mask;
277 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
278 afs_stat_v(dvnode, n_inval);
281 req->pages[i] = __page_cache_alloc(gfp);
284 ret = add_to_page_cache_lru(req->pages[i],
285 dvnode->vfs_inode.i_mapping,
290 set_page_private(req->pages[i], 1);
291 SetPagePrivate(req->pages[i]);
292 unlock_page(req->pages[i]);
297 } while (i < req->nr_pages);
299 /* If we're going to reload, we need to lock all the pages to prevent
303 if (down_read_killable(&dvnode->validate_lock) < 0)
306 if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
309 up_read(&dvnode->validate_lock);
310 if (down_write_killable(&dvnode->validate_lock) < 0)
313 if (!test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
314 trace_afs_reload_dir(dvnode);
315 ret = afs_fetch_data(dvnode, key, req);
319 task_io_account_read(PAGE_SIZE * req->nr_pages);
321 if (req->len < req->file_size)
322 goto content_has_grown;
324 /* Validate the data we just read. */
326 if (!afs_dir_check_pages(dvnode, req))
329 // TODO: Trim excess pages
331 set_bit(AFS_VNODE_DIR_VALID, &dvnode->flags);
334 downgrade_write(&dvnode->validate_lock);
339 up_write(&dvnode->validate_lock);
342 _leave(" = %d", ret);
346 up_write(&dvnode->validate_lock);
352 * deal with one block in an AFS directory
354 static int afs_dir_iterate_block(struct afs_vnode *dvnode,
355 struct dir_context *ctx,
356 union afs_xdr_dir_block *block,
359 union afs_xdr_dirent *dire;
360 unsigned offset, next, curr;
364 _enter("%u,%x,%p,,",(unsigned)ctx->pos,blkoff,block);
366 curr = (ctx->pos - blkoff) / sizeof(union afs_xdr_dirent);
368 /* walk through the block, an entry at a time */
369 for (offset = (blkoff == 0 ? AFS_DIR_RESV_BLOCKS0 : AFS_DIR_RESV_BLOCKS);
370 offset < AFS_DIR_SLOTS_PER_BLOCK;
375 /* skip entries marked unused in the bitmap */
376 if (!(block->hdr.bitmap[offset / 8] &
377 (1 << (offset % 8)))) {
378 _debug("ENT[%zu.%u]: unused",
379 blkoff / sizeof(union afs_xdr_dir_block), offset);
382 next * sizeof(union afs_xdr_dirent);
386 /* got a valid entry */
387 dire = &block->dirents[offset];
388 nlen = strnlen(dire->u.name,
390 offset * sizeof(union afs_xdr_dirent));
392 _debug("ENT[%zu.%u]: %s %zu \"%s\"",
393 blkoff / sizeof(union afs_xdr_dir_block), offset,
394 (offset < curr ? "skip" : "fill"),
397 /* work out where the next possible entry is */
398 for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_xdr_dirent)) {
399 if (next >= AFS_DIR_SLOTS_PER_BLOCK) {
400 _debug("ENT[%zu.%u]:"
401 " %u travelled beyond end dir block"
403 blkoff / sizeof(union afs_xdr_dir_block),
404 offset, next, tmp, nlen);
405 return afs_bad(dvnode, afs_file_error_dir_over_end);
407 if (!(block->hdr.bitmap[next / 8] &
408 (1 << (next % 8)))) {
409 _debug("ENT[%zu.%u]:"
410 " %u unmarked extension (len %u/%zu)",
411 blkoff / sizeof(union afs_xdr_dir_block),
412 offset, next, tmp, nlen);
413 return afs_bad(dvnode, afs_file_error_dir_unmarked_ext);
416 _debug("ENT[%zu.%u]: ext %u/%zu",
417 blkoff / sizeof(union afs_xdr_dir_block),
422 /* skip if starts before the current position */
426 /* found the next entry */
427 if (!dir_emit(ctx, dire->u.name, nlen,
428 ntohl(dire->u.vnode),
429 (ctx->actor == afs_lookup_filldir ||
430 ctx->actor == afs_lookup_one_filldir)?
431 ntohl(dire->u.unique) : DT_UNKNOWN)) {
432 _leave(" = 0 [full]");
436 ctx->pos = blkoff + next * sizeof(union afs_xdr_dirent);
439 _leave(" = 1 [more]");
444 * iterate through the data blob that lists the contents of an AFS directory
446 static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx,
449 struct afs_vnode *dvnode = AFS_FS_I(dir);
450 struct afs_xdr_dir_page *dbuf;
451 union afs_xdr_dir_block *dblock;
452 struct afs_read *req;
454 unsigned blkoff, limit;
457 _enter("{%lu},%u,,", dir->i_ino, (unsigned)ctx->pos);
459 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
460 _leave(" = -ESTALE");
464 req = afs_read_dir(dvnode, key);
468 /* round the file position up to the next entry boundary */
469 ctx->pos += sizeof(union afs_xdr_dirent) - 1;
470 ctx->pos &= ~(sizeof(union afs_xdr_dirent) - 1);
472 /* walk through the blocks in sequence */
474 while (ctx->pos < req->actual_len) {
475 blkoff = ctx->pos & ~(sizeof(union afs_xdr_dir_block) - 1);
477 /* Fetch the appropriate page from the directory and re-add it
480 page = req->pages[blkoff / PAGE_SIZE];
482 ret = afs_bad(dvnode, afs_file_error_dir_missing_page);
485 mark_page_accessed(page);
487 limit = blkoff & ~(PAGE_SIZE - 1);
491 /* deal with the individual blocks stashed on this page */
493 dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) /
494 sizeof(union afs_xdr_dir_block)];
495 ret = afs_dir_iterate_block(dvnode, ctx, dblock, blkoff);
501 blkoff += sizeof(union afs_xdr_dir_block);
503 } while (ctx->pos < dir->i_size && blkoff < limit);
510 up_read(&dvnode->validate_lock);
512 _leave(" = %d", ret);
517 * read an AFS directory
519 static int afs_readdir(struct file *file, struct dir_context *ctx)
521 return afs_dir_iterate(file_inode(file), ctx, afs_file_key(file));
525 * Search the directory for a single name
526 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
527 * uniquifier through dtype
529 static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name,
530 int nlen, loff_t fpos, u64 ino, unsigned dtype)
532 struct afs_lookup_one_cookie *cookie =
533 container_of(ctx, struct afs_lookup_one_cookie, ctx);
535 _enter("{%s,%u},%s,%u,,%llu,%u",
536 cookie->name.name, cookie->name.len, name, nlen,
537 (unsigned long long) ino, dtype);
539 /* insanity checks first */
540 BUILD_BUG_ON(sizeof(union afs_xdr_dir_block) != 2048);
541 BUILD_BUG_ON(sizeof(union afs_xdr_dirent) != 32);
543 if (cookie->name.len != nlen ||
544 memcmp(cookie->name.name, name, nlen) != 0) {
549 cookie->fid.vnode = ino;
550 cookie->fid.unique = dtype;
553 _leave(" = -1 [found]");
558 * Do a lookup of a single name in a directory
559 * - just returns the FID the dentry name maps to if found
561 static int afs_do_lookup_one(struct inode *dir, struct dentry *dentry,
562 struct afs_fid *fid, struct key *key)
564 struct afs_super_info *as = dir->i_sb->s_fs_info;
565 struct afs_lookup_one_cookie cookie = {
566 .ctx.actor = afs_lookup_one_filldir,
567 .name = dentry->d_name,
568 .fid.vid = as->volume->vid
572 _enter("{%lu},%p{%pd},", dir->i_ino, dentry, dentry);
574 /* search the directory */
575 ret = afs_dir_iterate(dir, &cookie.ctx, key);
577 _leave(" = %d [iter]", ret);
583 _leave(" = -ENOENT [not found]");
588 _leave(" = 0 { vn=%llu u=%u }", fid->vnode, fid->unique);
593 * search the directory for a name
594 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
595 * uniquifier through dtype
597 static int afs_lookup_filldir(struct dir_context *ctx, const char *name,
598 int nlen, loff_t fpos, u64 ino, unsigned dtype)
600 struct afs_lookup_cookie *cookie =
601 container_of(ctx, struct afs_lookup_cookie, ctx);
604 _enter("{%s,%u},%s,%u,,%llu,%u",
605 cookie->name.name, cookie->name.len, name, nlen,
606 (unsigned long long) ino, dtype);
608 /* insanity checks first */
609 BUILD_BUG_ON(sizeof(union afs_xdr_dir_block) != 2048);
610 BUILD_BUG_ON(sizeof(union afs_xdr_dirent) != 32);
613 if (cookie->nr_fids < 50) {
614 cookie->fids[cookie->nr_fids].vnode = ino;
615 cookie->fids[cookie->nr_fids].unique = dtype;
618 } else if (cookie->name.len == nlen &&
619 memcmp(cookie->name.name, name, nlen) == 0) {
620 cookie->fids[0].vnode = ino;
621 cookie->fids[0].unique = dtype;
623 if (cookie->one_only)
627 ret = cookie->nr_fids >= 50 ? -1 : 0;
628 _leave(" = %d", ret);
633 * Do a lookup in a directory. We make use of bulk lookup to query a slew of
634 * files in one go and create inodes for them. The inode of the file we were
635 * asked for is returned.
637 static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry,
640 struct afs_lookup_cookie *cookie;
641 struct afs_cb_interest *cbi = NULL;
642 struct afs_super_info *as = dir->i_sb->s_fs_info;
643 struct afs_status_cb *scb;
644 struct afs_iget_data data;
645 struct afs_fs_cursor fc;
646 struct afs_vnode *dvnode = AFS_FS_I(dir);
647 struct inode *inode = NULL;
650 _enter("{%lu},%p{%pd},", dir->i_ino, dentry, dentry);
652 cookie = kzalloc(sizeof(struct afs_lookup_cookie), GFP_KERNEL);
654 return ERR_PTR(-ENOMEM);
656 cookie->ctx.actor = afs_lookup_filldir;
657 cookie->name = dentry->d_name;
658 cookie->nr_fids = 1; /* slot 0 is saved for the fid we actually want */
660 read_seqlock_excl(&dvnode->cb_lock);
661 if (dvnode->cb_interest &&
662 dvnode->cb_interest->server &&
663 test_bit(AFS_SERVER_FL_NO_IBULK, &dvnode->cb_interest->server->flags))
664 cookie->one_only = true;
665 read_sequnlock_excl(&dvnode->cb_lock);
667 for (i = 0; i < 50; i++)
668 cookie->fids[i].vid = as->volume->vid;
670 /* search the directory */
671 ret = afs_dir_iterate(dir, &cookie->ctx, key);
673 inode = ERR_PTR(ret);
677 inode = ERR_PTR(-ENOENT);
681 /* Check to see if we already have an inode for the primary fid. */
682 data.volume = dvnode->volume;
683 data.fid = cookie->fids[0];
684 inode = ilookup5(dir->i_sb, cookie->fids[0].vnode, afs_iget5_test, &data);
688 /* Need space for examining all the selected files */
689 inode = ERR_PTR(-ENOMEM);
690 cookie->statuses = kvcalloc(cookie->nr_fids, sizeof(struct afs_status_cb),
692 if (!cookie->statuses)
695 /* Try FS.InlineBulkStatus first. Abort codes for the individual
696 * lookups contained therein are stored in the reply without aborting
697 * the whole operation.
699 if (cookie->one_only)
700 goto no_inline_bulk_status;
702 inode = ERR_PTR(-ERESTARTSYS);
703 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
704 while (afs_select_fileserver(&fc)) {
705 if (test_bit(AFS_SERVER_FL_NO_IBULK,
706 &fc.cbi->server->flags)) {
707 fc.ac.abort_code = RX_INVALID_OPERATION;
708 fc.ac.error = -ECONNABORTED;
711 afs_fs_inline_bulk_status(&fc,
715 cookie->nr_fids, NULL);
718 if (fc.ac.error == 0)
719 cbi = afs_get_cb_interest(fc.cbi);
720 if (fc.ac.abort_code == RX_INVALID_OPERATION)
721 set_bit(AFS_SERVER_FL_NO_IBULK, &fc.cbi->server->flags);
722 inode = ERR_PTR(afs_end_vnode_operation(&fc));
727 if (fc.ac.abort_code != RX_INVALID_OPERATION)
730 no_inline_bulk_status:
731 /* We could try FS.BulkStatus next, but this aborts the entire op if
732 * any of the lookups fails - so, for the moment, revert to
733 * FS.FetchStatus for just the primary fid.
736 inode = ERR_PTR(-ERESTARTSYS);
737 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
738 while (afs_select_fileserver(&fc)) {
739 scb = &cookie->statuses[0];
740 afs_fs_fetch_status(&fc,
747 if (fc.ac.error == 0)
748 cbi = afs_get_cb_interest(fc.cbi);
749 inode = ERR_PTR(afs_end_vnode_operation(&fc));
755 for (i = 0; i < cookie->nr_fids; i++)
756 cookie->statuses[i].status.abort_code = 0;
759 /* Turn all the files into inodes and save the first one - which is the
760 * one we actually want.
762 scb = &cookie->statuses[0];
763 if (scb->status.abort_code != 0)
764 inode = ERR_PTR(afs_abort_to_error(scb->status.abort_code));
766 for (i = 0; i < cookie->nr_fids; i++) {
767 struct afs_status_cb *scb = &cookie->statuses[i];
770 if (scb->status.abort_code != 0)
773 ti = afs_iget(dir->i_sb, key, &cookie->fids[i],
784 afs_put_cb_interest(afs_v2net(dvnode), cbi);
785 kvfree(cookie->statuses);
792 * Look up an entry in a directory with @sys substitution.
794 static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry,
797 struct afs_sysnames *subs;
798 struct afs_net *net = afs_i2net(dir);
800 char *buf, *p, *name;
805 ret = ERR_PTR(-ENOMEM);
806 p = buf = kmalloc(AFSNAMEMAX, GFP_KERNEL);
809 if (dentry->d_name.len > 4) {
810 memcpy(p, dentry->d_name.name, dentry->d_name.len - 4);
811 p += dentry->d_name.len - 4;
814 /* There is an ordered list of substitutes that we have to try. */
815 read_lock(&net->sysnames_lock);
816 subs = net->sysnames;
817 refcount_inc(&subs->usage);
818 read_unlock(&net->sysnames_lock);
820 for (i = 0; i < subs->nr; i++) {
821 name = subs->subs[i];
822 len = dentry->d_name.len - 4 + strlen(name);
823 if (len >= AFSNAMEMAX) {
824 ret = ERR_PTR(-ENAMETOOLONG);
829 ret = lookup_one_len(buf, dentry->d_parent, len);
830 if (IS_ERR(ret) || d_is_positive(ret))
835 /* We don't want to d_add() the @sys dentry here as we don't want to
836 * the cached dentry to hide changes to the sysnames list.
840 afs_put_sysnames(subs);
848 * look up an entry in a directory
850 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
853 struct afs_vnode *dvnode = AFS_FS_I(dir);
859 _enter("{%llx:%llu},%p{%pd},",
860 dvnode->fid.vid, dvnode->fid.vnode, dentry, dentry);
862 ASSERTCMP(d_inode(dentry), ==, NULL);
864 if (dentry->d_name.len >= AFSNAMEMAX) {
865 _leave(" = -ENAMETOOLONG");
866 return ERR_PTR(-ENAMETOOLONG);
869 if (test_bit(AFS_VNODE_DELETED, &dvnode->flags)) {
870 _leave(" = -ESTALE");
871 return ERR_PTR(-ESTALE);
874 key = afs_request_key(dvnode->volume->cell);
876 _leave(" = %ld [key]", PTR_ERR(key));
877 return ERR_CAST(key);
880 ret = afs_validate(dvnode, key);
883 _leave(" = %d [val]", ret);
887 if (dentry->d_name.len >= 4 &&
888 dentry->d_name.name[dentry->d_name.len - 4] == '@' &&
889 dentry->d_name.name[dentry->d_name.len - 3] == 's' &&
890 dentry->d_name.name[dentry->d_name.len - 2] == 'y' &&
891 dentry->d_name.name[dentry->d_name.len - 1] == 's')
892 return afs_lookup_atsys(dir, dentry, key);
894 afs_stat_v(dvnode, n_lookup);
895 inode = afs_do_lookup(dir, dentry, key);
897 if (inode == ERR_PTR(-ENOENT)) {
898 inode = afs_try_auto_mntpt(dentry, dir);
901 (void *)(unsigned long)dvnode->status.data_version;
903 d = d_splice_alias(inode, dentry);
904 if (!IS_ERR_OR_NULL(d)) {
905 d->d_fsdata = dentry->d_fsdata;
906 trace_afs_lookup(dvnode, &d->d_name,
907 inode ? AFS_FS_I(inode) : NULL);
909 trace_afs_lookup(dvnode, &dentry->d_name,
910 inode ? AFS_FS_I(inode) : NULL);
916 * check that a dentry lookup hit has found a valid entry
917 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
920 static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
922 struct afs_vnode *vnode, *dir;
923 struct afs_fid uninitialized_var(fid);
924 struct dentry *parent;
927 long dir_version, de_version;
930 if (flags & LOOKUP_RCU)
933 if (d_really_is_positive(dentry)) {
934 vnode = AFS_FS_I(d_inode(dentry));
935 _enter("{v={%llx:%llu} n=%pd fl=%lx},",
936 vnode->fid.vid, vnode->fid.vnode, dentry,
939 _enter("{neg n=%pd}", dentry);
942 key = afs_request_key(AFS_FS_S(dentry->d_sb)->volume->cell);
946 if (d_really_is_positive(dentry)) {
947 inode = d_inode(dentry);
949 vnode = AFS_FS_I(inode);
950 afs_validate(vnode, key);
951 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
956 /* lock down the parent dentry so we can peer at it */
957 parent = dget_parent(dentry);
958 dir = AFS_FS_I(d_inode(parent));
960 /* validate the parent directory */
961 afs_validate(dir, key);
963 if (test_bit(AFS_VNODE_DELETED, &dir->flags)) {
964 _debug("%pd: parent dir deleted", dentry);
968 /* We only need to invalidate a dentry if the server's copy changed
969 * behind our back. If we made the change, it's no problem. Note that
970 * on a 32-bit system, we only have 32 bits in the dentry to store the
973 dir_version = (long)dir->status.data_version;
974 de_version = (long)dentry->d_fsdata;
975 if (de_version == dir_version)
978 dir_version = (long)dir->invalid_before;
979 if (de_version - dir_version >= 0)
982 _debug("dir modified");
983 afs_stat_v(dir, n_reval);
985 /* search the directory for this vnode */
986 ret = afs_do_lookup_one(&dir->vfs_inode, dentry, &fid, key);
989 /* the filename maps to something */
990 if (d_really_is_negative(dentry))
992 inode = d_inode(dentry);
993 if (is_bad_inode(inode)) {
994 printk("kAFS: afs_d_revalidate: %pd2 has bad inode\n",
999 vnode = AFS_FS_I(inode);
1001 /* if the vnode ID has changed, then the dirent points to a
1003 if (fid.vnode != vnode->fid.vnode) {
1004 _debug("%pd: dirent changed [%llu != %llu]",
1010 /* if the vnode ID uniqifier has changed, then the file has
1011 * been deleted and replaced, and the original vnode ID has
1013 if (fid.unique != vnode->fid.unique) {
1014 _debug("%pd: file deleted (uq %u -> %u I:%u)",
1017 vnode->vfs_inode.i_generation);
1018 write_seqlock(&vnode->cb_lock);
1019 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1020 write_sequnlock(&vnode->cb_lock);
1026 /* the filename is unknown */
1027 _debug("%pd: dirent not found", dentry);
1028 if (d_really_is_positive(dentry))
1033 _debug("failed to iterate dir %pd: %d",
1035 goto out_bad_parent;
1039 dentry->d_fsdata = (void *)dir_version;
1042 _leave(" = 1 [valid]");
1045 /* the dirent, if it exists, now points to a different vnode */
1047 spin_lock(&dentry->d_lock);
1048 dentry->d_flags |= DCACHE_NFSFS_RENAMED;
1049 spin_unlock(&dentry->d_lock);
1052 _debug("dropping dentry %pd2", dentry);
1057 _leave(" = 0 [bad]");
1062 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
1064 * - called from dput() when d_count is going to 0.
1065 * - return 1 to request dentry be unhashed, 0 otherwise
1067 static int afs_d_delete(const struct dentry *dentry)
1069 _enter("%pd", dentry);
1071 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
1074 if (d_really_is_positive(dentry) &&
1075 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(d_inode(dentry))->flags) ||
1076 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(d_inode(dentry))->flags)))
1079 _leave(" = 0 [keep]");
1083 _leave(" = 1 [zap]");
1088 * Clean up sillyrename files on dentry removal.
1090 static void afs_d_iput(struct dentry *dentry, struct inode *inode)
1092 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
1093 afs_silly_iput(dentry, inode);
1098 * handle dentry release
1100 void afs_d_release(struct dentry *dentry)
1102 _enter("%pd", dentry);
1106 * Create a new inode for create/mkdir/symlink
1108 static void afs_vnode_new_inode(struct afs_fs_cursor *fc,
1109 struct dentry *new_dentry,
1110 struct afs_fid *newfid,
1111 struct afs_status_cb *new_scb)
1113 struct afs_vnode *vnode;
1114 struct inode *inode;
1116 if (fc->ac.error < 0)
1119 inode = afs_iget(fc->vnode->vfs_inode.i_sb, fc->key,
1120 newfid, new_scb, fc->cbi, fc->vnode);
1121 if (IS_ERR(inode)) {
1122 /* ENOMEM or EINTR at a really inconvenient time - just abandon
1123 * the new directory on the server.
1125 fc->ac.error = PTR_ERR(inode);
1129 vnode = AFS_FS_I(inode);
1130 set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
1131 if (fc->ac.error == 0)
1132 afs_cache_permit(vnode, fc->key, vnode->cb_break, new_scb);
1133 d_instantiate(new_dentry, inode);
1137 * create a directory on an AFS filesystem
1139 static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1141 struct afs_status_cb *scb;
1142 struct afs_fs_cursor fc;
1143 struct afs_vnode *dvnode = AFS_FS_I(dir);
1144 struct afs_fid newfid;
1150 _enter("{%llx:%llu},{%pd},%ho",
1151 dvnode->fid.vid, dvnode->fid.vnode, dentry, mode);
1154 scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
1158 key = afs_request_key(dvnode->volume->cell);
1165 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
1166 afs_dataversion_t data_version = dvnode->status.data_version + 1;
1168 while (afs_select_fileserver(&fc)) {
1169 fc.cb_break = afs_calc_vnode_cb_break(dvnode);
1170 afs_fs_create(&fc, dentry->d_name.name, mode,
1171 &scb[0], &newfid, &scb[1]);
1174 afs_check_for_remote_deletion(&fc, dvnode);
1175 afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
1176 &data_version, &scb[0]);
1177 afs_vnode_new_inode(&fc, dentry, &newfid, &scb[1]);
1178 ret = afs_end_vnode_operation(&fc);
1186 test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1187 afs_edit_dir_add(dvnode, &dentry->d_name, &newfid,
1188 afs_edit_dir_for_create);
1201 _leave(" = %d", ret);
1206 * Remove a subdir from a directory.
1208 static void afs_dir_remove_subdir(struct dentry *dentry)
1210 if (d_really_is_positive(dentry)) {
1211 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
1213 clear_nlink(&vnode->vfs_inode);
1214 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1215 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
1216 clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
1221 * remove a directory from an AFS filesystem
1223 static int afs_rmdir(struct inode *dir, struct dentry *dentry)
1225 struct afs_status_cb *scb;
1226 struct afs_fs_cursor fc;
1227 struct afs_vnode *dvnode = AFS_FS_I(dir), *vnode = NULL;
1231 _enter("{%llx:%llu},{%pd}",
1232 dvnode->fid.vid, dvnode->fid.vnode, dentry);
1234 scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
1238 key = afs_request_key(dvnode->volume->cell);
1244 /* Try to make sure we have a callback promise on the victim. */
1245 if (d_really_is_positive(dentry)) {
1246 vnode = AFS_FS_I(d_inode(dentry));
1247 ret = afs_validate(vnode, key);
1253 ret = down_write_killable(&vnode->rmdir_lock);
1259 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
1260 afs_dataversion_t data_version = dvnode->status.data_version + 1;
1262 while (afs_select_fileserver(&fc)) {
1263 fc.cb_break = afs_calc_vnode_cb_break(dvnode);
1264 afs_fs_remove(&fc, vnode, dentry->d_name.name, true, scb);
1267 afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
1268 &data_version, scb);
1269 ret = afs_end_vnode_operation(&fc);
1271 afs_dir_remove_subdir(dentry);
1272 if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1273 afs_edit_dir_remove(dvnode, &dentry->d_name,
1274 afs_edit_dir_for_rmdir);
1279 up_write(&vnode->rmdir_lock);
1288 * Remove a link to a file or symlink from a directory.
1290 * If the file was not deleted due to excess hard links, the fileserver will
1291 * break the callback promise on the file - if it had one - before it returns
1292 * to us, and if it was deleted, it won't
1294 * However, if we didn't have a callback promise outstanding, or it was
1295 * outstanding on a different server, then it won't break it either...
1297 int afs_dir_remove_link(struct dentry *dentry, struct key *key,
1298 unsigned long d_version_before,
1299 unsigned long d_version_after)
1304 /* There were no intervening changes on the server if the version
1305 * number we got back was incremented by exactly 1.
1307 dir_valid = (d_version_after == d_version_before + 1);
1309 if (d_really_is_positive(dentry)) {
1310 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
1312 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
1314 } else if (dir_valid) {
1315 drop_nlink(&vnode->vfs_inode);
1316 if (vnode->vfs_inode.i_nlink == 0) {
1317 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1318 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
1322 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
1324 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
1325 kdebug("AFS_VNODE_DELETED");
1327 ret = afs_validate(vnode, key);
1331 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
1338 * Remove a file or symlink from an AFS filesystem.
1340 static int afs_unlink(struct inode *dir, struct dentry *dentry)
1342 struct afs_fs_cursor fc;
1343 struct afs_status_cb *scb;
1344 struct afs_vnode *dvnode = AFS_FS_I(dir), *vnode = NULL;
1346 unsigned long d_version = (unsigned long)dentry->d_fsdata;
1347 bool need_rehash = false;
1350 _enter("{%llx:%llu},{%pd}",
1351 dvnode->fid.vid, dvnode->fid.vnode, dentry);
1353 if (dentry->d_name.len >= AFSNAMEMAX)
1354 return -ENAMETOOLONG;
1357 scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
1361 key = afs_request_key(dvnode->volume->cell);
1367 /* Try to make sure we have a callback promise on the victim. */
1368 if (d_really_is_positive(dentry)) {
1369 vnode = AFS_FS_I(d_inode(dentry));
1370 ret = afs_validate(vnode, key);
1375 spin_lock(&dentry->d_lock);
1376 if (vnode && d_count(dentry) > 1) {
1377 spin_unlock(&dentry->d_lock);
1378 /* Start asynchronous writeout of the inode */
1379 write_inode_now(d_inode(dentry), 0);
1380 ret = afs_sillyrename(dvnode, vnode, dentry, key);
1383 if (!d_unhashed(dentry)) {
1384 /* Prevent a race with RCU lookup. */
1388 spin_unlock(&dentry->d_lock);
1391 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
1392 afs_dataversion_t data_version = dvnode->status.data_version + 1;
1394 while (afs_select_fileserver(&fc)) {
1395 fc.cb_break = afs_calc_vnode_cb_break(dvnode);
1397 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc.cbi->server->flags) &&
1398 !test_bit(AFS_SERVER_FL_NO_RM2, &fc.cbi->server->flags)) {
1399 yfs_fs_remove_file2(&fc, vnode, dentry->d_name.name,
1401 if (fc.ac.error == 0 &&
1402 scb[1].status.abort_code == VNOVNODE) {
1403 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1404 afs_break_callback(vnode);
1407 if (fc.ac.error != -ECONNABORTED ||
1408 fc.ac.abort_code != RXGEN_OPCODE)
1410 set_bit(AFS_SERVER_FL_NO_RM2, &fc.cbi->server->flags);
1413 afs_fs_remove(&fc, vnode, dentry->d_name.name, false, &scb[0]);
1416 afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
1417 &data_version, &scb[0]);
1418 ret = afs_end_vnode_operation(&fc);
1420 ret = afs_dir_remove_link(
1421 dentry, key, d_version,
1422 (unsigned long)dvnode->status.data_version);
1424 test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1425 afs_edit_dir_remove(dvnode, &dentry->d_name,
1426 afs_edit_dir_for_unlink);
1429 if (need_rehash && ret < 0 && ret != -ENOENT)
1437 _leave(" = %d", ret);
1442 * create a regular file on an AFS filesystem
1444 static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
1447 struct afs_fs_cursor fc;
1448 struct afs_status_cb *scb;
1449 struct afs_vnode *dvnode = AFS_FS_I(dir);
1450 struct afs_fid newfid;
1456 _enter("{%llx:%llu},{%pd},%ho,",
1457 dvnode->fid.vid, dvnode->fid.vnode, dentry, mode);
1459 ret = -ENAMETOOLONG;
1460 if (dentry->d_name.len >= AFSNAMEMAX)
1463 key = afs_request_key(dvnode->volume->cell);
1470 scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
1475 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
1476 afs_dataversion_t data_version = dvnode->status.data_version + 1;
1478 while (afs_select_fileserver(&fc)) {
1479 fc.cb_break = afs_calc_vnode_cb_break(dvnode);
1480 afs_fs_create(&fc, dentry->d_name.name, mode,
1481 &scb[0], &newfid, &scb[1]);
1484 afs_check_for_remote_deletion(&fc, dvnode);
1485 afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
1486 &data_version, &scb[0]);
1487 afs_vnode_new_inode(&fc, dentry, &newfid, &scb[1]);
1488 ret = afs_end_vnode_operation(&fc);
1495 if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1496 afs_edit_dir_add(dvnode, &dentry->d_name, &newfid,
1497 afs_edit_dir_for_create);
1510 _leave(" = %d", ret);
1515 * create a hard link between files in an AFS filesystem
1517 static int afs_link(struct dentry *from, struct inode *dir,
1518 struct dentry *dentry)
1520 struct afs_fs_cursor fc;
1521 struct afs_status_cb *scb;
1522 struct afs_vnode *dvnode = AFS_FS_I(dir);
1523 struct afs_vnode *vnode = AFS_FS_I(d_inode(from));
1527 _enter("{%llx:%llu},{%llx:%llu},{%pd}",
1528 vnode->fid.vid, vnode->fid.vnode,
1529 dvnode->fid.vid, dvnode->fid.vnode,
1532 ret = -ENAMETOOLONG;
1533 if (dentry->d_name.len >= AFSNAMEMAX)
1537 scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
1541 key = afs_request_key(dvnode->volume->cell);
1548 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
1549 afs_dataversion_t data_version = dvnode->status.data_version + 1;
1551 if (mutex_lock_interruptible_nested(&vnode->io_lock, 1) < 0) {
1552 afs_end_vnode_operation(&fc);
1556 while (afs_select_fileserver(&fc)) {
1557 fc.cb_break = afs_calc_vnode_cb_break(dvnode);
1558 fc.cb_break_2 = afs_calc_vnode_cb_break(vnode);
1559 afs_fs_link(&fc, vnode, dentry->d_name.name,
1563 afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
1564 &data_version, &scb[0]);
1565 afs_vnode_commit_status(&fc, vnode, fc.cb_break_2,
1567 ihold(&vnode->vfs_inode);
1568 d_instantiate(dentry, &vnode->vfs_inode);
1570 mutex_unlock(&vnode->io_lock);
1571 ret = afs_end_vnode_operation(&fc);
1578 if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1579 afs_edit_dir_add(dvnode, &dentry->d_name, &vnode->fid,
1580 afs_edit_dir_for_link);
1593 _leave(" = %d", ret);
1598 * create a symlink in an AFS filesystem
1600 static int afs_symlink(struct inode *dir, struct dentry *dentry,
1601 const char *content)
1603 struct afs_fs_cursor fc;
1604 struct afs_status_cb *scb;
1605 struct afs_vnode *dvnode = AFS_FS_I(dir);
1606 struct afs_fid newfid;
1610 _enter("{%llx:%llu},{%pd},%s",
1611 dvnode->fid.vid, dvnode->fid.vnode, dentry,
1614 ret = -ENAMETOOLONG;
1615 if (dentry->d_name.len >= AFSNAMEMAX)
1619 if (strlen(content) >= AFSPATHMAX)
1623 scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
1627 key = afs_request_key(dvnode->volume->cell);
1634 if (afs_begin_vnode_operation(&fc, dvnode, key, true)) {
1635 afs_dataversion_t data_version = dvnode->status.data_version + 1;
1637 while (afs_select_fileserver(&fc)) {
1638 fc.cb_break = afs_calc_vnode_cb_break(dvnode);
1639 afs_fs_symlink(&fc, dentry->d_name.name, content,
1640 &scb[0], &newfid, &scb[1]);
1643 afs_check_for_remote_deletion(&fc, dvnode);
1644 afs_vnode_commit_status(&fc, dvnode, fc.cb_break,
1645 &data_version, &scb[0]);
1646 afs_vnode_new_inode(&fc, dentry, &newfid, &scb[1]);
1647 ret = afs_end_vnode_operation(&fc);
1654 if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1655 afs_edit_dir_add(dvnode, &dentry->d_name, &newfid,
1656 afs_edit_dir_for_symlink);
1669 _leave(" = %d", ret);
1674 * rename a file in an AFS filesystem and/or move it between directories
1676 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1677 struct inode *new_dir, struct dentry *new_dentry,
1680 struct afs_fs_cursor fc;
1681 struct afs_status_cb *scb;
1682 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
1683 struct dentry *tmp = NULL, *rehash = NULL;
1684 struct inode *new_inode;
1686 bool new_negative = d_is_negative(new_dentry);
1692 /* Don't allow silly-rename files be moved around. */
1693 if (old_dentry->d_flags & DCACHE_NFSFS_RENAMED)
1696 vnode = AFS_FS_I(d_inode(old_dentry));
1697 orig_dvnode = AFS_FS_I(old_dir);
1698 new_dvnode = AFS_FS_I(new_dir);
1700 _enter("{%llx:%llu},{%llx:%llu},{%llx:%llu},{%pd}",
1701 orig_dvnode->fid.vid, orig_dvnode->fid.vnode,
1702 vnode->fid.vid, vnode->fid.vnode,
1703 new_dvnode->fid.vid, new_dvnode->fid.vnode,
1707 scb = kcalloc(2, sizeof(struct afs_status_cb), GFP_KERNEL);
1711 key = afs_request_key(orig_dvnode->volume->cell);
1717 /* For non-directories, check whether the target is busy and if so,
1718 * make a copy of the dentry and then do a silly-rename. If the
1719 * silly-rename succeeds, the copied dentry is hashed and becomes the
1722 if (d_is_positive(new_dentry) && !d_is_dir(new_dentry)) {
1723 /* To prevent any new references to the target during the
1724 * rename, we unhash the dentry in advance.
1726 if (!d_unhashed(new_dentry)) {
1728 rehash = new_dentry;
1731 if (d_count(new_dentry) > 2) {
1732 /* copy the target dentry's name */
1734 tmp = d_alloc(new_dentry->d_parent,
1735 &new_dentry->d_name);
1739 ret = afs_sillyrename(new_dvnode,
1740 AFS_FS_I(d_inode(new_dentry)),
1747 new_negative = true;
1752 if (afs_begin_vnode_operation(&fc, orig_dvnode, key, true)) {
1753 afs_dataversion_t orig_data_version;
1754 afs_dataversion_t new_data_version;
1755 struct afs_status_cb *new_scb = &scb[1];
1757 orig_data_version = orig_dvnode->status.data_version + 1;
1759 if (orig_dvnode != new_dvnode) {
1760 if (mutex_lock_interruptible_nested(&new_dvnode->io_lock, 1) < 0) {
1761 afs_end_vnode_operation(&fc);
1764 new_data_version = new_dvnode->status.data_version;
1766 new_data_version = orig_data_version;
1770 while (afs_select_fileserver(&fc)) {
1771 fc.cb_break = afs_calc_vnode_cb_break(orig_dvnode);
1772 fc.cb_break_2 = afs_calc_vnode_cb_break(new_dvnode);
1773 afs_fs_rename(&fc, old_dentry->d_name.name,
1774 new_dvnode, new_dentry->d_name.name,
1778 afs_vnode_commit_status(&fc, orig_dvnode, fc.cb_break,
1779 &orig_data_version, &scb[0]);
1780 if (new_dvnode != orig_dvnode) {
1781 afs_vnode_commit_status(&fc, new_dvnode, fc.cb_break_2,
1782 &new_data_version, &scb[1]);
1783 mutex_unlock(&new_dvnode->io_lock);
1785 ret = afs_end_vnode_operation(&fc);
1793 if (test_bit(AFS_VNODE_DIR_VALID, &orig_dvnode->flags))
1794 afs_edit_dir_remove(orig_dvnode, &old_dentry->d_name,
1795 afs_edit_dir_for_rename_0);
1797 if (!new_negative &&
1798 test_bit(AFS_VNODE_DIR_VALID, &new_dvnode->flags))
1799 afs_edit_dir_remove(new_dvnode, &new_dentry->d_name,
1800 afs_edit_dir_for_rename_1);
1802 if (test_bit(AFS_VNODE_DIR_VALID, &new_dvnode->flags))
1803 afs_edit_dir_add(new_dvnode, &new_dentry->d_name,
1804 &vnode->fid, afs_edit_dir_for_rename_2);
1806 new_inode = d_inode(new_dentry);
1808 spin_lock(&new_inode->i_lock);
1809 if (new_inode->i_nlink > 0)
1810 drop_nlink(new_inode);
1811 spin_unlock(&new_inode->i_lock);
1813 d_move(old_dentry, new_dentry);
1827 _leave(" = %d", ret);
1832 * Release a directory page and clean up its private state if it's not busy
1833 * - return true if the page can now be released, false if not
1835 static int afs_dir_releasepage(struct page *page, gfp_t gfp_flags)
1837 struct afs_vnode *dvnode = AFS_FS_I(page->mapping->host);
1839 _enter("{{%llx:%llu}[%lu]}", dvnode->fid.vid, dvnode->fid.vnode, page->index);
1841 set_page_private(page, 0);
1842 ClearPagePrivate(page);
1844 /* The directory will need reloading. */
1845 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1846 afs_stat_v(dvnode, n_relpg);
1851 * invalidate part or all of a page
1852 * - release a page and clean up its private data if offset is 0 (indicating
1855 static void afs_dir_invalidatepage(struct page *page, unsigned int offset,
1856 unsigned int length)
1858 struct afs_vnode *dvnode = AFS_FS_I(page->mapping->host);
1860 _enter("{%lu},%u,%u", page->index, offset, length);
1862 BUG_ON(!PageLocked(page));
1864 /* The directory will need reloading. */
1865 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &dvnode->flags))
1866 afs_stat_v(dvnode, n_inval);
1868 /* we clean up only if the entire page is being invalidated */
1869 if (offset == 0 && length == PAGE_SIZE) {
1870 set_page_private(page, 0);
1871 ClearPagePrivate(page);