Commit 2cc6a5a0 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Kleikamp <dave.kleikamp@oracle.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 2401dc29
...@@ -72,7 +72,7 @@ struct posix_acl *jfs_get_acl(struct inode *inode, int type) ...@@ -72,7 +72,7 @@ struct posix_acl *jfs_get_acl(struct inode *inode, int type)
return acl; return acl;
} }
static int jfs_set_acl(tid_t tid, struct inode *inode, int type, static int __jfs_set_acl(tid_t tid, struct inode *inode, int type,
struct posix_acl *acl) struct posix_acl *acl)
{ {
char *ea_name; char *ea_name;
...@@ -80,21 +80,22 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int type, ...@@ -80,21 +80,22 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int type,
int size = 0; int size = 0;
char *value = NULL; char *value = NULL;
if (S_ISLNK(inode->i_mode)) switch (type) {
return -EOPNOTSUPP;
switch(type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
ea_name = POSIX_ACL_XATTR_ACCESS; ea_name = POSIX_ACL_XATTR_ACCESS;
rc = posix_acl_equiv_mode(acl, &inode->i_mode);
if (rc < 0)
return rc;
if (rc == 0)
acl = NULL;
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
ea_name = POSIX_ACL_XATTR_DEFAULT; ea_name = POSIX_ACL_XATTR_DEFAULT;
if (!S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
if (acl) { if (acl) {
size = posix_acl_xattr_size(acl->a_count); size = posix_acl_xattr_size(acl->a_count);
value = kmalloc(size, GFP_KERNEL); value = kmalloc(size, GFP_KERNEL);
...@@ -114,65 +115,43 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int type, ...@@ -114,65 +115,43 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int type,
return rc; return rc;
} }
int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir) int jfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{
struct posix_acl *acl = NULL;
int rc = 0;
if (S_ISLNK(inode->i_mode))
return 0;
acl = jfs_get_acl(dir, ACL_TYPE_DEFAULT);
if (IS_ERR(acl))
return PTR_ERR(acl);
if (acl) {
if (S_ISDIR(inode->i_mode)) {
rc = jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, acl);
if (rc)
goto cleanup;
}
rc = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
if (rc < 0)
goto cleanup; /* posix_acl_release(NULL) is no-op */
if (rc > 0)
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
cleanup:
posix_acl_release(acl);
} else
inode->i_mode &= ~current_umask();
JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) |
inode->i_mode;
return rc;
}
int jfs_acl_chmod(struct inode *inode)
{ {
struct posix_acl *acl;
int rc; int rc;
tid_t tid; tid_t tid;
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = jfs_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (rc)
return rc;
tid = txBegin(inode->i_sb, 0); tid = txBegin(inode->i_sb, 0);
mutex_lock(&JFS_IP(inode)->commit_mutex); mutex_lock(&JFS_IP(inode)->commit_mutex);
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl); rc = __jfs_set_acl(tid, inode, type, acl);
if (!rc) if (!rc)
rc = txCommit(tid, 1, &inode, 0); rc = txCommit(tid, 1, &inode, 0);
txEnd(tid); txEnd(tid);
mutex_unlock(&JFS_IP(inode)->commit_mutex); mutex_unlock(&JFS_IP(inode)->commit_mutex);
return rc;
}
int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
{
struct posix_acl *default_acl, *acl;
int rc = 0;
rc = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
if (rc)
return rc;
if (default_acl) {
rc = __jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, default_acl);
posix_acl_release(default_acl);
}
if (acl) {
if (!rc)
rc = __jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl); posix_acl_release(acl);
}
JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) |
inode->i_mode;
return rc; return rc;
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/posix_acl.h>
#include <linux/quotaops.h> #include <linux/quotaops.h>
#include "jfs_incore.h" #include "jfs_incore.h"
#include "jfs_inode.h" #include "jfs_inode.h"
...@@ -131,7 +132,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -131,7 +132,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
mark_inode_dirty(inode); mark_inode_dirty(inode);
if (iattr->ia_valid & ATTR_MODE) if (iattr->ia_valid & ATTR_MODE)
rc = jfs_acl_chmod(inode); rc = posix_acl_chmod(inode, inode->i_mode);
return rc; return rc;
} }
...@@ -143,6 +144,7 @@ const struct inode_operations jfs_file_inode_operations = { ...@@ -143,6 +144,7 @@ const struct inode_operations jfs_file_inode_operations = {
.setattr = jfs_setattr, .setattr = jfs_setattr,
#ifdef CONFIG_JFS_POSIX_ACL #ifdef CONFIG_JFS_POSIX_ACL
.get_acl = jfs_get_acl, .get_acl = jfs_get_acl,
.set_acl = jfs_set_acl,
#endif #endif
}; };
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#ifdef CONFIG_JFS_POSIX_ACL #ifdef CONFIG_JFS_POSIX_ACL
struct posix_acl *jfs_get_acl(struct inode *inode, int type); struct posix_acl *jfs_get_acl(struct inode *inode, int type);
int jfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
int jfs_init_acl(tid_t, struct inode *, struct inode *); int jfs_init_acl(tid_t, struct inode *, struct inode *);
int jfs_acl_chmod(struct inode *inode);
#else #else
...@@ -32,10 +32,5 @@ static inline int jfs_init_acl(tid_t tid, struct inode *inode, ...@@ -32,10 +32,5 @@ static inline int jfs_init_acl(tid_t tid, struct inode *inode,
return 0; return 0;
} }
static inline int jfs_acl_chmod(struct inode *inode)
{
return 0;
}
#endif #endif
#endif /* _H_JFS_ACL */ #endif /* _H_JFS_ACL */
...@@ -61,6 +61,8 @@ extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t); ...@@ -61,6 +61,8 @@ extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
extern ssize_t jfs_listxattr(struct dentry *, char *, size_t); extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
extern int jfs_removexattr(struct dentry *, const char *); extern int jfs_removexattr(struct dentry *, const char *);
extern const struct xattr_handler *jfs_xattr_handlers[];
#ifdef CONFIG_JFS_SECURITY #ifdef CONFIG_JFS_SECURITY
extern int jfs_init_security(tid_t, struct inode *, struct inode *, extern int jfs_init_security(tid_t, struct inode *, struct inode *,
const struct qstr *); const struct qstr *);
......
...@@ -1524,6 +1524,7 @@ const struct inode_operations jfs_dir_inode_operations = { ...@@ -1524,6 +1524,7 @@ const struct inode_operations jfs_dir_inode_operations = {
.setattr = jfs_setattr, .setattr = jfs_setattr,
#ifdef CONFIG_JFS_POSIX_ACL #ifdef CONFIG_JFS_POSIX_ACL
.get_acl = jfs_get_acl, .get_acl = jfs_get_acl,
.set_acl = jfs_set_acl,
#endif #endif
}; };
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "jfs_imap.h" #include "jfs_imap.h"
#include "jfs_acl.h" #include "jfs_acl.h"
#include "jfs_debug.h" #include "jfs_debug.h"
#include "jfs_xattr.h"
MODULE_DESCRIPTION("The Journaled Filesystem (JFS)"); MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM"); 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) ...@@ -522,6 +523,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
*/ */
sb->s_op = &jfs_super_operations; sb->s_op = &jfs_super_operations;
sb->s_export_op = &jfs_export_operations; sb->s_export_op = &jfs_export_operations;
sb->s_xattr = jfs_xattr_handlers;
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
sb->dq_op = &dquot_operations; sb->dq_op = &dquot_operations;
sb->s_qcop = &dquot_quotactl_ops; sb->s_qcop = &dquot_quotactl_ops;
......
...@@ -665,82 +665,13 @@ static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf, ...@@ -665,82 +665,13 @@ static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
return 0; return 0;
} }
/*
* can_set_system_xattr
*
* This code is specific to the system.* namespace. It contains policy
* which doesn't belong in the main xattr codepath.
*/
static int can_set_system_xattr(struct inode *inode, const char *name,
const void *value, size_t value_len)
{
#ifdef CONFIG_JFS_POSIX_ACL
struct posix_acl *acl;
int rc;
if (!inode_owner_or_capable(inode))
return -EPERM;
/*
* POSIX_ACL_XATTR_ACCESS is tied to i_mode
*/
if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) {
acl = posix_acl_from_xattr(&init_user_ns, value, value_len);
if (IS_ERR(acl)) {
rc = PTR_ERR(acl);
printk(KERN_ERR "posix_acl_from_xattr returned %d\n",
rc);
return rc;
}
if (acl) {
rc = posix_acl_equiv_mode(acl, &inode->i_mode);
posix_acl_release(acl);
if (rc < 0) {
printk(KERN_ERR
"posix_acl_equiv_mode returned %d\n",
rc);
return rc;
}
mark_inode_dirty(inode);
}
/*
* We're changing the ACL. Get rid of the cached one
*/
forget_cached_acl(inode, ACL_TYPE_ACCESS);
return 0;
} else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) {
acl = posix_acl_from_xattr(&init_user_ns, value, value_len);
if (IS_ERR(acl)) {
rc = PTR_ERR(acl);
printk(KERN_ERR "posix_acl_from_xattr returned %d\n",
rc);
return rc;
}
posix_acl_release(acl);
/*
* We're changing the default ACL. Get rid of the cached one
*/
forget_cached_acl(inode, ACL_TYPE_DEFAULT);
return 0;
}
#endif /* CONFIG_JFS_POSIX_ACL */
return -EOPNOTSUPP;
}
/* /*
* Most of the permission checking is done by xattr_permission in the vfs. * Most of the permission checking is done by xattr_permission in the vfs.
* The local file system is responsible for handling the system.* namespace.
* We also need to verify that this is a namespace that we recognize. * We also need to verify that this is a namespace that we recognize.
*/ */
static int can_set_xattr(struct inode *inode, const char *name, static int can_set_xattr(struct inode *inode, const char *name,
const void *value, size_t value_len) const void *value, size_t value_len)
{ {
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
return can_set_system_xattr(inode, name, value, value_len);
if (!strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) { if (!strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) {
/* /*
* This makes sure that we aren't trying to set an * This makes sure that we aren't trying to set an
...@@ -913,6 +844,14 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value, ...@@ -913,6 +844,14 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
if ((rc = can_set_xattr(inode, name, value, value_len))) if ((rc = can_set_xattr(inode, name, value, value_len)))
return rc; return rc;
/*
* If this is a request for a synthetic attribute in the system.*
* namespace use the generic infrastructure to resolve a handler
* for it via sb->s_xattr.
*/
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
return generic_setxattr(dentry, name, value, value_len, flags);
if (value == NULL) { /* empty EA, do not remove */ if (value == NULL) { /* empty EA, do not remove */
value = ""; value = "";
value_len = 0; value_len = 0;
...@@ -986,6 +925,14 @@ ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data, ...@@ -986,6 +925,14 @@ ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
{ {
int err; int err;
/*
* If this is a request for a synthetic attribute in the system.*
* namespace use the generic infrastructure to resolve a handler
* for it via sb->s_xattr.
*/
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
return generic_getxattr(dentry, name, data, buf_size);
if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
/* /*
* skip past "os2." prefix * skip past "os2." prefix
...@@ -1077,6 +1024,14 @@ int jfs_removexattr(struct dentry *dentry, const char *name) ...@@ -1077,6 +1024,14 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
if ((rc = can_set_xattr(inode, name, NULL, 0))) if ((rc = can_set_xattr(inode, name, NULL, 0)))
return rc; return rc;
/*
* If this is a request for a synthetic attribute in the system.*
* namespace use the generic infrastructure to resolve a handler
* for it via sb->s_xattr.
*/
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
return generic_removexattr(dentry, name);
tid = txBegin(inode->i_sb, 0); tid = txBegin(inode->i_sb, 0);
mutex_lock(&ji->commit_mutex); mutex_lock(&ji->commit_mutex);
rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE); 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) ...@@ -1088,6 +1043,19 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
return rc; return rc;
} }
/*
* List of handlers for synthetic system.* attributes. All real ondisk
* attributes are handled directly.
*/
const struct xattr_handler *jfs_xattr_handlers[] = {
#ifdef JFS_POSIX_ACL
&posix_acl_access_xattr_handler,
&posix_acl_default_xattr_handler,
#endif
NULL,
};
#ifdef CONFIG_JFS_SECURITY #ifdef CONFIG_JFS_SECURITY
static int jfs_initxattrs(struct inode *inode, const struct xattr *xattr_array, static int jfs_initxattrs(struct inode *inode, const struct xattr *xattr_array,
void *fs_info) void *fs_info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment