Skip to content

Commit 2cc6a5a

Browse files
Christoph HellwigAl Viro
authored andcommitted
jfs: use generic posix ACL infrastructure
Copy the scheme I introduced to btrfs many years ago to only use the xattr handler for ACLs, but pass plain attrs straight through. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Kleikamp <dave.kleikamp@oracle.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 2401dc2 commit 2cc6a5a

File tree

7 files changed

+89
-140
lines changed

7 files changed

+89
-140
lines changed

fs/jfs/acl.c

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,30 @@ struct posix_acl *jfs_get_acl(struct inode *inode, int type)
7272
return acl;
7373
}
7474

75-
static int jfs_set_acl(tid_t tid, struct inode *inode, int type,
75+
static int __jfs_set_acl(tid_t tid, struct inode *inode, int type,
7676
struct posix_acl *acl)
7777
{
7878
char *ea_name;
7979
int rc;
8080
int size = 0;
8181
char *value = NULL;
8282

83-
if (S_ISLNK(inode->i_mode))
84-
return -EOPNOTSUPP;
85-
86-
switch(type) {
87-
case ACL_TYPE_ACCESS:
88-
ea_name = POSIX_ACL_XATTR_ACCESS;
89-
break;
90-
case ACL_TYPE_DEFAULT:
91-
ea_name = POSIX_ACL_XATTR_DEFAULT;
92-
if (!S_ISDIR(inode->i_mode))
93-
return acl ? -EACCES : 0;
94-
break;
95-
default:
96-
return -EINVAL;
83+
switch (type) {
84+
case ACL_TYPE_ACCESS:
85+
ea_name = POSIX_ACL_XATTR_ACCESS;
86+
rc = posix_acl_equiv_mode(acl, &inode->i_mode);
87+
if (rc < 0)
88+
return rc;
89+
if (rc == 0)
90+
acl = NULL;
91+
break;
92+
case ACL_TYPE_DEFAULT:
93+
ea_name = POSIX_ACL_XATTR_DEFAULT;
94+
break;
95+
default:
96+
return -EINVAL;
9797
}
98+
9899
if (acl) {
99100
size = posix_acl_xattr_size(acl->a_count);
100101
value = kmalloc(size, GFP_KERNEL);
@@ -114,65 +115,43 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int type,
114115
return rc;
115116
}
116117

118+
int jfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
119+
{
120+
int rc;
121+
tid_t tid;
122+
123+
tid = txBegin(inode->i_sb, 0);
124+
mutex_lock(&JFS_IP(inode)->commit_mutex);
125+
rc = __jfs_set_acl(tid, inode, type, acl);
126+
if (!rc)
127+
rc = txCommit(tid, 1, &inode, 0);
128+
txEnd(tid);
129+
mutex_unlock(&JFS_IP(inode)->commit_mutex);
130+
return rc;
131+
}
132+
117133
int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
118134
{
119-
struct posix_acl *acl = NULL;
135+
struct posix_acl *default_acl, *acl;
120136
int rc = 0;
121137

122-
if (S_ISLNK(inode->i_mode))
123-
return 0;
138+
rc = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
139+
if (rc)
140+
return rc;
124141

125-
acl = jfs_get_acl(dir, ACL_TYPE_DEFAULT);
126-
if (IS_ERR(acl))
127-
return PTR_ERR(acl);
142+
if (default_acl) {
143+
rc = __jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, default_acl);
144+
posix_acl_release(default_acl);
145+
}
128146

129147
if (acl) {
130-
if (S_ISDIR(inode->i_mode)) {
131-
rc = jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, acl);
132-
if (rc)
133-
goto cleanup;
134-
}
135-
rc = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
136-
if (rc < 0)
137-
goto cleanup; /* posix_acl_release(NULL) is no-op */
138-
if (rc > 0)
139-
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
140-
cleanup:
148+
if (!rc)
149+
rc = __jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
141150
posix_acl_release(acl);
142-
} else
143-
inode->i_mode &= ~current_umask();
151+
}
144152

145153
JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) |
146154
inode->i_mode;
147155

