cache.c 3.0 KB

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