Skip to content

Commit a6dda0e

Browse files
Christoph HellwigAl Viro
authored andcommitted
f2fs: use generic posix ACL infrastructure
f2fs has some weird mode bit handling, so still using the old chmod code for now. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jaegeuk Kim <jaegeuk.kim@samsung.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 64e178a commit a6dda0e

File tree

7 files changed

+31
-170
lines changed

7 files changed

+31
-170
lines changed

fs/f2fs/acl.c

Lines changed: 17 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include "xattr.h"
1818
#include "acl.h"
1919

20-
#define get_inode_mode(i) ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
21-
(F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
22-
2320
static inline size_t f2fs_acl_size(int count)
2421
{
2522
if (count <= 4) {
@@ -167,19 +164,11 @@ static void *f2fs_acl_to_disk(const struct posix_acl *acl, size_t *size)
167164

168165
struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
169166
{
170-
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
171167
int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
172168
void *value = NULL;
173169
struct posix_acl *acl;
174170
int retval;
175171

176-
if (!test_opt(sbi, POSIX_ACL))
177-
return NULL;
178-
179-
acl = get_cached_acl(inode, type);
180-
if (acl != ACL_NOT_CACHED)
181-
return acl;
182-
183172
if (type == ACL_TYPE_ACCESS)
184173
name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
185174

@@ -205,21 +194,15 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
205194
return acl;
206195
}
207196

208-
static int f2fs_set_acl(struct inode *inode, int type,
197+
static int __f2fs_set_acl(struct inode *inode, int type,
209198
struct posix_acl *acl, struct page *ipage)
210199
{
211-
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
212200
struct f2fs_inode_info *fi = F2FS_I(inode);
213201
int name_index;
214202
void *value = NULL;
215203
size_t size = 0;
216204
int error;
217205

218-
if (!test_opt(sbi, POSIX_ACL))
219-
return 0;
220-
if (S_ISLNK(inode->i_mode))
221-
return -EOPNOTSUPP;
222-
223206
switch (type) {
224207
case ACL_TYPE_ACCESS:
225208
name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -261,154 +244,31 @@ static int f2fs_set_acl(struct inode *inode, int type,
261244
return error;
262245
}
263246

264-
int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
247+
int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
265248
{
266-
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
267-
struct posix_acl *acl = NULL;
268-
int error = 0;
269-
270-
if (!S_ISLNK(inode->i_mode)) {
271-
if (test_opt(sbi, POSIX_ACL)) {
272-
acl = f2fs_get_acl(dir, ACL_TYPE_DEFAULT);
273-
if (IS_ERR(acl))
274-
return PTR_ERR(acl);
275-
}
276-
if (!acl)
277-
inode->i_mode &= ~current_umask();
278-
}
279-
280-
if (!test_opt(sbi, POSIX_ACL) || !acl)
281-
goto cleanup;
282-
283-
if (S_ISDIR(inode->i_mode)) {
284-
error = f2fs_set_acl(inode, ACL_TYPE_DEFAULT, acl, ipage);
285-
if (error)
286-
goto cleanup;
287-
}
288-
error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
289-
if (error < 0)
290-
return error;
291-
if (error > 0)
292-
error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, ipage);
293-
cleanup:
294-
posix_acl_release(acl);
295-
return error;
249+
return __f2fs_set_acl(inode, type, acl, NULL);
296250
}
297251

298-
int f2fs_acl_chmod(struct inode *inode)
252+
int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
299253
{
300-
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
301-
struct posix_acl *acl;
302-
int error;
303-
umode_t mode = get_inode_mode(inode);
304-
305-
if (!test_opt(sbi, POSIX_ACL))
306-
return 0;
307-
if (S_ISLNK(mode))
308-
return -EOPNOTSUPP;
309-
310-
acl = f2fs_get_acl(inode, ACL_TYPE_ACCESS);
311-
if (IS_ERR(acl) || !acl)
312-
return PTR_ERR(acl);
254+
struct posix_acl *default_acl, *acl;
255+
int error = 0;
313256

314-
error = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
257+
error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
315258
if (error)
316259
return error;
317260

318-
error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, NULL);
319-
posix_acl_release(acl);
320-
return error;
321-
}
322-
323-
static size_t f2fs_xattr_list_acl(struct dentry *dentry, char *list,
324-
size_t list_size, const char *name, size_t name_len, int type)
325-
{
326-
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
327-
const char *xname = POSIX_ACL_XATTR_DEFAULT;
328-
size_t size;
329-
330-
if (!test_opt(sbi, POSIX_ACL))
331-
return 0;
332-
333-
if (type == ACL_TYPE_ACCESS)
334-
xname = POSIX_ACL_XATTR_ACCESS;
335-
336-
size = strlen(xname) + 1;
337-
if (list && size <= list_size)
338-
memcpy(list, xname, size);
339-
return size;
340-
}
341-
342-
static int f2fs_xattr_get_acl(struct dentry *dentry, const char *name,
343-
void *buffer, size_t size, int type)
344-
{
345-
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
346-
struct posix_acl *acl;
347-
int error;
348-
349-
if (strcmp(name, "") != 0)
350-
return -EINVAL;
351-
if (!test_opt(sbi, POSIX_ACL))
352-
return -EOPNOTSUPP;
353-
354-
acl = f2fs_get_acl(dentry->d_inode, type);
355-
if (IS_ERR(acl))
356-
return PTR_ERR(acl);
357-
if (!acl)
358-
return -ENODATA;
359-
error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
360-
posix_acl_release(acl);
361-
362-
return error;
363-
}
364-
365-
static int f2fs_xattr_set_acl(struct dentry *dentry, const char *name,
366-
const void *value, size_t size, int flags, int type)
367-
{
368-
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
369-
struct inode *inode = dentry->d_inode;
370-
struct posix_acl *acl = NULL;
371-
int error;
372-
373-
if (strcmp(name, "") != 0)
374-
return -EINVAL;
375-
if (!test_opt(sbi, POSIX_ACL))
376-
return -EOPNOTSUPP;
377-
if (!inode_owner_or_capable(inode))
378-
return -EPERM;
379-
380-
if (value) {
381-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
382-
if (IS_ERR(acl))
383-
return PTR_ERR(acl);
384-
if (acl) {
385-
error = posix_acl_valid(acl);
386-
if (error)
387-
goto release_and_out;
388-
}
389-
} else {
390-
acl = NULL;
261+
if (default_acl) {
262+
error = __f2fs_set_acl(inode, ACL_TYPE_DEFAULT, default_acl,
263+
ipage);
264+
posix_acl_release(default_acl);
265+
}
266+
if (acl) {
267+
if (error)
268+
error = __f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl,
269+
ipage);
270+
posix_acl_release(acl);
391271
}
392272

393-
error = f2fs_set_acl(inode, type, acl, NULL);
394-
395-
release_and_out:
396-
posix_acl_release(acl);
397273
return error;
398274
}
399-
400-
const struct xattr_handler f2fs_xattr_acl_default_handler = {
401-
.prefix = POSIX_ACL_XATTR_DEFAULT,
402-
.flags = ACL_TYPE_DEFAULT,
403-
.list = f2fs_xattr_list_acl,
404-
.get = f2fs_xattr_get_acl,
405-
.set = f2fs_xattr_set_acl,
406-
};
407-
408-
const struct xattr_handler f2fs_xattr_acl_access_handler = {
409-
.prefix = POSIX_ACL_XATTR_ACCESS,
410-
.flags = ACL_TYPE_ACCESS,
411-
.list = f2fs_xattr_list_acl,
412-
.get = f2fs_xattr_get_acl,
413-
.set = f2fs_xattr_set_acl,
414-
};

fs/f2fs/acl.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,13 @@ struct f2fs_acl_header {
3737
#ifdef CONFIG_F2FS_FS_POSIX_ACL
3838

3939
extern struct posix_acl *f2fs_get_acl(struct inode *, int);
40-
extern int f2fs_acl_chmod(struct inode *);
40+
extern int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
4141
extern int f2fs_init_acl(struct inode *, struct inode *, struct page *);
4242
#else
4343
#define f2fs_check_acl NULL
4444
#define f2fs_get_acl NULL
4545
#define f2fs_set_acl NULL
4646

47-
static inline int f2fs_acl_chmod(struct inode *inode)
48-
{
49-
return 0;
50-
}
51-
5247
static inline int f2fs_init_acl(struct inode *inode, struct inode *dir,
5348
struct page *page)
5449
{

fs/f2fs/f2fs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ static inline int f2fs_readonly(struct super_block *sb)
953953
return sb->s_flags & MS_RDONLY;
954954
}
955955

956+
#define get_inode_mode(i) \
957+
((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
958+
(F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
959+
956960
/*
957961
* file.c
958962
*/

fs/f2fs/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
390390
__setattr_copy(inode, attr);
391391

392392
if (attr->ia_valid & ATTR_MODE) {
393-
err = f2fs_acl_chmod(inode);
393+
err = posix_acl_chmod(inode, get_inode_mode(inode));
394394
if (err || is_inode_flag_set(fi, FI_ACL_MODE)) {
395395
inode->i_mode = fi->i_acl_mode;
396396
clear_inode_flag(fi, FI_ACL_MODE);
@@ -405,6 +405,7 @@ const struct inode_operations f2fs_file_inode_operations = {
405405
.getattr = f2fs_getattr,
406406
.setattr = f2fs_setattr,
407407
.get_acl = f2fs_get_acl,
408+
.set_acl = f2fs_set_acl,
408409
#ifdef CONFIG_F2FS_FS_XATTR
409410
.setxattr = generic_setxattr,
410411
.getxattr = generic_getxattr,

fs/f2fs/namei.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ const struct inode_operations f2fs_dir_inode_operations = {
496496
.getattr = f2fs_getattr,
497497
.setattr = f2fs_setattr,
498498
.get_acl = f2fs_get_acl,
499+
.set_acl = f2fs_set_acl,
499500
#ifdef CONFIG_F2FS_FS_XATTR
500501
.setxattr = generic_setxattr,
501502
.getxattr = generic_getxattr,
@@ -522,6 +523,7 @@ const struct inode_operations f2fs_special_inode_operations = {
522523
.getattr = f2fs_getattr,
523524
.setattr = f2fs_setattr,
524525
.get_acl = f2fs_get_acl,
526+
.set_acl = f2fs_set_acl,
525527
#ifdef CONFIG_F2FS_FS_XATTR
526528
.setxattr = generic_setxattr,
527529
.getxattr = generic_getxattr,

fs/f2fs/xattr.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/rwsem.h>
2222
#include <linux/f2fs_fs.h>
2323
#include <linux/security.h>
24+
#include <linux/posix_acl_xattr.h>
2425
#include "f2fs.h"
2526
#include "xattr.h"
2627

@@ -216,8 +217,8 @@ const struct xattr_handler f2fs_xattr_security_handler = {
216217
static const struct xattr_handler *f2fs_xattr_handler_map[] = {
217218
[F2FS_XATTR_INDEX_USER] = &f2fs_xattr_user_handler,
218219
#ifdef CONFIG_F2FS_FS_POSIX_ACL
219-
[F2FS_XATTR_INDEX_POSIX_ACL_ACCESS] = &f2fs_xattr_acl_access_handler,
220-
[F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &f2fs_xattr_acl_default_handler,
220+
[F2FS_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,
221+
[F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &posix_acl_default_xattr_handler,
221222
#endif
222223
[F2FS_XATTR_INDEX_TRUSTED] = &f2fs_xattr_trusted_handler,
223224
#ifdef CONFIG_F2FS_FS_SECURITY
@@ -229,8 +230,8 @@ static const struct xattr_handler *f2fs_xattr_handler_map[] = {
229230
const struct xattr_handler *f2fs_xattr_handlers[] = {
230231
&f2fs_xattr_user_handler,
231232
#ifdef CONFIG_F2FS_FS_POSIX_ACL
232-
&f2fs_xattr_acl_access_handler,
233-
&f2fs_xattr_acl_default_handler,
233+
&posix_acl_access_xattr_handler,
234+
&posix_acl_default_xattr_handler,
234235
#endif
235236
&f2fs_xattr_trusted_handler,
236237
#ifdef CONFIG_F2FS_FS_SECURITY

fs/f2fs/xattr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ struct f2fs_xattr_entry {
108108
#ifdef CONFIG_F2FS_FS_XATTR
109109
extern const struct xattr_handler f2fs_xattr_user_handler;
110110
extern const struct xattr_handler f2fs_xattr_trusted_handler;
111-
extern const struct xattr_handler f2fs_xattr_acl_access_handler;
112-
extern const struct xattr_handler f2fs_xattr_acl_default_handler;
113111
extern const struct xattr_handler f2fs_xattr_advise_handler;
114112
extern const struct xattr_handler f2fs_xattr_security_handler;
115113

0 commit comments

Comments
 (0)