cache.c 3.0 KB

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