cache.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/sched.h>
  19. #include <linux/coda.h>
  20. #include <linux/coda_linux.h>
  21. #include <linux/coda_psdev.h>
  22. #include <linux/coda_fs_i.h>
  23. #include <linux/coda_cache.h>
  24. static atomic_t permission_epoch = ATOMIC_INIT(0);
  25. /* replace or extend an acl cache hit */
  26. void coda_cache_enter(struct inode *inode, int mask)
  27. {
  28. struct coda_inode_info *cii = ITOC(inode);
  29. cii->c_cached_epoch = atomic_read(&permission_epoch);
  30. if (cii->c_uid != current_fsuid()) {
  31. cii->c_uid = current_fsuid();
  32. cii->c_cached_perm = mask;
  33. } else
  34. cii->c_cached_perm |= mask;
  35. }
  36. /* remove cached acl from an inode */
  37. void coda_cache_clear_inode(struct inode *inode)
  38. {
  39. struct coda_inode_info *cii = ITOC(inode);
  40. cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
  41. }
  42. /* remove all acl caches */
  43. void coda_cache_clear_all(struct super_block *sb)
  44. {
  45. atomic_inc(&permission_epoch);
  46. }
  47. /* check if the mask has been matched against the acl already */
  48. int coda_cache_check(struct inode *inode, int mask)
  49. {
  50. struct coda_inode_info *cii = ITOC(inode);
  51. int hit;
  52. hit = (mask & cii->c_cached_perm) == mask &&
  53. cii->c_uid == current_fsuid() &&
  54. cii->c_cached_epoch == atomic_read(&permission_epoch);
  55. return hit;
  56. }
  57. /* Purging dentries and children */
  58. /* The following routines drop dentries which are not
  59. in use and flag dentries which are in use to be
  60. zapped later.
  61. The flags are detected by:
  62. - coda_dentry_revalidate (for lookups) if the flag is C_PURGE
  63. - coda_dentry_delete: to remove dentry from the cache when d_count
  64. falls to zero
  65. - an inode method coda_revalidate (for attributes) if the
  66. flag is C_VATTR
  67. */
  68. /* this won't do any harm: just flag all children */
  69. static void coda_flag_children(struct dentry *parent, int flag)
  70. {
  71. struct list_head *child;
  72. struct dentry *de;
  73. spin_lock(&dcache_lock);
  74. list_for_each(child, &parent->d_subdirs)
  75. {
  76. de = list_entry(child, struct dentry, d_u.d_child);
  77. /* don't know what to do with negative dentries */
  78. if ( ! de->d_inode )
  79. continue;
  80. coda_flag_inode(de->d_inode, flag);
  81. }
  82. spin_unlock(&dcache_lock);
  83. return;
  84. }
  85. void coda_flag_inode_children(struct inode *inode, int flag)
  86. {
  87. struct dentry *alias_de;
  88. if ( !inode || !S_ISDIR(inode->i_mode))
  89. return;
  90. alias_de = d_find_alias(inode);
  91. if (!alias_de)
  92. return;
  93. coda_flag_children(alias_de, flag);
  94. shrink_dcache_parent(alias_de);
  95. dput(alias_de);
  96. }