gfs2: Switch to generic xattr handlers
Switch to the generic xattr handlers and take the necessary glocks at the layer below. The following are the new xattr "entry points"; they are called with the glock held already in the following cases: gfs2_xattr_get: From SELinux, during lookups. gfs2_xattr_set: The glock is never held. gfs2_get_acl: From gfs2_create_inode -> posix_acl_create and gfs2_setattr -> posix_acl_chmod. gfs2_set_acl: From gfs2_setattr -> posix_acl_chmod. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
b971e94e8f
commit
1a39ba99b5
4 changed files with 99 additions and 88 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "glock.h"
|
||||
#include "inode.h"
|
||||
#include "meta_io.h"
|
||||
#include "rgrp.h"
|
||||
#include "trans.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -38,7 +39,7 @@ static const char *gfs2_acl_name(int type)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
||||
static struct posix_acl *__gfs2_get_acl(struct inode *inode, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct posix_acl *acl;
|
||||
|
@ -50,29 +51,41 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
|||
return NULL;
|
||||
|
||||
name = gfs2_acl_name(type);
|
||||
if (name == NULL)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
len = gfs2_xattr_acl_get(ip, name, &data);
|
||||
if (len < 0)
|
||||
if (len <= 0)
|
||||
return ERR_PTR(len);
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
|
||||
acl = posix_acl_from_xattr(&init_user_ns, data, len);
|
||||
kfree(data);
|
||||
return acl;
|
||||
}
|
||||
|
||||
int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
bool need_unlock = false;
|
||||
struct posix_acl *acl;
|
||||
|
||||
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
|
||||
int ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
|
||||
LM_FLAG_ANY, &gh);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
need_unlock = true;
|
||||
}
|
||||
acl = __gfs2_get_acl(inode, type);
|
||||
if (need_unlock)
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return acl;
|
||||
}
|
||||
|
||||
int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
int error;
|
||||
int len;
|
||||
char *data;
|
||||
const char *name = gfs2_acl_name(type);
|
||||
|
||||
BUG_ON(name == NULL);
|
||||
|
||||
if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode)))
|
||||
return -E2BIG;
|
||||
|
||||
|
@ -115,3 +128,26 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
|||
kfree(data);
|
||||
return error;
|
||||
}
|
||||
|
||||
int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
bool need_unlock = false;
|
||||
int ret;
|
||||
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
if (ret)
|
||||
return ret;
|
||||
need_unlock = true;
|
||||
}
|
||||
ret = __gfs2_set_acl(inode, acl, type);
|
||||
if (need_unlock)
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define GFS2_ACL_MAX_ENTRIES(sdp) ((300 << (sdp)->sd_sb.sb_bsize_shift) >> 12)
|
||||
|
||||
extern struct posix_acl *gfs2_get_acl(struct inode *inode, int type);
|
||||
extern int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
extern int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
|
||||
#endif /* __ACL_DOT_H__ */
|
||||
|
|
|
@ -692,12 +692,12 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
|
|||
considered free. Any failures need to undo
|
||||
the gfs2 structures. */
|
||||
if (default_acl) {
|
||||
error = gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
|
||||
error = __gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
|
||||
posix_acl_release(default_acl);
|
||||
}
|
||||
if (acl) {
|
||||
if (!error)
|
||||
error = gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
|
||||
error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
|
||||
posix_acl_release(acl);
|
||||
}
|
||||
|
||||
|
@ -1948,66 +1948,6 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int gfs2_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *data, size_t size, int flags)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
ret = gfs2_glock_nq(&gh);
|
||||
if (ret == 0) {
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret == 0)
|
||||
ret = generic_setxattr(dentry, name, data, size, flags);
|
||||
gfs2_glock_dq(&gh);
|
||||
}
|
||||
gfs2_holder_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t gfs2_getxattr(struct dentry *dentry, struct inode *inode,
|
||||
const char *name, void *data, size_t size)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
/* For selinux during lookup */
|
||||
if (gfs2_glock_is_locked_by_me(ip->i_gl))
|
||||
return generic_getxattr(dentry, inode, name, data, size);
|
||||
|
||||
gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
|
||||
ret = gfs2_glock_nq(&gh);
|
||||
if (ret == 0) {
|
||||
ret = generic_getxattr(dentry, inode, name, data, size);
|
||||
gfs2_glock_dq(&gh);
|
||||
}
|
||||
gfs2_holder_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int gfs2_removexattr(struct dentry *dentry, const char *name)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
ret = gfs2_glock_nq(&gh);
|
||||
if (ret == 0) {
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret == 0)
|
||||
ret = generic_removexattr(dentry, name);
|
||||
gfs2_glock_dq(&gh);
|
||||
}
|
||||
gfs2_holder_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
||||
u64 start, u64 len)
|
||||
{
|
||||
|
@ -2054,10 +1994,10 @@ const struct inode_operations gfs2_file_iops = {
|
|||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
.getattr = gfs2_getattr,
|
||||
.setxattr = gfs2_setxattr,
|
||||
.getxattr = gfs2_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = gfs2_listxattr,
|
||||
.removexattr = gfs2_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.fiemap = gfs2_fiemap,
|
||||
.get_acl = gfs2_get_acl,
|
||||
.set_acl = gfs2_set_acl,
|
||||
|
@ -2076,10 +2016,10 @@ const struct inode_operations gfs2_dir_iops = {
|
|||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
.getattr = gfs2_getattr,
|
||||
.setxattr = gfs2_setxattr,
|
||||
.getxattr = gfs2_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = gfs2_listxattr,
|
||||
.removexattr = gfs2_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.fiemap = gfs2_fiemap,
|
||||
.get_acl = gfs2_get_acl,
|
||||
.set_acl = gfs2_set_acl,
|
||||
|
@ -2092,10 +2032,10 @@ const struct inode_operations gfs2_symlink_iops = {
|
|||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
.getattr = gfs2_getattr,
|
||||
.setxattr = gfs2_setxattr,
|
||||
.getxattr = gfs2_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = gfs2_listxattr,
|
||||
.removexattr = gfs2_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.fiemap = gfs2_fiemap,
|
||||
};
|
||||
|
||||
|
|
|
@ -583,13 +583,11 @@ int gfs2_xattr_acl_get(struct gfs2_inode *ip, const char *name, char **ppdata)
|
|||
*
|
||||
* Returns: actual size of data on success, -errno on error
|
||||
*/
|
||||
static int gfs2_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *unused, struct inode *inode,
|
||||
const char *name, void *buffer, size_t size)
|
||||
static int __gfs2_xattr_get(struct inode *inode, const char *name,
|
||||
void *buffer, size_t size, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_ea_location el;
|
||||
int type = handler->flags;
|
||||
int error;
|
||||
|
||||
if (!ip->i_eattr)
|
||||
|
@ -611,6 +609,29 @@ static int gfs2_xattr_get(const struct xattr_handler *handler,
|
|||
return error;
|
||||
}
|
||||
|
||||
static int gfs2_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *unused, struct inode *inode,
|
||||
const char *name, void *buffer, size_t size)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
bool need_unlock = false;
|
||||
int ret;
|
||||
|
||||
/* During lookup, SELinux calls this function with the glock locked. */
|
||||
|
||||
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
|
||||
if (ret)
|
||||
return ret;
|
||||
need_unlock = true;
|
||||
}
|
||||
ret = __gfs2_xattr_get(inode, name, buffer, size, handler->flags);
|
||||
if (need_unlock)
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ea_alloc_blk - allocates a new block for extended attributes.
|
||||
* @ip: A pointer to the inode that's getting extended attributes
|
||||
|
@ -1233,8 +1254,21 @@ static int gfs2_xattr_set(const struct xattr_handler *handler,
|
|||
struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags)
|
||||
{
|
||||
return __gfs2_xattr_set(d_inode(dentry), name, value,
|
||||
size, flags, handler->flags);
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = __gfs2_xattr_set(inode, name, value, size, flags, handler->flags);
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ea_dealloc_indirect(struct gfs2_inode *ip)
|
||||
|
|
Loading…
Reference in a new issue