dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /* dir.c: AFS filesystem directory handling
  2. *
  3. * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  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.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/fs.h>
  16. #include <linux/pagemap.h>
  17. #include "internal.h"
  18. static struct dentry *afs_dir_lookup(struct inode *dir, struct dentry *dentry,
  19. struct nameidata *nd);
  20. static int afs_dir_open(struct inode *inode, struct file *file);
  21. static int afs_dir_readdir(struct file *file, void *dirent, filldir_t filldir);
  22. static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd);
  23. static int afs_d_delete(struct dentry *dentry);
  24. static int afs_dir_lookup_filldir(void *_cookie, const char *name, int nlen,
  25. loff_t fpos, u64 ino, unsigned dtype);
  26. const struct file_operations afs_dir_file_operations = {
  27. .open = afs_dir_open,
  28. .readdir = afs_dir_readdir,
  29. };
  30. const struct inode_operations afs_dir_inode_operations = {
  31. .lookup = afs_dir_lookup,
  32. .getattr = afs_inode_getattr,
  33. #if 0 /* TODO */
  34. .create = afs_dir_create,
  35. .link = afs_dir_link,
  36. .unlink = afs_dir_unlink,
  37. .symlink = afs_dir_symlink,
  38. .mkdir = afs_dir_mkdir,
  39. .rmdir = afs_dir_rmdir,
  40. .mknod = afs_dir_mknod,
  41. .rename = afs_dir_rename,
  42. #endif
  43. };
  44. static struct dentry_operations afs_fs_dentry_operations = {
  45. .d_revalidate = afs_d_revalidate,
  46. .d_delete = afs_d_delete,
  47. };
  48. #define AFS_DIR_HASHTBL_SIZE 128
  49. #define AFS_DIR_DIRENT_SIZE 32
  50. #define AFS_DIRENT_PER_BLOCK 64
  51. union afs_dirent {
  52. struct {
  53. uint8_t valid;
  54. uint8_t unused[1];
  55. __be16 hash_next;
  56. __be32 vnode;
  57. __be32 unique;
  58. uint8_t name[16];
  59. uint8_t overflow[4]; /* if any char of the name (inc
  60. * NUL) reaches here, consume
  61. * the next dirent too */
  62. } u;
  63. uint8_t extended_name[32];
  64. };
  65. /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
  66. struct afs_dir_pagehdr {
  67. __be16 npages;
  68. __be16 magic;
  69. #define AFS_DIR_MAGIC htons(1234)
  70. uint8_t nentries;
  71. uint8_t bitmap[8];
  72. uint8_t pad[19];
  73. };
  74. /* directory block layout */
  75. union afs_dir_block {
  76. struct afs_dir_pagehdr pagehdr;
  77. struct {
  78. struct afs_dir_pagehdr pagehdr;
  79. uint8_t alloc_ctrs[128];
  80. /* dir hash table */
  81. uint16_t hashtable[AFS_DIR_HASHTBL_SIZE];
  82. } hdr;
  83. union afs_dirent dirents[AFS_DIRENT_PER_BLOCK];
  84. };
  85. /* layout on a linux VM page */
  86. struct afs_dir_page {
  87. union afs_dir_block blocks[PAGE_SIZE / sizeof(union afs_dir_block)];
  88. };
  89. struct afs_dir_lookup_cookie {
  90. struct afs_fid fid;
  91. const char *name;
  92. size_t nlen;
  93. int found;
  94. };
  95. /*
  96. * check that a directory page is valid
  97. */
  98. static inline void afs_dir_check_page(struct inode *dir, struct page *page)
  99. {
  100. struct afs_dir_page *dbuf;
  101. loff_t latter;
  102. int tmp, qty;
  103. #if 0
  104. /* check the page count */
  105. qty = desc.size / sizeof(dbuf->blocks[0]);
  106. if (qty == 0)
  107. goto error;
  108. if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) {
  109. printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
  110. __FUNCTION__, dir->i_ino, qty,
  111. ntohs(dbuf->blocks[0].pagehdr.npages));
  112. goto error;
  113. }
  114. #endif
  115. /* determine how many magic numbers there should be in this page */
  116. latter = dir->i_size - page_offset(page);
  117. if (latter >= PAGE_SIZE)
  118. qty = PAGE_SIZE;
  119. else
  120. qty = latter;
  121. qty /= sizeof(union afs_dir_block);
  122. /* check them */
  123. dbuf = page_address(page);
  124. for (tmp = 0; tmp < qty; tmp++) {
  125. if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) {
  126. printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
  127. __FUNCTION__, dir->i_ino, tmp, qty,
  128. ntohs(dbuf->blocks[tmp].pagehdr.magic));
  129. goto error;
  130. }
  131. }
  132. SetPageChecked(page);
  133. return;
  134. error:
  135. SetPageChecked(page);
  136. SetPageError(page);
  137. }
  138. /*
  139. * discard a page cached in the pagecache
  140. */
  141. static inline void afs_dir_put_page(struct page *page)
  142. {
  143. kunmap(page);
  144. page_cache_release(page);
  145. }
  146. /*
  147. * get a page into the pagecache
  148. */
  149. static struct page *afs_dir_get_page(struct inode *dir, unsigned long index)
  150. {
  151. struct page *page;
  152. _enter("{%lu},%lu", dir->i_ino, index);
  153. page = read_mapping_page(dir->i_mapping, index, NULL);
  154. if (!IS_ERR(page)) {
  155. wait_on_page_locked(page);
  156. kmap(page);
  157. if (!PageUptodate(page))
  158. goto fail;
  159. if (!PageChecked(page))
  160. afs_dir_check_page(dir, page);
  161. if (PageError(page))
  162. goto fail;
  163. }
  164. return page;
  165. fail:
  166. afs_dir_put_page(page);
  167. _leave(" = -EIO");
  168. return ERR_PTR(-EIO);
  169. }
  170. /*
  171. * open an AFS directory file
  172. */
  173. static int afs_dir_open(struct inode *inode, struct file *file)
  174. {
  175. _enter("{%lu}", inode->i_ino);
  176. BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
  177. BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
  178. if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags))
  179. return -ENOENT;
  180. _leave(" = 0");
  181. return 0;
  182. }
  183. /*
  184. * deal with one block in an AFS directory
  185. */
  186. static int afs_dir_iterate_block(unsigned *fpos,
  187. union afs_dir_block *block,
  188. unsigned blkoff,
  189. void *cookie,
  190. filldir_t filldir)
  191. {
  192. union afs_dirent *dire;
  193. unsigned offset, next, curr;
  194. size_t nlen;
  195. int tmp, ret;
  196. _enter("%u,%x,%p,,",*fpos,blkoff,block);
  197. curr = (*fpos - blkoff) / sizeof(union afs_dirent);
  198. /* walk through the block, an entry at a time */
  199. for (offset = AFS_DIRENT_PER_BLOCK - block->pagehdr.nentries;
  200. offset < AFS_DIRENT_PER_BLOCK;
  201. offset = next
  202. ) {
  203. next = offset + 1;
  204. /* skip entries marked unused in the bitmap */
  205. if (!(block->pagehdr.bitmap[offset / 8] &
  206. (1 << (offset % 8)))) {
  207. _debug("ENT[%Zu.%u]: unused",
  208. blkoff / sizeof(union afs_dir_block), offset);
  209. if (offset >= curr)
  210. *fpos = blkoff +
  211. next * sizeof(union afs_dirent);
  212. continue;
  213. }
  214. /* got a valid entry */
  215. dire = &block->dirents[offset];
  216. nlen = strnlen(dire->u.name,
  217. sizeof(*block) -
  218. offset * sizeof(union afs_dirent));
  219. _debug("ENT[%Zu.%u]: %s %Zu \"%s\"",
  220. blkoff / sizeof(union afs_dir_block), offset,
  221. (offset < curr ? "skip" : "fill"),
  222. nlen, dire->u.name);
  223. /* work out where the next possible entry is */
  224. for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) {
  225. if (next >= AFS_DIRENT_PER_BLOCK) {
  226. _debug("ENT[%Zu.%u]:"
  227. " %u travelled beyond end dir block"
  228. " (len %u/%Zu)",
  229. blkoff / sizeof(union afs_dir_block),
  230. offset, next, tmp, nlen);
  231. return -EIO;
  232. }
  233. if (!(block->pagehdr.bitmap[next / 8] &
  234. (1 << (next % 8)))) {
  235. _debug("ENT[%Zu.%u]:"
  236. " %u unmarked extension (len %u/%Zu)",
  237. blkoff / sizeof(union afs_dir_block),
  238. offset, next, tmp, nlen);
  239. return -EIO;
  240. }
  241. _debug("ENT[%Zu.%u]: ext %u/%Zu",
  242. blkoff / sizeof(union afs_dir_block),
  243. next, tmp, nlen);
  244. next++;
  245. }
  246. /* skip if starts before the current position */
  247. if (offset < curr)
  248. continue;
  249. /* found the next entry */
  250. ret = filldir(cookie,
  251. dire->u.name,
  252. nlen,
  253. blkoff + offset * sizeof(union afs_dirent),
  254. ntohl(dire->u.vnode),
  255. filldir == afs_dir_lookup_filldir ?
  256. ntohl(dire->u.unique) : DT_UNKNOWN);
  257. if (ret < 0) {
  258. _leave(" = 0 [full]");
  259. return 0;
  260. }
  261. *fpos = blkoff + next * sizeof(union afs_dirent);
  262. }
  263. _leave(" = 1 [more]");
  264. return 1;
  265. }
  266. /*
  267. * iterate through the data blob that lists the contents of an AFS directory
  268. */
  269. static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
  270. filldir_t filldir)
  271. {
  272. union afs_dir_block *dblock;
  273. struct afs_dir_page *dbuf;
  274. struct page *page;
  275. unsigned blkoff, limit;
  276. int ret;
  277. _enter("{%lu},%u,,", dir->i_ino, *fpos);
  278. if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
  279. _leave(" = -ESTALE");
  280. return -ESTALE;
  281. }
  282. /* round the file position up to the next entry boundary */
  283. *fpos += sizeof(union afs_dirent) - 1;
  284. *fpos &= ~(sizeof(union afs_dirent) - 1);
  285. /* walk through the blocks in sequence */
  286. ret = 0;
  287. while (*fpos < dir->i_size) {
  288. blkoff = *fpos & ~(sizeof(union afs_dir_block) - 1);
  289. /* fetch the appropriate page from the directory */
  290. page = afs_dir_get_page(dir, blkoff / PAGE_SIZE);
  291. if (IS_ERR(page)) {
  292. ret = PTR_ERR(page);
  293. break;
  294. }
  295. limit = blkoff & ~(PAGE_SIZE - 1);
  296. dbuf = page_address(page);
  297. /* deal with the individual blocks stashed on this page */
  298. do {
  299. dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) /
  300. sizeof(union afs_dir_block)];
  301. ret = afs_dir_iterate_block(fpos, dblock, blkoff,
  302. cookie, filldir);
  303. if (ret != 1) {
  304. afs_dir_put_page(page);
  305. goto out;
  306. }
  307. blkoff += sizeof(union afs_dir_block);
  308. } while (*fpos < dir->i_size && blkoff < limit);
  309. afs_dir_put_page(page);
  310. ret = 0;
  311. }
  312. out:
  313. _leave(" = %d", ret);
  314. return ret;
  315. }
  316. /*
  317. * read an AFS directory
  318. */
  319. static int afs_dir_readdir(struct file *file, void *cookie, filldir_t filldir)
  320. {
  321. unsigned fpos;
  322. int ret;
  323. _enter("{%Ld,{%lu}}",
  324. file->f_pos, file->f_path.dentry->d_inode->i_ino);
  325. fpos = file->f_pos;
  326. ret = afs_dir_iterate(file->f_path.dentry->d_inode, &fpos,
  327. cookie, filldir);
  328. file->f_pos = fpos;
  329. _leave(" = %d", ret);
  330. return ret;
  331. }
  332. /*
  333. * search the directory for a name
  334. * - if afs_dir_iterate_block() spots this function, it'll pass the FID
  335. * uniquifier through dtype
  336. */
  337. static int afs_dir_lookup_filldir(void *_cookie, const char *name, int nlen,
  338. loff_t fpos, u64 ino, unsigned dtype)
  339. {
  340. struct afs_dir_lookup_cookie *cookie = _cookie;
  341. _enter("{%s,%Zu},%s,%u,,%llu,%u",
  342. cookie->name, cookie->nlen, name, nlen, ino, dtype);
  343. /* insanity checks first */
  344. BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
  345. BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
  346. if (cookie->nlen != nlen || memcmp(cookie->name, name, nlen) != 0) {
  347. _leave(" = 0 [no]");
  348. return 0;
  349. }
  350. cookie->fid.vnode = ino;
  351. cookie->fid.unique = dtype;
  352. cookie->found = 1;
  353. _leave(" = -1 [found]");
  354. return -1;
  355. }
  356. /*
  357. * do a lookup in a directory
  358. */
  359. static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
  360. struct afs_fid *fid)
  361. {
  362. struct afs_dir_lookup_cookie cookie;
  363. struct afs_super_info *as;
  364. unsigned fpos;
  365. int ret;
  366. _enter("{%lu},%p{%s},", dir->i_ino, dentry, dentry->d_name.name);
  367. as = dir->i_sb->s_fs_info;
  368. /* search the directory */
  369. cookie.name = dentry->d_name.name;
  370. cookie.nlen = dentry->d_name.len;
  371. cookie.fid.vid = as->volume->vid;
  372. cookie.found = 0;
  373. fpos = 0;
  374. ret = afs_dir_iterate(dir, &fpos, &cookie, afs_dir_lookup_filldir);
  375. if (ret < 0) {
  376. _leave(" = %d [iter]", ret);
  377. return ret;
  378. }
  379. ret = -ENOENT;
  380. if (!cookie.found) {
  381. _leave(" = -ENOENT [not found]");
  382. return -ENOENT;
  383. }
  384. *fid = cookie.fid;
  385. _leave(" = 0 { vn=%u u=%u }", fid->vnode, fid->unique);
  386. return 0;
  387. }
  388. /*
  389. * look up an entry in a directory
  390. */
  391. static struct dentry *afs_dir_lookup(struct inode *dir, struct dentry *dentry,
  392. struct nameidata *nd)
  393. {
  394. struct afs_vnode *vnode;
  395. struct afs_fid fid;
  396. struct inode *inode;
  397. int ret;
  398. _enter("{%lu},%p{%s}", dir->i_ino, dentry, dentry->d_name.name);
  399. if (dentry->d_name.len > 255) {
  400. _leave(" = -ENAMETOOLONG");
  401. return ERR_PTR(-ENAMETOOLONG);
  402. }
  403. vnode = AFS_FS_I(dir);
  404. if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
  405. _leave(" = -ESTALE");
  406. return ERR_PTR(-ESTALE);
  407. }
  408. ret = afs_do_lookup(dir, dentry, &fid);
  409. if (ret < 0) {
  410. _leave(" = %d [do]", ret);
  411. return ERR_PTR(ret);
  412. }
  413. /* instantiate the dentry */
  414. inode = afs_iget(dir->i_sb, &fid);
  415. if (IS_ERR(inode)) {
  416. _leave(" = %ld", PTR_ERR(inode));
  417. return ERR_PTR(PTR_ERR(inode));
  418. }
  419. dentry->d_op = &afs_fs_dentry_operations;
  420. d_add(dentry, inode);
  421. _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%lu }",
  422. fid.vnode,
  423. fid.unique,
  424. dentry->d_inode->i_ino,
  425. dentry->d_inode->i_version);
  426. return NULL;
  427. }
  428. /*
  429. * propagate changed and modified flags on a directory to all the children of
  430. * that directory as they may indicate that the ACL on the dir has changed,
  431. * potentially rendering the child inaccessible or that a file has been deleted
  432. * or renamed
  433. */
  434. static void afs_propagate_dir_changes(struct dentry *dir)
  435. {
  436. struct dentry *child;
  437. bool c, m;
  438. c = test_bit(AFS_VNODE_CHANGED, &AFS_FS_I(dir->d_inode)->flags);
  439. m = test_bit(AFS_VNODE_MODIFIED, &AFS_FS_I(dir->d_inode)->flags);
  440. _enter("{%d,%d}", c, m);
  441. spin_lock(&dir->d_lock);
  442. list_for_each_entry(child, &dir->d_subdirs, d_u.d_child) {
  443. if (child->d_inode) {
  444. struct afs_vnode *vnode;
  445. _debug("tag %s", child->d_name.name);
  446. vnode = AFS_FS_I(child->d_inode);
  447. if (c)
  448. set_bit(AFS_VNODE_DIR_CHANGED, &vnode->flags);
  449. if (m)
  450. set_bit(AFS_VNODE_DIR_MODIFIED, &vnode->flags);
  451. }
  452. }
  453. spin_unlock(&dir->d_lock);
  454. }
  455. /*
  456. * check that a dentry lookup hit has found a valid entry
  457. * - NOTE! the hit can be a negative hit too, so we can't assume we have an
  458. * inode
  459. * - there are several things we need to check
  460. * - parent dir data changes (rm, rmdir, rename, mkdir, create, link,
  461. * symlink)
  462. * - parent dir metadata changed (security changes)
  463. * - dentry data changed (write, truncate)
  464. * - dentry metadata changed (security changes)
  465. */
  466. static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
  467. {
  468. struct afs_vnode *vnode;
  469. struct afs_fid fid;
  470. struct dentry *parent;
  471. struct inode *inode, *dir;
  472. int ret;
  473. vnode = AFS_FS_I(dentry->d_inode);
  474. _enter("{sb=%p n=%s fl=%lx},",
  475. dentry->d_sb, dentry->d_name.name, vnode->flags);
  476. /* lock down the parent dentry so we can peer at it */
  477. parent = dget_parent(dentry);
  478. dir = parent->d_inode;
  479. inode = dentry->d_inode;
  480. /* handle a negative dentry */
  481. if (!inode)
  482. goto out_bad;
  483. /* handle a bad inode */
  484. if (is_bad_inode(inode)) {
  485. printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
  486. parent->d_name.name, dentry->d_name.name);
  487. goto out_bad;
  488. }
  489. /* check that this dirent still exists if the directory's contents were
  490. * modified */
  491. if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
  492. _debug("%s: parent dir deleted", dentry->d_name.name);
  493. goto out_bad;
  494. }
  495. if (test_and_clear_bit(AFS_VNODE_DIR_MODIFIED, &vnode->flags)) {
  496. /* rm/rmdir/rename may have occurred */
  497. _debug("dir modified");
  498. /* search the directory for this vnode */
  499. ret = afs_do_lookup(dir, dentry, &fid);
  500. if (ret == -ENOENT) {
  501. _debug("%s: dirent not found", dentry->d_name.name);
  502. goto not_found;
  503. }
  504. if (ret < 0) {
  505. _debug("failed to iterate dir %s: %d",
  506. parent->d_name.name, ret);
  507. goto out_bad;
  508. }
  509. /* if the vnode ID has changed, then the dirent points to a
  510. * different file */
  511. if (fid.vnode != vnode->fid.vnode) {
  512. _debug("%s: dirent changed [%u != %u]",
  513. dentry->d_name.name, fid.vnode,
  514. vnode->fid.vnode);
  515. goto not_found;
  516. }
  517. /* if the vnode ID uniqifier has changed, then the file has
  518. * been deleted */
  519. if (fid.unique != vnode->fid.unique) {
  520. _debug("%s: file deleted (uq %u -> %u I:%lu)",
  521. dentry->d_name.name, fid.unique,
  522. vnode->fid.unique, inode->i_version);
  523. spin_lock(&vnode->lock);
  524. set_bit(AFS_VNODE_DELETED, &vnode->flags);
  525. spin_unlock(&vnode->lock);
  526. invalidate_remote_inode(inode);
  527. goto out_bad;
  528. }
  529. }
  530. /* if the directory's metadata were changed then the security may be
  531. * different and we may no longer have access */
  532. mutex_lock(&vnode->cb_broken_lock);
  533. if (test_and_clear_bit(AFS_VNODE_DIR_CHANGED, &vnode->flags) ||
  534. test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) {
  535. _debug("%s: changed", dentry->d_name.name);
  536. set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
  537. if (afs_vnode_fetch_status(vnode) < 0) {
  538. mutex_unlock(&vnode->cb_broken_lock);
  539. goto out_bad;
  540. }
  541. }
  542. if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
  543. _debug("%s: file already deleted", dentry->d_name.name);
  544. mutex_unlock(&vnode->cb_broken_lock);
  545. goto out_bad;
  546. }
  547. /* if the vnode's data version number changed then its contents are
  548. * different */
  549. if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) {
  550. _debug("zap data");
  551. invalidate_remote_inode(inode);
  552. }
  553. if (S_ISDIR(inode->i_mode) &&
  554. (test_bit(AFS_VNODE_CHANGED, &vnode->flags) ||
  555. test_bit(AFS_VNODE_MODIFIED, &vnode->flags)))
  556. afs_propagate_dir_changes(dentry);
  557. clear_bit(AFS_VNODE_CHANGED, &vnode->flags);
  558. clear_bit(AFS_VNODE_MODIFIED, &vnode->flags);
  559. mutex_unlock(&vnode->cb_broken_lock);
  560. out_valid:
  561. dput(parent);
  562. _leave(" = 1 [valid]");
  563. return 1;
  564. /* the dirent, if it exists, now points to a different vnode */
  565. not_found:
  566. spin_lock(&dentry->d_lock);
  567. dentry->d_flags |= DCACHE_NFSFS_RENAMED;
  568. spin_unlock(&dentry->d_lock);
  569. out_bad:
  570. if (inode) {
  571. /* don't unhash if we have submounts */
  572. if (have_submounts(dentry))
  573. goto out_valid;
  574. }
  575. _debug("dropping dentry %s/%s",
  576. parent->d_name.name, dentry->d_name.name);
  577. shrink_dcache_parent(dentry);
  578. d_drop(dentry);
  579. dput(parent);
  580. _leave(" = 0 [bad]");
  581. return 0;
  582. }
  583. /*
  584. * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
  585. * sleep)
  586. * - called from dput() when d_count is going to 0.
  587. * - return 1 to request dentry be unhashed, 0 otherwise
  588. */
  589. static int afs_d_delete(struct dentry *dentry)
  590. {
  591. _enter("%s", dentry->d_name.name);
  592. if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
  593. goto zap;
  594. if (dentry->d_inode &&
  595. test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags))
  596. goto zap;
  597. _leave(" = 0 [keep]");
  598. return 0;
  599. zap:
  600. _leave(" = 1 [zap]");
  601. return 1;
  602. }