cache.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Cache operations for Coda.
  3. * For Linux 2.1: (C) 1997 Carnegie Mellon University
  4. * For Linux 2.3: (C) 2000 Carnegie Mellon University
  5. *
  6. * Carnegie Mellon encourages users of this code to contribute improvements
  7. * to the Coda project http://www.coda.cs.cmu.edu/ <coda@cs.cmu.edu>.
  8. */
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/time.h>
  12. #include <linux/fs.h>
  13. #include <linux/stat.h>
  14. #include <linux/errno.h>
  15. #include <asm/uaccess.h>
  16. #include <linux/string.h>
  17. #include <linux/list.h>
  18. #include <linux/coda.h>
  19. #include <linux/coda_linux.h>
  20. #include <linux/coda_psdev.h>
  21. #include <linux/coda_fs_i.h>
  22. #include <linux/coda_cache.h>
  23. static atomic_t permission_epoch = ATOMIC_INIT(0);
  24. /* replace or extend an acl cache hit */
  25. void coda_cache_enter(struct inode *inode, int mask)
  26. {
  27. struct coda_inode_info *cii = ITOC(inode);
  28. cii->c_cached_epoch = atomic_read(&permission_epoch);
  29. if (cii->c_uid != current->fsuid) {
  30. cii->c_uid = current->fsuid;
  31. cii->c_cached_perm = mask;
  32. } else
  33. cii->c_cached_perm |= mask;
  34. }
  35. /* remove cached acl from an inode */
  36. void coda_cache_clear_inode(struct inode *inode)
  37. {
  38. struct coda_inode_info *cii = ITOC(inode);
  39. cii->c_cached_perm = 0;
  40. }
  41. /* remove all acl caches */
  42. void coda_cache_clear_all(struct super_block *sb)
  43. {
  44. struct coda_sb_info *sbi;
  45. sbi = coda_sbp(sb);
  46. BUG_ON(!sbi);
  47. atomic_inc(&permission_epoch);
  48. }
  49. /* check if the mask has been matched against the acl already */
  50. int coda_cache_check(struct inode *inode, int mask)
  51. {
  52. struct coda_inode_info *cii = ITOC(inode);
  53. int hit;
  54. hit = (mask & cii->c_cached_perm) == mask &&
  55. cii->c_uid == current->fsuid &&
  56. cii->c_cached_epoch == atomic_read(&permission_epoch);
  57. return hit;
  58. }
  59. /* Purging dentries and children */
  60. /* The following routines drop dentries which are not
  61. in use and flag dentries which are in use to be
  62. zapped later.
  63. The flags are detected by:
  64. - coda_dentry_revalidate (for lookups) if the flag is C_PURGE
  65. - coda_dentry_delete: to remove dentry from the cache when d_count
  66. falls to zero
  67. - an inode method coda_revalidate (for attributes) if the
  68. flag is C_VATTR
  69. */
  70. /* this won't do any harm: just flag all children */
  71. static void coda_flag_children(struct dentry *parent, int flag)
  72. {
  73. struct list_head *child;
  74. struct dentry *de;
  75. spin_lock(&dcache_lock);
  76. list_for_each(child, &parent->d_subdirs)
  77. {
  78. de = list_entry(child, struct dentry, d_u.d_child);
  79. /* don't know what to do with negative dentries */
  80. if ( ! de->d_inode )
  81. continue;
  82. coda_flag_inode(de->d_inode, flag);
  83. }
  84. spin_unlock(&dcache_lock);
  85. return;
  86. }
  87. void coda_flag_inode_children(struct inode *inode, int flag)
  88. {
  89. struct dentry *alias_de;
  90. if ( !inode || !S_ISDIR(inode->i_mode))
  91. return;
  92. alias_de = d_find_alias(inode);
  93. if (!alias_de)
  94. return;
  95. coda_flag_children(alias_de, flag);
  96. shrink_dcache_parent(alias_de);
  97. dput(alias_de);
  98. }