Commit 48b32a35 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Linus Torvalds

reiserfs: use generic xattr handlers

Christoph Hellwig had asked me quite some time ago to port the reiserfs
xattrs to the generic xattr interface.

This patch replaces the reiserfs-specific xattr handling code with the
generic struct xattr_handler.

However, since reiserfs doesn't split the prefix and name when accessing
xattrs, it can't leverage generic_{set,get,list,remove}xattr without
needlessly reconstructing the name on the back end.

Update 7/26/07: Added missing dput() to deletion path.
Update 8/30/07: Added missing mark_inode_dirty when i_mode is used to
                represent an ACL and no previous ACL existed.
Signed-off-by: 's avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8ecbe550
......@@ -2263,9 +2263,6 @@ static int __init init_reiserfs_fs(void)
return ret;
}
if ((ret = reiserfs_xattr_register_handlers()))
goto failed_reiserfs_xattr_register_handlers;
reiserfs_proc_info_global_init();
reiserfs_proc_register_global("version",
reiserfs_global_version_in_proc);
......@@ -2276,9 +2273,6 @@ static int __init init_reiserfs_fs(void)
return 0;
}
reiserfs_xattr_unregister_handlers();
failed_reiserfs_xattr_register_handlers:
reiserfs_proc_unregister_global("version");
reiserfs_proc_info_global_done();
destroy_inodecache();
......@@ -2288,7 +2282,6 @@ static int __init init_reiserfs_fs(void)
static void __exit exit_reiserfs_fs(void)
{
reiserfs_xattr_unregister_handlers();
reiserfs_proc_unregister_global("version");
reiserfs_proc_info_global_done();
unregister_filesystem(&reiserfs_fs_type);
......
This diff is collapsed.
......@@ -271,7 +271,7 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
char *name;
void *value = NULL;
struct posix_acl **p_acl;
size_t size;
size_t size = 0;
int error;
struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
......@@ -308,16 +308,21 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
value = posix_acl_to_disk(acl, &size);
if (IS_ERR(value))
return (int)PTR_ERR(value);
error = reiserfs_xattr_set(inode, name, value, size, 0);
} else {
error = reiserfs_xattr_del(inode, name);
if (error == -ENODATA) {
/* This may seem odd here, but it means that the ACL was set
* with a value representable with mode bits. If there was
* an ACL before, reiserfs_xattr_del already dirtied the inode.
*/
}
error = __reiserfs_xattr_set(inode, name, value, size, 0);
/*
* Ensure that the inode gets dirtied if we're only using
* the mode bits and an old ACL didn't exist. We don't need
* to check if the inode is hashed here since we won't get
* called by reiserfs_inherit_default_acl().
*/
if (error == -ENODATA) {
error = 0;
if (type == ACL_TYPE_ACCESS) {
inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
error = 0;
}
}
......@@ -474,33 +479,22 @@ posix_acl_access_set(struct inode *inode, const char *name,
return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
}
static int posix_acl_access_del(struct inode *inode, const char *name)
{
struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
return -EINVAL;
iset_acl(inode, &reiserfs_i->i_acl_access, ERR_PTR(-ENODATA));
return 0;
}
static int
posix_acl_access_list(struct inode *inode, const char *name, int namelen,
char *out)
static size_t posix_acl_access_list(struct inode *inode, char *list,
size_t list_size, const char *name,
size_t name_len)
{
int len = namelen;
const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
if (!reiserfs_posixacl(inode->i_sb))
return 0;
if (out)
memcpy(out, name, len);
return len;
if (list && size <= list_size)
memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
return size;
}
struct reiserfs_xattr_handler posix_acl_access_handler = {
struct xattr_handler reiserfs_posix_acl_access_handler = {
.prefix = POSIX_ACL_XATTR_ACCESS,
.get = posix_acl_access_get,
.set = posix_acl_access_set,
.del = posix_acl_access_del,
.list = posix_acl_access_list,
};
......@@ -522,32 +516,21 @@ posix_acl_default_set(struct inode *inode, const char *name,
return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
}
static int posix_acl_default_del(struct inode *inode, const char *name)
static size_t posix_acl_default_list(struct inode *inode, char *list,
size_t list_size, const char *name,
size_t name_len)
{
struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
return -EINVAL;
iset_acl(inode, &reiserfs_i->i_acl_default, ERR_PTR(-ENODATA));
return 0;
}
static int
posix_acl_default_list(struct inode *inode, const char *name, int namelen,
char *out)
{
int len = namelen;
const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
if (!reiserfs_posixacl(inode->i_sb))
return 0;
if (out)
memcpy(out, name, len);
return len;
if (list && size <= list_size)
memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
return size;
}
struct reiserfs_xattr_handler posix_acl_default_handler = {
struct xattr_handler reiserfs_posix_acl_default_handler = {
.prefix = POSIX_ACL_XATTR_DEFAULT,
.get = posix_acl_default_get,
.set = posix_acl_default_set,
.del = posix_acl_default_del,
.list = posix_acl_default_list,
};
......@@ -31,35 +31,25 @@ security_set(struct inode *inode, const char *name, const void *buffer,
return reiserfs_xattr_set(inode, name, buffer, size, flags);
}
static int security_del(struct inode *inode, const char *name)
static size_t security_list(struct inode *inode, char *list, size_t list_len,
const char *name, size_t namelen)
{
if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
return -EINVAL;
if (IS_PRIVATE(inode))
return -EPERM;
return 0;
}
static int
security_list(struct inode *inode, const char *name, int namelen, char *out)
{
int len = namelen;
const size_t len = namelen + 1;
if (IS_PRIVATE(inode))
return 0;
if (out)
memcpy(out, name, len);
if (list && len <= list_len) {
memcpy(list, name, namelen);
list[namelen] = '\0';
}
return len;
}
struct reiserfs_xattr_handler security_handler = {
struct xattr_handler reiserfs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX,
.get = security_get,
.set = security_set,
.del = security_del,
.list = security_list,
};
......@@ -13,10 +13,7 @@ trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
return -EINVAL;
if (!reiserfs_xattrs(inode->i_sb))
return -EOPNOTSUPP;
if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
return -EPERM;
return reiserfs_xattr_get(inode, name, buffer, size);
......@@ -29,50 +26,30 @@ trusted_set(struct inode *inode, const char *name, const void *buffer,
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
return -EINVAL;
if (!reiserfs_xattrs(inode->i_sb))
return -EOPNOTSUPP;
if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
return -EPERM;
return reiserfs_xattr_set(inode, name, buffer, size, flags);
}
static int trusted_del(struct inode *inode, const char *name)
static size_t trusted_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len)
{
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
return -EINVAL;
const size_t len = name_len + 1;
if (!reiserfs_xattrs(inode->i_sb))
return -EOPNOTSUPP;
if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
return -EPERM;
return 0;
}
static int
trusted_list(struct inode *inode, const char *name, int namelen, char *out)
{
int len = namelen;
if (!reiserfs_xattrs(inode->i_sb))
if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
return 0;
if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
return 0;
if (out)
memcpy(out, name, len);
if (list && len <= list_size) {
memcpy(list, name, name_len);
list[name_len] = '\0';
}
return len;
}
struct reiserfs_xattr_handler trusted_handler = {
struct xattr_handler reiserfs_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX,
.get = trusted_get,
.set = trusted_set,
.del = trusted_del,
.list = trusted_list,
};
......@@ -6,10 +6,6 @@
#include <linux/reiserfs_xattr.h>
#include <asm/uaccess.h>
#ifdef CONFIG_REISERFS_FS_POSIX_ACL
# include <linux/reiserfs_acl.h>
#endif
static int
user_get(struct inode *inode, const char *name, void *buffer, size_t size)
{
......@@ -25,7 +21,6 @@ static int
user_set(struct inode *inode, const char *name, const void *buffer,
size_t size, int flags)
{
if (strlen(name) < sizeof(XATTR_USER_PREFIX))
return -EINVAL;
......@@ -34,33 +29,23 @@ user_set(struct inode *inode, const char *name, const void *buffer,
return reiserfs_xattr_set(inode, name, buffer, size, flags);
}
static int user_del(struct inode *inode, const char *name)
static size_t user_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len)
{
if (strlen(name) < sizeof(XATTR_USER_PREFIX))
return -EINVAL;
if (!reiserfs_xattrs_user(inode->i_sb))
return -EOPNOTSUPP;
return 0;
}
const size_t len = name_len + 1;
static int
user_list(struct inode *inode, const char *name, int namelen, char *out)
{
int len = namelen;
if (!reiserfs_xattrs_user(inode->i_sb))
return 0;
if (out)
memcpy(out, name, len);
if (list && len <= list_size) {
memcpy(list, name, name_len);
list[name_len] = '\0';
}
return len;
}
struct reiserfs_xattr_handler user_handler = {
struct xattr_handler reiserfs_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX,
.get = user_get,
.set = user_set,
.del = user_del,
.list = user_list,
};
......@@ -52,10 +52,8 @@ int reiserfs_acl_chmod(struct inode *inode);
int reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
struct inode *inode);
int reiserfs_cache_default_acl(struct inode *dir);
extern int reiserfs_xattr_posix_acl_init(void) __init;
extern int reiserfs_xattr_posix_acl_exit(void);
extern struct reiserfs_xattr_handler posix_acl_default_handler;
extern struct reiserfs_xattr_handler posix_acl_access_handler;
extern struct xattr_handler reiserfs_posix_acl_default_handler;
extern struct xattr_handler reiserfs_posix_acl_access_handler;
static inline void reiserfs_init_acl_access(struct inode *inode)
{
......@@ -75,16 +73,6 @@ static inline struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
return NULL;
}
static inline int reiserfs_xattr_posix_acl_init(void)
{
return 0;
}
static inline int reiserfs_xattr_posix_acl_exit(void)
{
return 0;
}
static inline int reiserfs_acl_chmod(struct inode *inode)
{
return 0;
......
......@@ -451,7 +451,6 @@ enum reiserfs_mount_options {
REISERFS_NO_UNHASHED_RELOCATION,
REISERFS_HASHED_RELOCATION,
REISERFS_ATTRS,
REISERFS_XATTRS,
REISERFS_XATTRS_USER,
REISERFS_POSIXACL,
REISERFS_BARRIER_NONE,
......@@ -489,7 +488,7 @@ enum reiserfs_mount_options {
#define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG))
#define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED))
#define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK))
#define reiserfs_xattrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS))
#define reiserfs_xattrs(s) ((s)->s_xattr != NULL)
#define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER))
#define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL))
#define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s))
......
......@@ -29,20 +29,6 @@ struct iattr;
struct super_block;
struct nameidata;
struct reiserfs_xattr_handler {
char *prefix;
int (*init) (void);
void (*exit) (void);
int (*get) (struct inode * inode, const char *name, void *buffer,
size_t size);
int (*set) (struct inode * inode, const char *name, const void *buffer,
size_t size, int flags);
int (*del) (struct inode * inode, const char *name);
int (*list) (struct inode * inode, const char *name, int namelen,
char *out);
struct list_head handlers;
};
int reiserfs_xattr_register_handlers(void) __init;
void reiserfs_xattr_unregister_handlers(void);
int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
......@@ -59,13 +45,14 @@ ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
int reiserfs_removexattr(struct dentry *dentry, const char *name);
int reiserfs_permission(struct inode *inode, int mask);
int reiserfs_xattr_del(struct inode *, const char *);
int reiserfs_xattr_get(const struct inode *, const char *, void *, size_t);
int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
int __reiserfs_xattr_set(struct inode *, const char *, const void *,
size_t, int);
int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
extern struct reiserfs_xattr_handler user_handler;
extern struct reiserfs_xattr_handler trusted_handler;
extern struct reiserfs_xattr_handler security_handler;
extern struct xattr_handler reiserfs_xattr_user_handler;
extern struct xattr_handler reiserfs_xattr_trusted_handler;
extern struct xattr_handler reiserfs_xattr_security_handler;
static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
{
......
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