aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@redhat.com>2008-07-24 12:16:36 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:05 -0400
commit33268eaf0b3db5e2bd12c0ada81a8e8f87a46d68 (patch)
tree93b6d00a73402b59c2ea7ae7434138feecefc085
parent6099afe88fe64b2f47c43a8a71c13be3a416bbf7 (diff)
Btrfs: Add ACL support
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r--fs/btrfs/acl.c296
-rw-r--r--fs/btrfs/btrfs_inode.h3
-rw-r--r--fs/btrfs/ctree.h7
-rw-r--r--fs/btrfs/inode.c42
-rw-r--r--fs/btrfs/super.c9
-rw-r--r--fs/btrfs/xattr.c26
6 files changed, 335 insertions, 48 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index ff0fcc72848a..b192659b4f5f 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -20,76 +20,302 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/xattr.h> 21#include <linux/xattr.h>
22#include <linux/posix_acl_xattr.h> 22#include <linux/posix_acl_xattr.h>
23#include <linux/posix_acl.h>
23#include <linux/sched.h> 24#include <linux/sched.h>
25
24#include "ctree.h" 26#include "ctree.h"
27#include "btrfs_inode.h"
25#include "xattr.h" 28#include "xattr.h"
26#ifndef is_owner_or_cap 29
27#define is_owner_or_cap(inode) \ 30static void btrfs_update_cached_acl(struct inode *inode,
28 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER)) 31 struct posix_acl **p_acl,
29#endif 32 struct posix_acl *acl)
33{
34 spin_lock(&inode->i_lock);
35 if (*p_acl && *p_acl != BTRFS_ACL_NOT_CACHED)
36 posix_acl_release(*p_acl);
37 *p_acl = posix_acl_dup(acl);
38 spin_unlock(&inode->i_lock);
39}
40
41static struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
42{
43 int size, name_index;
44 char *value = NULL;
45 struct posix_acl *acl = NULL, **p_acl;
46
47 switch (type) {
48 case ACL_TYPE_ACCESS:
49 name_index = BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS;
50 p_acl = &BTRFS_I(inode)->i_acl;
51 break;
52 case ACL_TYPE_DEFAULT:
53 name_index = BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT;
54 p_acl = &BTRFS_I(inode)->i_default_acl;
55 break;
56 default:
57 return ERR_PTR(-EINVAL);
58 }
59
60 spin_lock(&inode->i_lock);
61 if (*p_acl != BTRFS_ACL_NOT_CACHED)
62 acl = posix_acl_dup(*p_acl);
63 spin_unlock(&inode->i_lock);
64
65 if (acl)
66 return acl;
67
68
69 size = btrfs_xattr_get(inode, name_index, "", NULL, 0);
70 if (size > 0) {
71 value = kzalloc(size, GFP_NOFS);
72 if (!value)
73 return ERR_PTR(-ENOMEM);
74 size = btrfs_xattr_get(inode, name_index, "", value, size);
75 if (size > 0) {
76 acl = posix_acl_from_xattr(value, size);
77 btrfs_update_cached_acl(inode, p_acl, acl);
78 }
79 kfree(value);
80 } else if (size == -ENOENT) {
81 acl = NULL;
82 btrfs_update_cached_acl(inode, p_acl, acl);
83 }
84
85 return acl;
86}
87
88static int btrfs_xattr_get_acl(struct inode *inode, int type,
89 void *value, size_t size)
90{
91 struct posix_acl *acl;
92 int ret = 0;
93
94 acl = btrfs_get_acl(inode, type);
95
96 if (IS_ERR(acl))
97 return PTR_ERR(acl);
98 if (acl == NULL)
99 return -ENODATA;
100 ret = posix_acl_to_xattr(acl, value, size);
101 posix_acl_release(acl);
102
103 return ret;
104}
105
106/*
107 * Needs to be called with fs_mutex held
108 */
109static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
110{
111 int ret, name_index = 0, size = 0;
112 struct posix_acl **p_acl;
113 char *value = NULL;
114 mode_t mode;
115
116 if (acl) {
117 ret = posix_acl_valid(acl);
118 if (ret < 0)
119 return ret;
120 ret = 0;
121 }
122
123 switch (type) {
124 case ACL_TYPE_ACCESS:
125 mode = inode->i_mode;
126 ret = posix_acl_equiv_mode(acl, &mode);
127 if (ret < 0)
128 return ret;
129 ret = 0;
130 inode->i_mode = mode;
131 name_index = BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS;
132 p_acl = &BTRFS_I(inode)->i_acl;
133 break;
134 case ACL_TYPE_DEFAULT:
135 if (!S_ISDIR(inode->i_mode))
136 return acl ? -EINVAL : 0;
137 name_index = BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT;
138 p_acl = &BTRFS_I(inode)->i_default_acl;
139 break;
140 default:
141 return -EINVAL;
142 }
143
144 if (acl) {
145 size = posix_acl_xattr_size(acl->a_count);
146 value = kmalloc(size, GFP_NOFS);
147 if (!value) {
148 ret = -ENOMEM;
149 goto out;
150 }
151
152 ret = posix_acl_to_xattr(acl, value, size);
153 if (ret < 0)
154 goto out;
155 }
156
157 ret = btrfs_xattr_set(inode, name_index, "", value, size, 0);
158
159out:
160 if (value)
161 kfree(value);
162
163 if (!ret)
164 btrfs_update_cached_acl(inode, p_acl, acl);
165
166 return ret;
167}
30 168
31static int btrfs_xattr_set_acl(struct inode *inode, int type, 169static int btrfs_xattr_set_acl(struct inode *inode, int type,
32 const void *value, size_t size) 170 const void *value, size_t size)
33{ 171{
34 int ret = 0; 172 int ret = 0;
35 struct posix_acl *acl; 173 struct posix_acl *acl = NULL;
36 174
37 if (!is_owner_or_cap(inode))
38 return -EPERM;
39 if (value) { 175 if (value) {
40 acl = posix_acl_from_xattr(value, size); 176 acl = posix_acl_from_xattr(value, size);
41 if (acl == NULL) { 177 if (acl == NULL) {
42 value = NULL; 178 value = NULL;
43 size = 0; 179 size = 0;
44 } else if (IS_ERR(acl)) { 180 } else if (IS_ERR(acl)) {
45 ret = PTR_ERR(acl); 181 return PTR_ERR(acl);
46 } else {
47 ret = posix_acl_valid(acl);
48 posix_acl_release(acl);
49 } 182 }
50 if (ret)
51 return ret;
52 } 183 }
53 return btrfs_xattr_set(inode, type, "", value, size, 0);
54}
55 184
56static int btrfs_xattr_get_acl(struct inode *inode, int type, 185 ret = btrfs_set_acl(inode, acl, type);
57 void *value, size_t size) 186
58{ 187 posix_acl_release(acl);
59 return btrfs_xattr_get(inode, type, "", value, size); 188
189 return ret;
60} 190}
191
192
61static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name, 193static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name,
62 void *value, size_t size) 194 void *value, size_t size)
63{ 195{
64 if (*name != '\0') 196 return btrfs_xattr_get_acl(inode, ACL_TYPE_ACCESS, value, size);
65 return -EINVAL;
66 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
67 value, size);
68} 197}
198
69static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name, 199static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name,
70 const void *value, size_t size, int flags) 200 const void *value, size_t size, int flags)
71{ 201{
72 if (*name != '\0') 202 return btrfs_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
73 return -EINVAL;
74 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
75 value, size);
76} 203}
204
77static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name, 205static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name,
78 void *value, size_t size) 206 void *value, size_t size)
79{ 207{
80 if (*name != '\0') 208 return btrfs_xattr_get_acl(inode, ACL_TYPE_DEFAULT, value, size);
81 return -EINVAL;
82 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
83 value, size);
84} 209}
210
85static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name, 211static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name,
86 const void *value, size_t size, int flags) 212 const void *value, size_t size, int flags)
87{ 213{
88 if (*name != '\0') 214 return btrfs_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
89 return -EINVAL; 215}
90 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT, 216
91 value, size); 217int btrfs_check_acl(struct inode *inode, int mask)
218{
219 struct posix_acl *acl;
220 int error = -EAGAIN;
221
222 acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS);
223
224 if (IS_ERR(acl))
225 return PTR_ERR(acl);
226 if (acl) {
227 error = posix_acl_permission(inode, acl, mask);
228 posix_acl_release(acl);
229 }
230
231 return error;
232}
233
234/*
235 * btrfs_init_acl is already generally called under fs_mutex, so the locking
236 * stuff has been fixed to work with that. If the locking stuff changes, we
237 * need to re-evaluate the acl locking stuff.
238 */
239int btrfs_init_acl(struct inode *inode, struct inode *dir)
240{
241 struct posix_acl *acl = NULL;
242 int ret = 0;
243
244 /* this happens with subvols */
245 if (!dir)
246 return 0;
247
248 if (!S_ISLNK(inode->i_mode)) {
249 if (IS_POSIXACL(dir)) {
250 acl = btrfs_get_acl(dir, ACL_TYPE_DEFAULT);
251 if (IS_ERR(acl))
252 return PTR_ERR(acl);
253 }
254
255 if (!acl)
256 inode->i_mode &= ~current->fs->umask;
257 }
258
259 if (IS_POSIXACL(dir) && acl) {
260 struct posix_acl *clone;
261 mode_t mode;
262
263 if (S_ISDIR(inode->i_mode)) {
264 ret = btrfs_set_acl(inode, acl, ACL_TYPE_DEFAULT);
265 if (ret)
266 goto failed;
267 }
268 clone = posix_acl_clone(acl, GFP_NOFS);
269 ret = -ENOMEM;
270 if (!clone)
271 goto failed;
272
273 mode = inode->i_mode;
274 ret = posix_acl_create_masq(clone, &mode);
275 if (ret >= 0) {
276 inode->i_mode = mode;
277 if (ret > 0) {
278 /* we need an acl */
279 ret = btrfs_set_acl(inode, clone,
280 ACL_TYPE_ACCESS);
281 }
282 }
283 }
284failed:
285 posix_acl_release(acl);
286
287 return ret;
288}
289
290int btrfs_acl_chmod(struct inode *inode)
291{
292 struct posix_acl *acl, *clone;
293 int ret = 0;
294
295 if (S_ISLNK(inode->i_mode))
296 return -EOPNOTSUPP;
297
298 if (!IS_POSIXACL(inode))
299 return 0;
300
301 acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS);
302 if (IS_ERR(acl) || !acl)
303 return PTR_ERR(acl);
304
305 clone = posix_acl_clone(acl, GFP_KERNEL);
306 posix_acl_release(acl);
307 if (!clone)
308 return -ENOMEM;
309
310 ret = posix_acl_chmod_masq(clone, inode->i_mode);
311 if (!ret)
312 ret = btrfs_set_acl(inode, clone, ACL_TYPE_ACCESS);
313
314 posix_acl_release(clone);
315
316 return ret;
92} 317}
318
93struct xattr_handler btrfs_xattr_acl_default_handler = { 319struct xattr_handler btrfs_xattr_acl_default_handler = {
94 .prefix = POSIX_ACL_XATTR_DEFAULT, 320 .prefix = POSIX_ACL_XATTR_DEFAULT,
95 .list = btrfs_xattr_generic_list, 321 .list = btrfs_xattr_generic_list,
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index b7bd60e4fdd7..9f2a4ef944a7 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -36,6 +36,9 @@ struct btrfs_inode {
36 struct inode vfs_inode; 36 struct inode vfs_inode;
37 struct btrfs_ordered_inode_tree ordered_tree; 37 struct btrfs_ordered_inode_tree ordered_tree;
38 38
39 struct posix_acl *i_acl;
40 struct posix_acl *i_default_acl;
41
39 /* 42 /*
40 * transid of the trans_handle that last modified this inode 43 * transid of the trans_handle that last modified this inode
41 */ 44 */
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 53d315bdd16d..f87d7263f2d7 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -42,6 +42,8 @@ struct btrfs_ordered_sum;
42 42
43#define BTRFS_MAGIC "_B5RfS_M" 43#define BTRFS_MAGIC "_B5RfS_M"
44 44
45#define BTRFS_ACL_NOT_CACHED ((void *)-1)
46
45#ifdef CONFIG_LOCKDEP 47#ifdef CONFIG_LOCKDEP
46# define BTRFS_MAX_LEVEL 7 48# define BTRFS_MAX_LEVEL 7
47#else 49#else
@@ -1694,4 +1696,9 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
1694u64 btrfs_parse_size(char *str); 1696u64 btrfs_parse_size(char *str);
1695int btrfs_parse_options(struct btrfs_root *root, char *options); 1697int btrfs_parse_options(struct btrfs_root *root, char *options);
1696int btrfs_sync_fs(struct super_block *sb, int wait); 1698int btrfs_sync_fs(struct super_block *sb, int wait);
1699
1700/* acl.c */
1701int btrfs_check_acl(struct inode *inode, int mask);
1702int btrfs_init_acl(struct inode *inode, struct inode *dir);
1703int btrfs_acl_chmod(struct inode *inode);
1697#endif 1704#endif
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 8d371d6fe551..2d8853543a71 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -36,6 +36,7 @@
36#include <linux/bit_spinlock.h> 36#include <linux/bit_spinlock.h>
37#include <linux/version.h> 37#include <linux/version.h>
38#include <linux/xattr.h> 38#include <linux/xattr.h>
39#include <linux/posix_acl.h>
39#include "ctree.h" 40#include "ctree.h"
40#include "disk-io.h" 41#include "disk-io.h"
41#include "transaction.h" 42#include "transaction.h"
@@ -1478,6 +1479,9 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
1478 } 1479 }
1479out: 1480out:
1480 err = inode_setattr(inode, attr); 1481 err = inode_setattr(inode, attr);
1482
1483 if (!err && ((attr->ia_valid & ATTR_MODE)))
1484 err = btrfs_acl_chmod(inode);
1481fail: 1485fail:
1482 return err; 1486 return err;
1483} 1487}
@@ -2184,6 +2188,12 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
2184 if (IS_ERR(inode)) 2188 if (IS_ERR(inode))
2185 goto out_unlock; 2189 goto out_unlock;
2186 2190
2191 err = btrfs_init_acl(inode, dir);
2192 if (err) {
2193 drop_inode = 1;
2194 goto out_unlock;
2195 }
2196
2187 btrfs_set_trans_block_group(trans, inode); 2197 btrfs_set_trans_block_group(trans, inode);
2188 err = btrfs_add_nondir(trans, dentry, inode, 0); 2198 err = btrfs_add_nondir(trans, dentry, inode, 0);
2189 if (err) 2199 if (err)
@@ -2239,6 +2249,12 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
2239 if (IS_ERR(inode)) 2249 if (IS_ERR(inode))
2240 goto out_unlock; 2250 goto out_unlock;
2241 2251
2252 err = btrfs_init_acl(inode, dir);
2253 if (err) {
2254 drop_inode = 1;
2255 goto out_unlock;
2256 }
2257
2242 btrfs_set_trans_block_group(trans, inode); 2258 btrfs_set_trans_block_group(trans, inode);
2243 err = btrfs_add_nondir(trans, dentry, inode, 0); 2259 err = btrfs_add_nondir(trans, dentry, inode, 0);
2244 if (err) 2260 if (err)
@@ -2366,6 +2382,11 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
2366 } 2382 }
2367 2383
2368 drop_on_err = 1; 2384 drop_on_err = 1;
2385
2386 err = btrfs_init_acl(inode, dir);
2387 if (err)
2388 goto out_fail;
2389
2369 inode->i_op = &btrfs_dir_inode_operations; 2390 inode->i_op = &btrfs_dir_inode_operations;
2370 inode->i_fop = &btrfs_dir_file_operations; 2391 inode->i_fop = &btrfs_dir_file_operations;
2371 btrfs_set_trans_block_group(trans, inode); 2392 btrfs_set_trans_block_group(trans, inode);
@@ -3023,6 +3044,8 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
3023 return NULL; 3044 return NULL;
3024 ei->last_trans = 0; 3045 ei->last_trans = 0;
3025 btrfs_ordered_inode_tree_init(&ei->ordered_tree); 3046 btrfs_ordered_inode_tree_init(&ei->ordered_tree);
3047 ei->i_acl = BTRFS_ACL_NOT_CACHED;
3048 ei->i_default_acl = BTRFS_ACL_NOT_CACHED;
3026 return &ei->vfs_inode; 3049 return &ei->vfs_inode;
3027} 3050}
3028 3051
@@ -3032,6 +3055,13 @@ void btrfs_destroy_inode(struct inode *inode)
3032 WARN_ON(!list_empty(&inode->i_dentry)); 3055 WARN_ON(!list_empty(&inode->i_dentry));
3033 WARN_ON(inode->i_data.nrpages); 3056 WARN_ON(inode->i_data.nrpages);
3034 3057
3058 if (BTRFS_I(inode)->i_acl &&
3059 BTRFS_I(inode)->i_acl != BTRFS_ACL_NOT_CACHED)
3060 posix_acl_release(BTRFS_I(inode)->i_acl);
3061 if (BTRFS_I(inode)->i_default_acl &&
3062 BTRFS_I(inode)->i_default_acl != BTRFS_ACL_NOT_CACHED)
3063 posix_acl_release(BTRFS_I(inode)->i_default_acl);
3064
3035 while(1) { 3065 while(1) {
3036 ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); 3066 ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1);
3037 if (!ordered) 3067 if (!ordered)
@@ -3230,6 +3260,12 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
3230 if (IS_ERR(inode)) 3260 if (IS_ERR(inode))
3231 goto out_unlock; 3261 goto out_unlock;
3232 3262
3263 err = btrfs_init_acl(inode, dir);
3264 if (err) {
3265 drop_inode = 1;
3266 goto out_unlock;
3267 }
3268
3233 btrfs_set_trans_block_group(trans, inode); 3269 btrfs_set_trans_block_group(trans, inode);
3234 err = btrfs_add_nondir(trans, dentry, inode, 0); 3270 err = btrfs_add_nondir(trans, dentry, inode, 0);
3235 if (err) 3271 if (err)
@@ -3310,7 +3346,7 @@ static int btrfs_permission(struct inode *inode, int mask,
3310{ 3346{
3311 if (btrfs_test_flag(inode, READONLY) && (mask & MAY_WRITE)) 3347 if (btrfs_test_flag(inode, READONLY) && (mask & MAY_WRITE))
3312 return -EACCES; 3348 return -EACCES;
3313 return generic_permission(inode, mask, NULL); 3349 return generic_permission(inode, mask, btrfs_check_acl);
3314} 3350}
3315 3351
3316static struct inode_operations btrfs_dir_inode_operations = { 3352static struct inode_operations btrfs_dir_inode_operations = {
@@ -3392,6 +3428,10 @@ static struct inode_operations btrfs_special_inode_operations = {
3392 .getattr = btrfs_getattr, 3428 .getattr = btrfs_getattr,
3393 .setattr = btrfs_setattr, 3429 .setattr = btrfs_setattr,
3394 .permission = btrfs_permission, 3430 .permission = btrfs_permission,
3431 .setxattr = generic_setxattr,
3432 .getxattr = generic_getxattr,
3433 .listxattr = btrfs_listxattr,
3434 .removexattr = generic_removexattr,
3395}; 3435};
3396static struct inode_operations btrfs_symlink_inode_operations = { 3436static struct inode_operations btrfs_symlink_inode_operations = {
3397 .readlink = generic_readlink, 3437 .readlink = generic_readlink,
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 4cb6aac5122e..a6a418b6894b 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -68,7 +68,7 @@ static void btrfs_put_super (struct super_block * sb)
68enum { 68enum {
69 Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, 69 Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow,
70 Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, 70 Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
71 Opt_ssd, Opt_thread_pool, Opt_err, 71 Opt_ssd, Opt_thread_pool, Opt_noacl, Opt_err,
72}; 72};
73 73
74static match_table_t tokens = { 74static match_table_t tokens = {
@@ -83,7 +83,8 @@ static match_table_t tokens = {
83 {Opt_alloc_start, "alloc_start=%s"}, 83 {Opt_alloc_start, "alloc_start=%s"},
84 {Opt_thread_pool, "thread_pool=%d"}, 84 {Opt_thread_pool, "thread_pool=%d"},
85 {Opt_ssd, "ssd"}, 85 {Opt_ssd, "ssd"},
86 {Opt_err, NULL} 86 {Opt_noacl, "noacl"},
87 {Opt_err, NULL},
87}; 88};
88 89
89u64 btrfs_parse_size(char *str) 90u64 btrfs_parse_size(char *str)
@@ -215,6 +216,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
215 info->alloc_start); 216 info->alloc_start);
216 } 217 }
217 break; 218 break;
219 case Opt_noacl:
220 root->fs_info->sb->s_flags &= ~MS_POSIXACL;
221 break;
218 default: 222 default:
219 break; 223 break;
220 } 224 }
@@ -301,6 +305,7 @@ static int btrfs_fill_super(struct super_block * sb,
301 sb->s_op = &btrfs_super_ops; 305 sb->s_op = &btrfs_super_ops;
302 sb->s_xattr = btrfs_xattr_handlers; 306 sb->s_xattr = btrfs_xattr_handlers;
303 sb->s_time_gran = 1; 307 sb->s_time_gran = 1;
308 sb->s_flags |= MS_POSIXACL;
304 309
305 tree_root = open_ctree(sb, fs_devices, (char *)data); 310 tree_root = open_ctree(sb, fs_devices, (char *)data);
306 311
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index 6730b5958844..121c9550314f 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -26,25 +26,27 @@
26#include "transaction.h" 26#include "transaction.h"
27#include "xattr.h" 27#include "xattr.h"
28#include "disk-io.h" 28#include "disk-io.h"
29
29static struct xattr_handler *btrfs_xattr_handler_map[] = { 30static struct xattr_handler *btrfs_xattr_handler_map[] = {
30 [BTRFS_XATTR_INDEX_USER] = &btrfs_xattr_user_handler, 31 [BTRFS_XATTR_INDEX_USER] = &btrfs_xattr_user_handler,
31#ifdef CONFIG_FS_POSIX_ACL 32#ifdef CONFIG_FS_POSIX_ACL
32// [BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &btrfs_xattr_acl_access_handler, 33 [BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &btrfs_xattr_acl_access_handler,
33// [BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &btrfs_xattr_acl_default_handler, 34 [BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &btrfs_xattr_acl_default_handler,
34#endif 35#endif
35 [BTRFS_XATTR_INDEX_TRUSTED] = &btrfs_xattr_trusted_handler, 36 [BTRFS_XATTR_INDEX_TRUSTED] = &btrfs_xattr_trusted_handler,
36 [BTRFS_XATTR_INDEX_SECURITY] = &btrfs_xattr_security_handler, 37 [BTRFS_XATTR_INDEX_SECURITY] = &btrfs_xattr_security_handler,
37// [BTRFS_XATTR_INDEX_SYSTEM] = &btrfs_xattr_system_handler, 38 [BTRFS_XATTR_INDEX_SYSTEM] = &btrfs_xattr_system_handler,
38}; 39};
40
39struct xattr_handler *btrfs_xattr_handlers[] = { 41struct xattr_handler *btrfs_xattr_handlers[] = {
40 &btrfs_xattr_user_handler, 42 &btrfs_xattr_user_handler,
41#ifdef CONFIG_FS_POSIX_ACL 43#ifdef CONFIG_FS_POSIX_ACL
42// &btrfs_xattr_acl_access_handler, 44 &btrfs_xattr_acl_access_handler,
43// &btrfs_xattr_acl_default_handler, 45 &btrfs_xattr_acl_default_handler,
44#endif 46#endif
45 &btrfs_xattr_trusted_handler, 47 &btrfs_xattr_trusted_handler,
46 &btrfs_xattr_security_handler, 48 &btrfs_xattr_security_handler,
47// &btrfs_xattr_system_handler, 49 &btrfs_xattr_system_handler,
48 NULL, 50 NULL,
49}; 51};
50 52
@@ -237,10 +239,14 @@ int btrfs_xattr_set(struct inode *inode, int name_index,
237 mod = 1; 239 mod = 1;
238 goto out; 240 goto out;
239 } 241 }
240 } else if (flags & XATTR_REPLACE) { 242 } else {
241 /* we couldn't find the attr to replace, so error out */ 243 btrfs_release_path(root, path);
242 ret = -ENODATA; 244
243 goto out; 245 if (flags & XATTR_REPLACE) {
246 /* we couldn't find the attr to replace */
247 ret = -ENODATA;
248 goto out;
249 }
244 } 250 }
245 251
246 /* ok we have to create a completely new xattr */ 252 /* ok we have to create a completely new xattr */