cache.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <linux/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 (!uid_eq(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. uid_eq(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 dentry *de;
  78. spin_lock(&parent->d_lock);
  79. list_for_each_entry(de, &parent->d_subdirs, d_child) {
  80. /* don't know what to do with negative dentries */
  81. if (d_inode(de) )
  82. coda_flag_inode(d_inode(de), flag);
  83. }
  84. spin_unlock(&parent->d_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. }