148156
return rc;
149157
}
150-
151-
int jfs_acl_chmod(struct inode *inode)
152-
{
153-
struct posix_acl *acl;
154-
int rc;
155-
tid_t tid;
156-
157-
if (S_ISLNK(inode->i_mode))
158-
return -EOPNOTSUPP;
159-
160-
acl = jfs_get_acl(inode, ACL_TYPE_ACCESS);
161-
if (IS_ERR(acl) || !acl)
162-
return PTR_ERR(acl);
163-
164-
rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
165-
if (rc)
166-
return rc;
167-
168-
tid = txBegin(inode->i_sb, 0);
169-
mutex_lock(&JFS_IP(inode)->commit_mutex);
170-
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
171-
if (!rc)
172-
rc = txCommit(tid, 1, &inode, 0);
173-
txEnd(tid);
174-
mutex_unlock(&JFS_IP(inode)->commit_mutex);
175-
176-
posix_acl_release(acl);
177-
return rc;
178-
}

fs/jfs/file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/mm.h>
2121
#include <linux/fs.h>
22+
#include <linux/posix_acl.h>
2223
#include <linux/quotaops.h>
2324
#include "jfs_incore.h"
2425
#include "jfs_inode.h"
@@ -131,7 +132,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
131132
mark_inode_dirty(inode);
132133

133134
if (iattr->ia_valid & ATTR_MODE)
134-
rc = jfs_acl_chmod(inode);
135+
rc = posix_acl_chmod(inode, inode->i_mode);
135136
return rc;
136137
}
137138

@@ -143,6 +144,7 @@ const struct inode_operations jfs_file_inode_operations = {
143144
.setattr = jfs_setattr,
144145
#ifdef CONFIG_JFS_POSIX_ACL
145146
.get_acl = jfs_get_acl,
147+
.set_acl = jfs_set_acl,
146148
#endif
147149
};
148150

fs/jfs/jfs_acl.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#ifdef CONFIG_JFS_POSIX_ACL
2222

2323
struct posix_acl *jfs_get_acl(struct inode *inode, int type);
24+
int jfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
2425
int jfs_init_acl(tid_t, struct inode *, struct inode *);
25-
int jfs_acl_chmod(struct inode *inode);
2626

2727
#else
2828

@@ -32,10 +32,5 @@ static inline int jfs_init_acl(tid_t tid, struct inode *inode,
3232
return 0;
3333
}
3434

35-
static inline int jfs_acl_chmod(struct inode *inode)
36-
{
37-
return 0;
38-
}
39-
4035
#endif
4136
#endif /* _H_JFS_ACL */

fs/jfs/jfs_xattr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
6161
extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
6262
extern int jfs_removexattr(struct dentry *, const char *);
6363

64+
extern const struct xattr_handler *jfs_xattr_handlers[];
65+
6466
#ifdef CONFIG_JFS_SECURITY
6567
extern int jfs_init_security(tid_t, struct inode *, struct inode *,
6668
const struct qstr *);

fs/jfs/namei.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,7 @@ const struct inode_operations jfs_dir_inode_operations = {
15241524
.setattr = jfs_setattr,
15251525
#ifdef CONFIG_JFS_POSIX_ACL
15261526
.get_acl = jfs_get_acl,
1527+
.set_acl = jfs_set_acl,
15271528
#endif
15281529
};
15291530

fs/jfs/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "jfs_imap.h"
4545
#include "jfs_acl.h"
4646
#include "jfs_debug.h"
47+
#include "jfs_xattr.h"
4748

4849
MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
4950
MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
@@ -522,6 +523,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
522523
*/
523524
sb->s_op = &jfs_super_operations;
524525
sb->s_export_op = &jfs_export_operations;
526+
sb->s_xattr = jfs_xattr_handlers;
525527
#ifdef CONFIG_QUOTA
526528
sb->dq_op = &dquot_operations;
527529
sb->s_qcop = &dquot_quotactl_ops;

fs/jfs/xattr.c

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -665,90 +665,21 @@ static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
665665
return 0;
666666
}
667667

