diff options
author | Guangliang Zhao <lucienchao@gmail.com> | 2013-11-11 02:18:03 -0500 |
---|---|---|
committer | Ilya Dryomov <ilya.dryomov@inktank.com> | 2013-12-31 13:32:01 -0500 |
commit | 7221fe4c2ed72804b28633c8e0217d65abb0023f (patch) | |
tree | 70b02b121258635837f2db4b339a5fdcc014392a | |
parent | 61f68816211ee4b884dc0dda8dd4d977548f4865 (diff) |
ceph: add acl for cephfs
Signed-off-by: Guangliang Zhao <lucienchao@gmail.com>
Reviewed-by: Li Wang <li.wang@ubuntykylin.com>
Reviewed-by: Zheng Yan <zheng.z.yan@intel.com>
-rw-r--r-- | fs/ceph/Kconfig | 13 | ||||
-rw-r--r-- | fs/ceph/Makefile | 1 | ||||
-rw-r--r-- | fs/ceph/acl.c | 332 | ||||
-rw-r--r-- | fs/ceph/caps.c | 1 | ||||
-rw-r--r-- | fs/ceph/dir.c | 5 | ||||
-rw-r--r-- | fs/ceph/inode.c | 11 | ||||
-rw-r--r-- | fs/ceph/super.c | 4 | ||||
-rw-r--r-- | fs/ceph/super.h | 37 | ||||
-rw-r--r-- | fs/ceph/xattr.c | 60 |
9 files changed, 451 insertions, 13 deletions
diff --git a/fs/ceph/Kconfig b/fs/ceph/Kconfig index ac9a2ef5bb9b..264e9bf83ff3 100644 --- a/fs/ceph/Kconfig +++ b/fs/ceph/Kconfig | |||
@@ -25,3 +25,16 @@ config CEPH_FSCACHE | |||
25 | caching support for Ceph clients using FS-Cache | 25 | caching support for Ceph clients using FS-Cache |
26 | 26 | ||
27 | endif | 27 | endif |
28 | |||
29 | config CEPH_FS_POSIX_ACL | ||
30 | bool "Ceph POSIX Access Control Lists" | ||
31 | depends on CEPH_FS | ||
32 | select FS_POSIX_ACL | ||
33 | help | ||
34 | POSIX Access Control Lists (ACLs) support permissions for users and | ||
35 | groups beyond the owner/group/world scheme. | ||
36 | |||
37 | To learn more about Access Control Lists, visit the POSIX ACLs for | ||
38 | Linux website <http://acl.bestbits.at/>. | ||
39 | |||
40 | If you don't know what Access Control Lists are, say N | ||
diff --git a/fs/ceph/Makefile b/fs/ceph/Makefile index 32e30106a2f0..85a4230b9bff 100644 --- a/fs/ceph/Makefile +++ b/fs/ceph/Makefile | |||
@@ -10,3 +10,4 @@ ceph-y := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \ | |||
10 | debugfs.o | 10 | debugfs.o |
11 | 11 | ||
12 | ceph-$(CONFIG_CEPH_FSCACHE) += cache.o | 12 | ceph-$(CONFIG_CEPH_FSCACHE) += cache.o |
13 | ceph-$(CONFIG_CEPH_FS_POSIX_ACL) += acl.o | ||
diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c new file mode 100644 index 000000000000..64fddbc1d17b --- /dev/null +++ b/fs/ceph/acl.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * linux/fs/ceph/acl.c | ||
3 | * | ||
4 | * Copyright (C) 2013 Guangliang Zhao, <lucienchao@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public | ||
8 | * License v2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public | ||
16 | * License along with this program; if not, write to the | ||
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | * Boston, MA 021110-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #include <linux/ceph/ceph_debug.h> | ||
22 | #include <linux/fs.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/xattr.h> | ||
25 | #include <linux/posix_acl_xattr.h> | ||
26 | #include <linux/posix_acl.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include <linux/slab.h> | ||
29 | |||
30 | #include "super.h" | ||
31 | |||
32 | static inline void ceph_set_cached_acl(struct inode *inode, | ||
33 | int type, struct posix_acl *acl) | ||
34 | { | ||
35 | struct ceph_inode_info *ci = ceph_inode(inode); | ||
36 | |||
37 | spin_lock(&ci->i_ceph_lock); | ||
38 | if (__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 0)) | ||
39 | set_cached_acl(inode, type, acl); | ||
40 | spin_unlock(&ci->i_ceph_lock); | ||
41 | } | ||
42 | |||
43 | static inline struct posix_acl *ceph_get_cached_acl(struct inode *inode, | ||
44 | int type) | ||
45 | { | ||
46 | struct ceph_inode_info *ci = ceph_inode(inode); | ||
47 | struct posix_acl *acl = ACL_NOT_CACHED; | ||
48 | |||
49 | spin_lock(&ci->i_ceph_lock); | ||
50 | if (__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 0)) | ||
51 | acl = get_cached_acl(inode, type); | ||
52 | spin_unlock(&ci->i_ceph_lock); | ||
53 | |||
54 | return acl; | ||
55 | } | ||
56 | |||
57 | void ceph_forget_all_cached_acls(struct inode *inode) | ||
58 | { | ||
59 | forget_all_cached_acls(inode); | ||
60 | } | ||
61 | |||
62 | struct posix_acl *ceph_get_acl(struct inode *inode, int type) | ||
63 | { | ||
64 | int size; | ||
65 | const char *name; | ||
66 | char *value = NULL; | ||
67 | struct posix_acl *acl; | ||
68 | |||
69 | if (!IS_POSIXACL(inode)) | ||
70 | return NULL; | ||
71 | |||
72 | acl = ceph_get_cached_acl(inode, type); | ||
73 | if (acl != ACL_NOT_CACHED) | ||
74 | return acl; | ||
75 | |||
76 | switch (type) { | ||
77 | case ACL_TYPE_ACCESS: | ||
78 | name = POSIX_ACL_XATTR_ACCESS; | ||
79 | break; | ||
80 | case ACL_TYPE_DEFAULT: | ||
81 | name = POSIX_ACL_XATTR_DEFAULT; | ||
82 | break; | ||
83 | default: | ||
84 | BUG(); | ||
85 | } | ||
86 | |||
87 | size = __ceph_getxattr(inode, name, "", 0); | ||
88 | if (size > 0) { | ||
89 | value = kzalloc(size, GFP_NOFS); | ||
90 | if (!value) | ||
91 | return ERR_PTR(-ENOMEM); | ||
92 | size = __ceph_getxattr(inode, name, value, size); | ||
93 | } | ||
94 | |||
95 | if (size > 0) | ||
96 | acl = posix_acl_from_xattr(&init_user_ns, value, size); | ||
97 | else if (size == -ERANGE || size == -ENODATA || size == 0) | ||
98 | acl = NULL; | ||
99 | else | ||
100 | acl = ERR_PTR(-EIO); | ||
101 | |||
102 | kfree(value); | ||
103 | |||
104 | if (!IS_ERR(acl)) | ||
105 | ceph_set_cached_acl(inode, type, acl); | ||
106 | |||
107 | return acl; | ||
108 | } | ||
109 | |||
110 | static int ceph_set_acl(struct dentry *dentry, struct inode *inode, | ||
111 | struct posix_acl *acl, int type) | ||
112 | { | ||
113 | int ret = 0, size = 0; | ||
114 | const char *name = NULL; | ||
115 | char *value = NULL; | ||
116 | struct iattr newattrs; | ||
117 | umode_t new_mode = inode->i_mode, old_mode = inode->i_mode; | ||
118 | |||
119 | if (acl) { | ||
120 | ret = posix_acl_valid(acl); | ||
121 | if (ret < 0) | ||
122 | goto out; | ||
123 | } | ||
124 | |||
125 | switch (type) { | ||
126 | case ACL_TYPE_ACCESS: | ||
127 | name = POSIX_ACL_XATTR_ACCESS; | ||
128 | if (acl) { | ||
129 | ret = posix_acl_equiv_mode(acl, &new_mode); | ||
130 | if (ret < 0) | ||
131 | goto out; | ||
132 | if (ret == 0) | ||
133 | acl = NULL; | ||
134 | } | ||
135 | break; | ||
136 | case ACL_TYPE_DEFAULT: | ||
137 | if (!S_ISDIR(inode->i_mode)) { | ||
138 | ret = acl ? -EINVAL : 0; | ||
139 | goto out; | ||
140 | } | ||
141 | name = POSIX_ACL_XATTR_DEFAULT; | ||
142 | break; | ||
143 | default: | ||
144 | ret = -EINVAL; | ||
145 | goto out; | ||
146 | } | ||
147 | |||
148 | if (acl) { | ||
149 | size = posix_acl_xattr_size(acl->a_count); | ||
150 | value = kmalloc(size, GFP_NOFS); | ||
151 | if (!value) { | ||
152 | ret = -ENOMEM; | ||
153 | goto out; | ||
154 | } | ||
155 | |||
156 | ret = posix_acl_to_xattr(&init_user_ns, acl, value, size); | ||
157 | if (ret < 0) | ||
158 | goto out_free; | ||
159 | } | ||
160 | |||
161 | if (new_mode != old_mode) { | ||
162 | newattrs.ia_mode = new_mode; | ||
163 | newattrs.ia_valid = ATTR_MODE; | ||
164 | ret = ceph_setattr(dentry, &newattrs); | ||
165 | if (ret) | ||
166 | goto out_free; | ||
167 | } | ||
168 | |||
169 | if (value) | ||
170 | ret = __ceph_setxattr(dentry, name, value, size, 0); | ||
171 | else | ||
172 | ret = __ceph_removexattr(dentry, name); | ||
173 | |||
174 | if (ret) { | ||
175 | if (new_mode != old_mode) { | ||
176 | newattrs.ia_mode = old_mode; | ||
177 | newattrs.ia_valid = ATTR_MODE; | ||
178 | ceph_setattr(dentry, &newattrs); | ||
179 | } | ||
180 | goto out_free; | ||
181 | } | ||
182 | |||
183 | ceph_set_cached_acl(inode, type, acl); | ||
184 | |||
185 | out_free: | ||
186 | kfree(value); | ||
187 | out: | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | int ceph_init_acl(struct dentry *dentry, struct inode *inode, struct inode *dir) | ||
192 | { | ||
193 | struct posix_acl *acl = NULL; | ||
194 | int ret = 0; | ||
195 | |||
196 | if (!S_ISLNK(inode->i_mode)) { | ||
197 | if (IS_POSIXACL(dir)) { | ||
198 | acl = ceph_get_acl(dir, ACL_TYPE_DEFAULT); | ||
199 | if (IS_ERR(acl)) { | ||
200 | ret = PTR_ERR(acl); | ||
201 | goto out; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | if (!acl) | ||
206 | inode->i_mode &= ~current_umask(); | ||
207 | } | ||
208 | |||
209 | if (IS_POSIXACL(dir) && acl) { | ||
210 | if (S_ISDIR(inode->i_mode)) { | ||
211 | ret = ceph_set_acl(dentry, inode, acl, | ||
212 | ACL_TYPE_DEFAULT); | ||
213 | if (ret) | ||
214 | goto out_release; | ||
215 | } | ||
216 | ret = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode); | ||
217 | if (ret < 0) | ||
218 | goto out; | ||
219 | else if (ret > 0) | ||
220 | ret = ceph_set_acl(dentry, inode, acl, ACL_TYPE_ACCESS); | ||
221 | else | ||
222 | cache_no_acl(inode); | ||
223 | } else { | ||
224 | cache_no_acl(inode); | ||
225 | } | ||
226 | |||
227 | out_release: | ||
228 | posix_acl_release(acl); | ||
229 | out: | ||
230 | return ret; | ||
231 | } | ||
232 | |||
233 | int ceph_acl_chmod(struct dentry *dentry, struct inode *inode) | ||
234 | { | ||
235 | struct posix_acl *acl; | ||
236 | int ret = 0; | ||
237 | |||
238 | if (S_ISLNK(inode->i_mode)) { | ||
239 | ret = -EOPNOTSUPP; | ||
240 | goto out; | ||
241 | } | ||
242 | |||
243 | if (!IS_POSIXACL(inode)) | ||
244 | goto out; | ||
245 | |||
246 | acl = ceph_get_acl(inode, ACL_TYPE_ACCESS); | ||
247 | if (IS_ERR_OR_NULL(acl)) { | ||
248 | ret = PTR_ERR(acl); | ||
249 | goto out; | ||
250 | } | ||
251 | |||
252 | ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode); | ||
253 | if (ret) | ||
254 | goto out; | ||
255 | ret = ceph_set_acl(dentry, inode, acl, ACL_TYPE_ACCESS); | ||
256 | posix_acl_release(acl); | ||
257 | out: | ||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | static int ceph_xattr_acl_get(struct dentry *dentry, const char *name, | ||
262 | void *value, size_t size, int type) | ||
263 | { | ||
264 | struct posix_acl *acl; | ||
265 | int ret = 0; | ||
266 | |||
267 | if (!IS_POSIXACL(dentry->d_inode)) | ||
268 | return -EOPNOTSUPP; | ||
269 | |||
270 | acl = ceph_get_acl(dentry->d_inode, type); | ||
271 | if (IS_ERR(acl)) | ||
272 | return PTR_ERR(acl); | ||
273 | if (acl == NULL) | ||
274 | return -ENODATA; | ||
275 | |||
276 | ret = posix_acl_to_xattr(&init_user_ns, acl, value, size); | ||
277 | posix_acl_release(acl); | ||
278 | |||
279 | return ret; | ||
280 | } | ||
281 | |||
282 | static int ceph_xattr_acl_set(struct dentry *dentry, const char *name, | ||
283 | const void *value, size_t size, int flags, int type) | ||
284 | { | ||
285 | int ret = 0; | ||
286 | struct posix_acl *acl = NULL; | ||
287 | |||
288 | if (!inode_owner_or_capable(dentry->d_inode)) { | ||
289 | ret = -EPERM; | ||
290 | goto out; | ||
291 | } | ||
292 | |||
293 | if (!IS_POSIXACL(dentry->d_inode)) { | ||
294 | ret = -EOPNOTSUPP; | ||
295 | goto out; | ||
296 | } | ||
297 | |||
298 | if (value) { | ||
299 | acl = posix_acl_from_xattr(&init_user_ns, value, size); | ||
300 | if (IS_ERR(acl)) { | ||
301 | ret = PTR_ERR(acl); | ||
302 | goto out; | ||
303 | } | ||
304 | |||
305 | if (acl) { | ||
306 | ret = posix_acl_valid(acl); | ||
307 | if (ret) | ||
308 | goto out_release; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | ret = ceph_set_acl(dentry, dentry->d_inode, acl, type); | ||
313 | |||
314 | out_release: | ||
315 | posix_acl_release(acl); | ||
316 | out: | ||
317 | return ret; | ||
318 | } | ||
319 | |||
320 | const struct xattr_handler ceph_xattr_acl_default_handler = { | ||
321 | .prefix = POSIX_ACL_XATTR_DEFAULT, | ||
322 | .flags = ACL_TYPE_DEFAULT, | ||
323 | .get = ceph_xattr_acl_get, | ||
324 | .set = ceph_xattr_acl_set, | ||
325 | }; | ||
326 | |||
327 | const struct xattr_handler ceph_xattr_acl_access_handler = { | ||
328 | .prefix = POSIX_ACL_XATTR_ACCESS, | ||
329 | .flags = ACL_TYPE_ACCESS, | ||
330 | .get = ceph_xattr_acl_get, | ||
331 | .set = ceph_xattr_acl_set, | ||
332 | }; | ||
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 3c0a4bd74996..9289c6b2f1bb 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c | |||
@@ -2464,6 +2464,7 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant, | |||
2464 | ceph_buffer_put(ci->i_xattrs.blob); | 2464 | ceph_buffer_put(ci->i_xattrs.blob); |
2465 | ci->i_xattrs.blob = ceph_buffer_get(xattr_buf); | 2465 | ci->i_xattrs.blob = ceph_buffer_get(xattr_buf); |
2466 | ci->i_xattrs.version = version; | 2466 | ci->i_xattrs.version = version; |
2467 | ceph_forget_all_cached_acls(inode); | ||
2467 | } | 2468 | } |
2468 | } | 2469 | } |
2469 | 2470 | ||
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 2a0bcaeb189a..b629e9d59a35 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c | |||
@@ -693,6 +693,10 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry, | |||
693 | if (!err && !req->r_reply_info.head->is_dentry) | 693 | if (!err && !req->r_reply_info.head->is_dentry) |
694 | err = ceph_handle_notrace_create(dir, dentry); | 694 | err = ceph_handle_notrace_create(dir, dentry); |
695 | ceph_mdsc_put_request(req); | 695 | ceph_mdsc_put_request(req); |
696 | |||
697 | if (!err) | ||
698 | err = ceph_init_acl(dentry, dentry->d_inode, dir); | ||
699 | |||
696 | if (err) | 700 | if (err) |
697 | d_drop(dentry); | 701 | d_drop(dentry); |
698 | return err; | 702 | return err; |
@@ -1293,6 +1297,7 @@ const struct inode_operations ceph_dir_iops = { | |||
1293 | .getxattr = ceph_getxattr, | 1297 | .getxattr = ceph_getxattr, |
1294 | .listxattr = ceph_listxattr, | 1298 | .listxattr = ceph_listxattr, |
1295 | .removexattr = ceph_removexattr, | 1299 | .removexattr = ceph_removexattr, |
1300 | .get_acl = ceph_get_acl, | ||
1296 | .mknod = ceph_mknod, | 1301 | .mknod = ceph_mknod, |
1297 | .symlink = ceph_symlink, | 1302 | .symlink = ceph_symlink, |
1298 | .mkdir = ceph_mkdir, | 1303 | .mkdir = ceph_mkdir, |
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index d37b2dc01d3f..a808bfb8d8d8 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c | |||
@@ -95,6 +95,7 @@ const struct inode_operations ceph_file_iops = { | |||
95 | .getxattr = ceph_getxattr, | 95 | .getxattr = ceph_getxattr, |
96 | .listxattr = ceph_listxattr, | 96 | .listxattr = ceph_listxattr, |
97 | .removexattr = ceph_removexattr, | 97 | .removexattr = ceph_removexattr, |
98 | .get_acl = ceph_get_acl, | ||
98 | }; | 99 | }; |
99 | 100 | ||
100 | 101 | ||
@@ -680,6 +681,7 @@ static int fill_inode(struct inode *inode, | |||
680 | memcpy(ci->i_xattrs.blob->vec.iov_base, | 681 | memcpy(ci->i_xattrs.blob->vec.iov_base, |
681 | iinfo->xattr_data, iinfo->xattr_len); | 682 | iinfo->xattr_data, iinfo->xattr_len); |
682 | ci->i_xattrs.version = le64_to_cpu(info->xattr_version); | 683 | ci->i_xattrs.version = le64_to_cpu(info->xattr_version); |
684 | ceph_forget_all_cached_acls(inode); | ||
683 | xattr_blob = NULL; | 685 | xattr_blob = NULL; |
684 | } | 686 | } |
685 | 687 | ||
@@ -1612,6 +1614,7 @@ static const struct inode_operations ceph_symlink_iops = { | |||
1612 | .getxattr = ceph_getxattr, | 1614 | .getxattr = ceph_getxattr, |
1613 | .listxattr = ceph_listxattr, | 1615 | .listxattr = ceph_listxattr, |
1614 | .removexattr = ceph_removexattr, | 1616 | .removexattr = ceph_removexattr, |
1617 | .get_acl = ceph_get_acl, | ||
1615 | }; | 1618 | }; |
1616 | 1619 | ||
1617 | /* | 1620 | /* |
@@ -1685,6 +1688,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) | |||
1685 | dirtied |= CEPH_CAP_AUTH_EXCL; | 1688 | dirtied |= CEPH_CAP_AUTH_EXCL; |
1686 | } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 || | 1689 | } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 || |
1687 | attr->ia_mode != inode->i_mode) { | 1690 | attr->ia_mode != inode->i_mode) { |
1691 | inode->i_mode = attr->ia_mode; | ||
1688 | req->r_args.setattr.mode = cpu_to_le32(attr->ia_mode); | 1692 | req->r_args.setattr.mode = cpu_to_le32(attr->ia_mode); |
1689 | mask |= CEPH_SETATTR_MODE; | 1693 | mask |= CEPH_SETATTR_MODE; |
1690 | release |= CEPH_CAP_AUTH_SHARED; | 1694 | release |= CEPH_CAP_AUTH_SHARED; |
@@ -1800,6 +1804,12 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) | |||
1800 | if (inode_dirty_flags) | 1804 | if (inode_dirty_flags) |
1801 | __mark_inode_dirty(inode, inode_dirty_flags); | 1805 | __mark_inode_dirty(inode, inode_dirty_flags); |
1802 | 1806 | ||
1807 | if (ia_valid & ATTR_MODE) { | ||
1808 | err = ceph_acl_chmod(dentry, inode); | ||
1809 | if (err) | ||
1810 | goto out_put; | ||
1811 | } | ||
1812 | |||
1803 | if (mask) { | 1813 | if (mask) { |
1804 | req->r_inode = inode; | 1814 | req->r_inode = inode; |
1805 | ihold(inode); | 1815 | ihold(inode); |
@@ -1819,6 +1829,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) | |||
1819 | return err; | 1829 | return err; |
1820 | out: | 1830 | out: |
1821 | spin_unlock(&ci->i_ceph_lock); | 1831 | spin_unlock(&ci->i_ceph_lock); |
1832 | out_put: | ||
1822 | ceph_mdsc_put_request(req); | 1833 | ceph_mdsc_put_request(req); |
1823 | return err; | 1834 | return err; |
1824 | } | 1835 | } |
diff --git a/fs/ceph/super.c b/fs/ceph/super.c index e58bd4a23bfb..c6740e43a351 100644 --- a/fs/ceph/super.c +++ b/fs/ceph/super.c | |||
@@ -819,7 +819,11 @@ static int ceph_set_super(struct super_block *s, void *data) | |||
819 | 819 | ||
820 | s->s_flags = fsc->mount_options->sb_flags; | 820 | s->s_flags = fsc->mount_options->sb_flags; |
821 | s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */ | 821 | s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */ |
822 | #ifdef CONFIG_CEPH_FS_POSIX_ACL | ||
823 | s->s_flags |= MS_POSIXACL; | ||
824 | #endif | ||
822 | 825 | ||
826 | s->s_xattr = ceph_xattr_handlers; | ||
823 | s->s_fs_info = fsc; | 827 | s->s_fs_info = fsc; |
824 | fsc->sb = s; | 828 | fsc->sb = s; |
825 | 829 | ||
diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 8de94b564d67..7fa78a7c8894 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h | |||
@@ -335,7 +335,6 @@ struct ceph_inode_info { | |||
335 | u32 i_fscache_gen; /* sequence, for delayed fscache validate */ | 335 | u32 i_fscache_gen; /* sequence, for delayed fscache validate */ |
336 | struct work_struct i_revalidate_work; | 336 | struct work_struct i_revalidate_work; |
337 | #endif | 337 | #endif |
338 | |||
339 | struct inode vfs_inode; /* at end */ | 338 | struct inode vfs_inode; /* at end */ |
340 | }; | 339 | }; |
341 | 340 | ||
@@ -725,6 +724,9 @@ extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
725 | /* xattr.c */ | 724 | /* xattr.c */ |
726 | extern int ceph_setxattr(struct dentry *, const char *, const void *, | 725 | extern int ceph_setxattr(struct dentry *, const char *, const void *, |
727 | size_t, int); | 726 | size_t, int); |
727 | int __ceph_setxattr(struct dentry *, const char *, const void *, size_t, int); | ||
728 | ssize_t __ceph_getxattr(struct inode *, const char *, void *, size_t); | ||
729 | int __ceph_removexattr(struct dentry *, const char *); | ||
728 | extern ssize_t ceph_getxattr(struct dentry *, const char *, void *, size_t); | 730 | extern ssize_t ceph_getxattr(struct dentry *, const char *, void *, size_t); |
729 | extern ssize_t ceph_listxattr(struct dentry *, char *, size_t); | 731 | extern ssize_t ceph_listxattr(struct dentry *, char *, size_t); |
730 | extern int ceph_removexattr(struct dentry *, const char *); | 732 | extern int ceph_removexattr(struct dentry *, const char *); |
@@ -733,6 +735,39 @@ extern void __ceph_destroy_xattrs(struct ceph_inode_info *ci); | |||
733 | extern void __init ceph_xattr_init(void); | 735 | extern void __init ceph_xattr_init(void); |
734 | extern void ceph_xattr_exit(void); | 736 | extern void ceph_xattr_exit(void); |
735 | 737 | ||
738 | /* acl.c */ | ||
739 | extern const struct xattr_handler ceph_xattr_acl_access_handler; | ||
740 | extern const struct xattr_handler ceph_xattr_acl_default_handler; | ||
741 | extern const struct xattr_handler *ceph_xattr_handlers[]; | ||
742 | |||
743 | #ifdef CONFIG_CEPH_FS_POSIX_ACL | ||
744 | |||
745 | struct posix_acl *ceph_get_acl(struct inode *, int); | ||
746 | int ceph_init_acl(struct dentry *, struct inode *, struct inode *); | ||
747 | int ceph_acl_chmod(struct dentry *, struct inode *); | ||
748 | void ceph_forget_all_cached_acls(struct inode *inode); | ||
749 | |||
750 | #else | ||
751 | |||
752 | #define ceph_get_acl NULL | ||
753 | |||
754 | static inline int ceph_init_acl(struct dentry *dentry, struct inode *inode, | ||
755 | struct inode *dir) | ||
756 | { | ||
757 | return 0; | ||
758 | } | ||
759 | |||
760 | static inline int ceph_acl_chmod(struct dentry *dentry, struct inode *inode) | ||
761 | { | ||
762 | return 0; | ||
763 | } | ||
764 | |||
765 | static inline void ceph_forget_all_cached_acls(struct inode *inode) | ||
766 | { | ||
767 | } | ||
768 | |||
769 | #endif | ||
770 | |||
736 | /* caps.c */ | 771 | /* caps.c */ |
737 | extern const char *ceph_cap_string(int c); | 772 | extern const char *ceph_cap_string(int c); |
738 | extern void ceph_handle_caps(struct ceph_mds_session *session, | 773 | extern void ceph_handle_caps(struct ceph_mds_session *session, |
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c index be661d8f532a..c7581f3733c1 100644 --- a/fs/ceph/xattr.c +++ b/fs/ceph/xattr.c | |||
@@ -11,11 +11,24 @@ | |||
11 | #define XATTR_CEPH_PREFIX "ceph." | 11 | #define XATTR_CEPH_PREFIX "ceph." |
12 | #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1) | 12 | #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1) |
13 | 13 | ||
14 | /* | ||
15 | * List of handlers for synthetic system.* attributes. Other | ||
16 | * attributes are handled directly. | ||
17 | */ | ||
18 | const struct xattr_handler *ceph_xattr_handlers[] = { | ||
19 | #ifdef CONFIG_CEPH_FS_POSIX_ACL | ||
20 | &ceph_xattr_acl_access_handler, | ||
21 | &ceph_xattr_acl_default_handler, | ||
22 | #endif | ||
23 | NULL, | ||
24 | }; | ||
25 | |||
14 | static bool ceph_is_valid_xattr(const char *name) | 26 | static bool ceph_is_valid_xattr(const char *name) |
15 | { | 27 | { |
16 | return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) || | 28 | return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) || |
17 | !strncmp(name, XATTR_SECURITY_PREFIX, | 29 | !strncmp(name, XATTR_SECURITY_PREFIX, |
18 | XATTR_SECURITY_PREFIX_LEN) || | 30 | XATTR_SECURITY_PREFIX_LEN) || |
31 | !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) || | ||
19 | !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) || | 32 | !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) || |
20 | !strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); | 33 | !strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
21 | } | 34 | } |
@@ -663,10 +676,9 @@ void __ceph_build_xattrs_blob(struct ceph_inode_info *ci) | |||
663 | } | 676 | } |
664 | } | 677 | } |
665 | 678 | ||
666 | ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value, | 679 | ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value, |
667 | size_t size) | 680 | size_t size) |
668 | { | 681 | { |
669 | struct inode *inode = dentry->d_inode; | ||
670 | struct ceph_inode_info *ci = ceph_inode(inode); | 682 | struct ceph_inode_info *ci = ceph_inode(inode); |
671 | int err; | 683 | int err; |
672 | struct ceph_inode_xattr *xattr; | 684 | struct ceph_inode_xattr *xattr; |
@@ -675,7 +687,6 @@ ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value, | |||
675 | if (!ceph_is_valid_xattr(name)) | 687 | if (!ceph_is_valid_xattr(name)) |
676 | return -ENODATA; | 688 | return -ENODATA; |
677 | 689 | ||
678 | |||
679 | /* let's see if a virtual xattr was requested */ | 690 | /* let's see if a virtual xattr was requested */ |
680 | vxattr = ceph_match_vxattr(inode, name); | 691 | vxattr = ceph_match_vxattr(inode, name); |
681 | if (vxattr && !(vxattr->exists_cb && !vxattr->exists_cb(ci))) { | 692 | if (vxattr && !(vxattr->exists_cb && !vxattr->exists_cb(ci))) { |
@@ -725,6 +736,15 @@ out: | |||
725 | return err; | 736 | return err; |
726 | } | 737 | } |
727 | 738 | ||
739 | ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value, | ||
740 | size_t size) | ||
741 | { | ||
742 | if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) | ||
743 | return generic_getxattr(dentry, name, value, size); | ||
744 | |||
745 | return __ceph_getxattr(dentry->d_inode, name, value, size); | ||
746 | } | ||
747 | |||
728 | ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size) | 748 | ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size) |
729 | { | 749 | { |
730 | struct inode *inode = dentry->d_inode; | 750 | struct inode *inode = dentry->d_inode; |
@@ -863,8 +883,8 @@ out: | |||
863 | return err; | 883 | return err; |
864 | } | 884 | } |
865 | 885 | ||
866 | int ceph_setxattr(struct dentry *dentry, const char *name, | 886 | int __ceph_setxattr(struct dentry *dentry, const char *name, |
867 | const void *value, size_t size, int flags) | 887 | const void *value, size_t size, int flags) |
868 | { | 888 | { |
869 | struct inode *inode = dentry->d_inode; | 889 | struct inode *inode = dentry->d_inode; |
870 | struct ceph_vxattr *vxattr; | 890 | struct ceph_vxattr *vxattr; |
@@ -879,9 +899,6 @@ int ceph_setxattr(struct dentry *dentry, const char *name, | |||
879 | struct ceph_inode_xattr *xattr = NULL; | 899 | struct ceph_inode_xattr *xattr = NULL; |
880 | int required_blob_size; | 900 | int required_blob_size; |
881 | 901 | ||
882 | if (ceph_snap(inode) != CEPH_NOSNAP) | ||
883 | return -EROFS; | ||
884 | |||
885 | if (!ceph_is_valid_xattr(name)) | 902 | if (!ceph_is_valid_xattr(name)) |
886 | return -EOPNOTSUPP; | 903 | return -EOPNOTSUPP; |
887 | 904 | ||
@@ -958,6 +975,18 @@ out: | |||
958 | return err; | 975 | return err; |
959 | } | 976 | } |
960 | 977 | ||
978 | int ceph_setxattr(struct dentry *dentry, const char *name, | ||
979 | const void *value, size_t size, int flags) | ||
980 | { | ||
981 | if (ceph_snap(dentry->d_inode) != CEPH_NOSNAP) | ||
982 | return -EROFS; | ||
983 | |||
984 | if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) | ||
985 | return generic_setxattr(dentry, name, value, size, flags); | ||
986 | |||
987 | return __ceph_setxattr(dentry, name, value, size, flags); | ||
988 | } | ||
989 | |||
961 | static int ceph_send_removexattr(struct dentry *dentry, const char *name) | 990 | static int ceph_send_removexattr(struct dentry *dentry, const char *name) |
962 | { | 991 | { |
963 | struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); | 992 | struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); |
@@ -984,7 +1013,7 @@ static int ceph_send_removexattr(struct dentry *dentry, const char *name) | |||
984 | return err; | 1013 | return err; |
985 | } | 1014 | } |
986 | 1015 | ||
987 | int ceph_removexattr(struct dentry *dentry, const char *name) | 1016 | int __ceph_removexattr(struct dentry *dentry, const char *name) |
988 | { | 1017 | { |
989 | struct inode *inode = dentry->d_inode; | 1018 | struct inode *inode = dentry->d_inode; |
990 | struct ceph_vxattr *vxattr; | 1019 | struct ceph_vxattr *vxattr; |
@@ -994,9 +1023,6 @@ int ceph_removexattr(struct dentry *dentry, const char *name) | |||
994 | int required_blob_size; | 1023 | int required_blob_size; |
995 | int dirty; | 1024 | int dirty; |
996 | 1025 | ||
997 | if (ceph_snap(inode) != CEPH_NOSNAP) | ||
998 | return -EROFS; | ||
999 | |||
1000 | if (!ceph_is_valid_xattr(name)) | 1026 | if (!ceph_is_valid_xattr(name)) |
1001 | return -EOPNOTSUPP; | 1027 | return -EOPNOTSUPP; |
1002 | 1028 | ||
@@ -1053,3 +1079,13 @@ out: | |||
1053 | return err; | 1079 | return err; |
1054 | } | 1080 | } |
1055 | 1081 | ||
1082 | int ceph_removexattr(struct dentry *dentry, const char *name) | ||
1083 | { | ||
1084 | if (ceph_snap(dentry->d_inode) != CEPH_NOSNAP) | ||
1085 | return -EROFS; | ||
1086 | |||
1087 | if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) | ||
1088 | return generic_removexattr(dentry, name); | ||
1089 | |||
1090 | return __ceph_removexattr(dentry, name); | ||
1091 | } | ||