aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/posix_acl.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/posix_acl.h')
-rw-r--r--include/linux/posix_acl.h83
1 files changed, 30 insertions, 53 deletions
diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h
index 54211c1cd926..b7681102a4b9 100644
--- a/include/linux/posix_acl.h
+++ b/include/linux/posix_acl.h
@@ -9,6 +9,7 @@
9#define __LINUX_POSIX_ACL_H 9#define __LINUX_POSIX_ACL_H
10 10
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/rcupdate.h>
12 13
13#define ACL_UNDEFINED_ID (-1) 14#define ACL_UNDEFINED_ID (-1)
14 15
@@ -38,7 +39,10 @@ struct posix_acl_entry {
38}; 39};
39 40
40struct posix_acl { 41struct posix_acl {
41 atomic_t a_refcount; 42 union {
43 atomic_t a_refcount;
44 struct rcu_head a_rcu;
45 };
42 unsigned int a_count; 46 unsigned int a_count;
43 struct posix_acl_entry a_entries[0]; 47 struct posix_acl_entry a_entries[0];
44}; 48};
@@ -65,7 +69,7 @@ static inline void
65posix_acl_release(struct posix_acl *acl) 69posix_acl_release(struct posix_acl *acl)
66{ 70{
67 if (acl && atomic_dec_and_test(&acl->a_refcount)) 71 if (acl && atomic_dec_and_test(&acl->a_refcount))
68 kfree(acl); 72 kfree_rcu(acl, a_rcu);
69} 73}
70 74
71 75
@@ -73,32 +77,33 @@ posix_acl_release(struct posix_acl *acl)
73 77
74extern void posix_acl_init(struct posix_acl *, int); 78extern void posix_acl_init(struct posix_acl *, int);
75extern struct posix_acl *posix_acl_alloc(int, gfp_t); 79extern struct posix_acl *posix_acl_alloc(int, gfp_t);
76extern struct posix_acl *posix_acl_clone(const struct posix_acl *, gfp_t);
77extern int posix_acl_valid(const struct posix_acl *); 80extern int posix_acl_valid(const struct posix_acl *);
78extern int posix_acl_permission(struct inode *, const struct posix_acl *, int); 81extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
79extern struct posix_acl *posix_acl_from_mode(mode_t, gfp_t); 82extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
80extern int posix_acl_equiv_mode(const struct posix_acl *, mode_t *); 83extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
81extern int posix_acl_create_masq(struct posix_acl *, mode_t *); 84extern int posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
82extern int posix_acl_chmod_masq(struct posix_acl *, mode_t); 85extern int posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
83 86
84extern struct posix_acl *get_posix_acl(struct inode *, int); 87extern struct posix_acl *get_posix_acl(struct inode *, int);
85extern int set_posix_acl(struct inode *, int, struct posix_acl *); 88extern int set_posix_acl(struct inode *, int, struct posix_acl *);
86 89
87#ifdef CONFIG_FS_POSIX_ACL 90#ifdef CONFIG_FS_POSIX_ACL
88static inline struct posix_acl *get_cached_acl(struct inode *inode, int type) 91static inline struct posix_acl **acl_by_type(struct inode *inode, int type)
89{ 92{
90 struct posix_acl **p, *acl;
91 switch (type) { 93 switch (type) {
92 case ACL_TYPE_ACCESS: 94 case ACL_TYPE_ACCESS:
93 p = &inode->i_acl; 95 return &inode->i_acl;
94 break;
95 case ACL_TYPE_DEFAULT: 96 case ACL_TYPE_DEFAULT:
96 p = &inode->i_default_acl; 97 return &inode->i_default_acl;
97 break;
98 default: 98 default:
99 return ERR_PTR(-EINVAL); 99 BUG();
100 } 100 }
101 acl = ACCESS_ONCE(*p); 101}
102
103static inline struct posix_acl *get_cached_acl(struct inode *inode, int type)
104{
105 struct posix_acl **p = acl_by_type(inode, type);
106 struct posix_acl *acl = ACCESS_ONCE(*p);
102 if (acl) { 107 if (acl) {
103 spin_lock(&inode->i_lock); 108 spin_lock(&inode->i_lock);
104 acl = *p; 109 acl = *p;
@@ -109,41 +114,20 @@ static inline struct posix_acl *get_cached_acl(struct inode *inode, int type)
109 return acl; 114 return acl;
110} 115}
111 116
112static inline int negative_cached_acl(struct inode *inode, int type) 117static inline struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type)
113{ 118{
114 struct posix_acl **p, *acl; 119 return rcu_dereference(*acl_by_type(inode, type));
115 switch (type) {
116 case ACL_TYPE_ACCESS:
117 p = &inode->i_acl;
118 break;
119 case ACL_TYPE_DEFAULT:
120 p = &inode->i_default_acl;
121 break;
122 default:
123 BUG();
124 }
125 acl = ACCESS_ONCE(*p);
126 if (acl)
127 return 0;
128 return 1;
129} 120}
130 121
131static inline void set_cached_acl(struct inode *inode, 122static inline void set_cached_acl(struct inode *inode,
132 int type, 123 int type,
133 struct posix_acl *acl) 124 struct posix_acl *acl)
134{ 125{
135 struct posix_acl *old = NULL; 126 struct posix_acl **p = acl_by_type(inode, type);
127 struct posix_acl *old;
136 spin_lock(&inode->i_lock); 128 spin_lock(&inode->i_lock);
137 switch (type) { 129 old = *p;
138 case ACL_TYPE_ACCESS: 130 rcu_assign_pointer(*p, posix_acl_dup(acl));
139 old = inode->i_acl;
140 inode->i_acl = posix_acl_dup(acl);
141 break;
142 case ACL_TYPE_DEFAULT:
143 old = inode->i_default_acl;
144 inode->i_default_acl = posix_acl_dup(acl);
145 break;
146 }
147 spin_unlock(&inode->i_lock); 131 spin_unlock(&inode->i_lock);
148 if (old != ACL_NOT_CACHED) 132 if (old != ACL_NOT_CACHED)
149 posix_acl_release(old); 133 posix_acl_release(old);
@@ -151,18 +135,11 @@ static inline void set_cached_acl(struct inode *inode,
151 135
152static inline void forget_cached_acl(struct inode *inode, int type) 136static inline void forget_cached_acl(struct inode *inode, int type)
153{ 137{
154 struct posix_acl *old = NULL; 138 struct posix_acl **p = acl_by_type(inode, type);
139 struct posix_acl *old;
155 spin_lock(&inode->i_lock); 140 spin_lock(&inode->i_lock);
156 switch (type) { 141 old = *p;
157 case ACL_TYPE_ACCESS: 142 *p = ACL_NOT_CACHED;
158 old = inode->i_acl;
159 inode->i_acl = ACL_NOT_CACHED;
160 break;
161 case ACL_TYPE_DEFAULT:
162 old = inode->i_default_acl;
163 inode->i_default_acl = ACL_NOT_CACHED;
164 break;
165 }
166 spin_unlock(&inode->i_lock); 143 spin_unlock(&inode->i_lock);
167 if (old != ACL_NOT_CACHED) 144 if (old != ACL_NOT_CACHED)
168 posix_acl_release(old); 145 posix_acl_release(old);