668-
/*
669-
* can_set_system_xattr
670-
*
671-
* This code is specific to the system.* namespace. It contains policy
672-
* which doesn't belong in the main xattr codepath.
673-
*/
674-
static int can_set_system_xattr(struct inode *inode, const char *name,
675-
const void *value, size_t value_len)
676-
{
677-
#ifdef CONFIG_JFS_POSIX_ACL
678-
struct posix_acl *acl;
679-
int rc;
680-
681-
if (!inode_owner_or_capable(inode))
682-
return -EPERM;
683-
684-
/*
685-
* POSIX_ACL_XATTR_ACCESS is tied to i_mode
686-
*/
687-
if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) {
688-
acl = posix_acl_from_xattr(&init_user_ns, value, value_len);
689-
if (IS_ERR(acl)) {
690-
rc = PTR_ERR(acl);
691-
printk(KERN_ERR "posix_acl_from_xattr returned %d\n",
692-
rc);
693-
return rc;
694-
}
695-
if (acl) {
696-
rc = posix_acl_equiv_mode(acl, &inode->i_mode);
697-
posix_acl_release(acl);
698-
if (rc < 0) {
699-
printk(KERN_ERR
700-
"posix_acl_equiv_mode returned %d\n",
701-
rc);
702-
return rc;
703-
}
704-
mark_inode_dirty(inode);
705-
}
706-
/*
707-
* We're changing the ACL. Get rid of the cached one
708-
*/
709-
forget_cached_acl(inode, ACL_TYPE_ACCESS);
710-
711-
return 0;
712-
} else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) {
713-
acl = posix_acl_from_xattr(&init_user_ns, value, value_len);
714-
if (IS_ERR(acl)) {
715-
rc = PTR_ERR(acl);
716-
printk(KERN_ERR "posix_acl_from_xattr returned %d\n",
717-
rc);
718-
return rc;
719-
}
720-
posix_acl_release(acl);
721-
722-
/*
723-
* We're changing the default ACL. Get rid of the cached one
724-
*/
725-
forget_cached_acl(inode, ACL_TYPE_DEFAULT);
726-
727-
return 0;
728-
}
729-
#endif /* CONFIG_JFS_POSIX_ACL */
730-
return -EOPNOTSUPP;
731-
}
732-
733668
/*
734669
* Most of the permission checking is done by xattr_permission in the vfs.
735-
* The local file system is responsible for handling the system.* namespace.
736670
* We also need to verify that this is a namespace that we recognize.
737671
*/
738672
static int can_set_xattr(struct inode *inode, const char *name,
739673
const void *value, size_t value_len)
740674
{
741-
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
742-
return can_set_system_xattr(inode, name, value, value_len);
743-
744675
if (!strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) {
745676
/*
746677
* This makes sure that we aren't trying to set an
747678
* attribute in a different namespace by prefixing it
748679
* with "os2."
749680
*/
750681
if (is_known_namespace(name + XATTR_OS2_PREFIX_LEN))
751-
return -EOPNOTSUPP;
682+
return -EOPNOTSUPP;
752683
return 0;
753684
}
754685

@@ -913,6 +844,14 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
913844
if ((rc = can_set_xattr(inode, name, value, value_len)))
914845
return rc;
915846

847+
/*
848+
* If this is a request for a synthetic attribute in the system.*
849+
* namespace use the generic infrastructure to resolve a handler
850+
* for it via sb->s_xattr.
851+
*/
852+
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
853+
return generic_setxattr(dentry, name, value, value_len, flags);
854+
916855
if (value == NULL) { /* empty EA, do not remove */
917856
value = "";
918857
value_len = 0;
@@ -986,6 +925,14 @@ ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
986925
{
987926
int err;
988927

928+
/*
929+
* If this is a request for a synthetic attribute in the system.*
930+
* namespace use the generic infrastructure to resolve a handler
931+
* for it via sb->s_xattr.
932+
*/
933+
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
934+
return generic_getxattr(dentry, name, data, buf_size);
935+
989936
if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
990937
/*
991938
* skip past "os2." prefix
@@ -1077,6 +1024,14 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
10771024
if ((rc = can_set_xattr(inode, name, NULL, 0)))
10781025
return rc;
10791026

1027+
/*
1028+
* If this is a request for a synthetic attribute in the system.*
1029+
* namespace use the generic infrastructure to resolve a handler
1030+
* for it via sb->s_xattr.
1031+
*/
1032+
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
1033+
return generic_removexattr(dentry, name);
1034+
10801035
tid = txBegin(inode->i_sb, 0);
10811036
mutex_lock(&ji->commit_mutex);
10821037
rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE);
@@ -1088,6 +1043,19 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
10881043
return rc;
10891044
}
10901045

1046+
/*
1047+
* List of handlers for synthetic system.* attributes. All real ondisk
1048+
* attributes are handled directly.
1049+
*/
1050+
const struct xattr_handler *jfs_xattr_handlers[] = {
1051+
#ifdef JFS_POSIX_ACL
1052+
&posix_acl_access_xattr_handler,
1053+
&posix_acl_default_xattr_handler,
1054+
#endif
1055+
NULL,
1056+
};
1057+
1058+
10911059
#ifdef CONFIG_JFS_SECURITY
10921060
static int jfs_initxattrs(struct inode *inode, const struct xattr *xattr_array,
10931061
void *fs_info)

0 commit comments

Comments
 (0)