diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-08-04 22:44:40 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-08-04 22:44:40 -0400 |
commit | 24f0eed2668b059e847ff145848ddacb75419acc (patch) | |
tree | 010c89c06e191b068f8a078b10bfaf1d3699c834 /include | |
parent | 8b6b4628126fd73d0a53b499a26133c15b73c1e6 (diff) | |
parent | 3567866bf26190d1e734c975c907eb06e923ba23 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
RCUify freeing acls, let check_acl() go ahead in RCU mode if acl is cached
get rid of boilerplate switches in posix_acl.h
fix block device fallout from ->fsync() changes
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/posix_acl.h | 74 |
1 files changed, 26 insertions, 48 deletions
diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h index 951bba82d50d..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 | ||
40 | struct posix_acl { | 41 | struct 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 | |||
65 | posix_acl_release(struct posix_acl *acl) | 69 | posix_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 | ||
@@ -84,20 +88,22 @@ extern struct posix_acl *get_posix_acl(struct inode *, int); | |||
84 | extern int set_posix_acl(struct inode *, int, struct posix_acl *); | 88 | extern int set_posix_acl(struct inode *, int, struct posix_acl *); |
85 | 89 | ||
86 | #ifdef CONFIG_FS_POSIX_ACL | 90 | #ifdef CONFIG_FS_POSIX_ACL |
87 | static inline struct posix_acl *get_cached_acl(struct inode *inode, int type) | 91 | static inline struct posix_acl **acl_by_type(struct inode *inode, int type) |
88 | { | 92 | { |
89 | struct posix_acl **p, *acl; | ||
90 | switch (type) { | 93 | switch (type) { |
91 | case ACL_TYPE_ACCESS: | 94 | case ACL_TYPE_ACCESS: |
92 | p = &inode->i_acl; | 95 | return &inode->i_acl; |
93 | break; | ||
94 | case ACL_TYPE_DEFAULT: | 96 | case ACL_TYPE_DEFAULT: |
95 | p = &inode->i_default_acl; | 97 | return &inode->i_default_acl; |
96 | break; | ||
97 | default: | 98 | default: |
98 | return ERR_PTR(-EINVAL); | 99 | BUG(); |
99 | } | 100 | } |
100 | acl = ACCESS_ONCE(*p); | 101 | } |
102 | |||
103 | static 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); | ||
101 | if (acl) { | 107 | if (acl) { |
102 | spin_lock(&inode->i_lock); | 108 | spin_lock(&inode->i_lock); |
103 | acl = *p; | 109 | acl = *p; |
@@ -108,41 +114,20 @@ static inline struct posix_acl *get_cached_acl(struct inode *inode, int type) | |||
108 | return acl; | 114 | return acl; |
109 | } | 115 | } |
110 | 116 | ||
111 | static inline int negative_cached_acl(struct inode *inode, int type) | 117 | static inline struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type) |
112 | { | 118 | { |
113 | struct posix_acl **p, *acl; | 119 | return rcu_dereference(*acl_by_type(inode, type)); |
114 | switch (type) { | ||
115 | case ACL_TYPE_ACCESS: | ||
116 | p = &inode->i_acl; | ||
117 | break; | ||
118 | case ACL_TYPE_DEFAULT: | ||
119 | p = &inode->i_default_acl; | ||
120 | break; | ||
121 | default: | ||
122 | BUG(); | ||
123 | } | ||
124 | acl = ACCESS_ONCE(*p); | ||
125 | if (acl) | ||
126 | return 0; | ||
127 | return 1; | ||
128 | } | 120 | } |
129 | 121 | ||
130 | static inline void set_cached_acl(struct inode *inode, | 122 | static inline void set_cached_acl(struct inode *inode, |
131 | int type, | 123 | int type, |
132 | struct posix_acl *acl) | 124 | struct posix_acl *acl) |
133 | { | 125 | { |
134 | struct posix_acl *old = NULL; | 126 | struct posix_acl **p = acl_by_type(inode, type); |
127 | struct posix_acl *old; | ||
135 | spin_lock(&inode->i_lock); | 128 | spin_lock(&inode->i_lock); |
136 | switch (type) { | 129 | old = *p; |
137 | case ACL_TYPE_ACCESS: | 130 | rcu_assign_pointer(*p, posix_acl_dup(acl)); |
138 | old = inode->i_acl; | ||
139 | inode->i_acl = posix_acl_dup(acl); | ||
140 | break; | ||
141 | case ACL_TYPE_DEFAULT: | ||
142 | old = inode->i_default_acl; | ||
143 | inode->i_default_acl = posix_acl_dup(acl); | ||
144 | break; | ||
145 | } | ||
146 | spin_unlock(&inode->i_lock); | 131 | spin_unlock(&inode->i_lock); |
147 | if (old != ACL_NOT_CACHED) | 132 | if (old != ACL_NOT_CACHED) |
148 | posix_acl_release(old); | 133 | posix_acl_release(old); |
@@ -150,18 +135,11 @@ static inline void set_cached_acl(struct inode *inode, | |||
150 | 135 | ||
151 | static inline void forget_cached_acl(struct inode *inode, int type) | 136 | static inline void forget_cached_acl(struct inode *inode, int type) |
152 | { | 137 | { |
153 | struct posix_acl *old = NULL; | 138 | struct posix_acl **p = acl_by_type(inode, type); |
139 | struct posix_acl *old; | ||
154 | spin_lock(&inode->i_lock); | 140 | spin_lock(&inode->i_lock); |
155 | switch (type) { | 141 | old = *p; |
156 | case ACL_TYPE_ACCESS: | 142 | *p = ACL_NOT_CACHED; |
157 | old = inode->i_acl; | ||
158 | inode->i_acl = ACL_NOT_CACHED; | ||
159 | break; | ||
160 | case ACL_TYPE_DEFAULT: | ||
161 | old = inode->i_default_acl; | ||
162 | inode->i_default_acl = ACL_NOT_CACHED; | ||
163 | break; | ||
164 | } | ||
165 | spin_unlock(&inode->i_lock); | 143 | spin_unlock(&inode->i_lock); |
166 | if (old != ACL_NOT_CACHED) | 144 | if (old != ACL_NOT_CACHED) |
167 | posix_acl_release(old); | 145 | posix_acl_release(old); |