Commit 1a39ba99 authored by Al Viro's avatar Al Viro

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: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent b971e94e
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "glock.h" #include "glock.h"
#include "inode.h" #include "inode.h"
#include "meta_io.h" #include "meta_io.h"
#include "rgrp.h"
#include "trans.h" #include "trans.h"
#include "util.h" #include "util.h"
...@@ -38,7 +39,7 @@ static const char *gfs2_acl_name(int type) ...@@ -38,7 +39,7 @@ static const char *gfs2_acl_name(int type)
return NULL; 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 gfs2_inode *ip = GFS2_I(inode);
struct posix_acl *acl; struct posix_acl *acl;
...@@ -50,29 +51,41 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type) ...@@ -50,29 +51,41 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
return NULL; return NULL;
name = gfs2_acl_name(type); name = gfs2_acl_name(type);
if (name == NULL)
return ERR_PTR(-EINVAL);
len = gfs2_xattr_acl_get(ip, name, &data); len = gfs2_xattr_acl_get(ip, name, &data);
if (len < 0) if (len <= 0)
return ERR_PTR(len); return ERR_PTR(len);
if (len == 0)
return NULL;
acl = posix_acl_from_xattr(&init_user_ns, data, len); acl = posix_acl_from_xattr(&init_user_ns, data, len);
kfree(data); kfree(data);
return acl; 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 error;
int len; int len;
char *data; char *data;
const char *name = gfs2_acl_name(type); const char *name = gfs2_acl_name(type);
BUG_ON(name == NULL);
if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode))) if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode)))
return -E2BIG; return -E2BIG;
...@@ -115,3 +128,26 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type) ...@@ -115,3 +128,26 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
kfree(data); kfree(data);
return error; 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 @@ ...@@ -15,6 +15,7 @@
#define GFS2_ACL_MAX_ENTRIES(sdp) ((300 << (sdp)->sd_sb.sb_bsize_shift) >> 12) #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 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); extern int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
#endif /* __ACL_DOT_H__ */ #endif /* __ACL_DOT_H__ */
...@@ -692,12 +692,12 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, ...@@ -692,12 +692,12 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
considered free. Any failures need to undo considered free. Any failures need to undo
the gfs2 structures. */ the gfs2 structures. */
if (default_acl) { 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); posix_acl_release(default_acl);
} }
if (acl) { if (acl) {
if (!error) if (!error)
error = gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS); error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
posix_acl_release(acl); posix_acl_release(acl);
} }
...@@ -1948,66 +1948,6 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -1948,66 +1948,6 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
return 0; 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, static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
u64 start, u64 len) u64 start, u64 len)
{ {
...@@ -2054,10 +1994,10 @@ const struct inode_operations gfs2_file_iops = { ...@@ -2054,10 +1994,10 @@ const struct inode_operations gfs2_file_iops = {
.permission = gfs2_permission, .permission = gfs2_permission,
.setattr = gfs2_setattr, .setattr = gfs2_setattr,
.getattr = gfs2_getattr, .getattr = gfs2_getattr,
.setxattr = gfs2_setxattr, .setxattr = generic_setxattr,
.getxattr = gfs2_getxattr, .getxattr = generic_getxattr,
.listxattr = gfs2_listxattr, .listxattr = gfs2_listxattr,
.removexattr = gfs2_removexattr, .removexattr = generic_removexattr,
.fiemap = gfs2_fiemap, .fiemap = gfs2_fiemap,
.get_acl = gfs2_get_acl, .get_acl = gfs2_get_acl,
.set_acl = gfs2_set_acl, .set_acl = gfs2_set_acl,
...@@ -2076,10 +2016,10 @@ const struct inode_operations gfs2_dir_iops = { ...@@ -2076,10 +2016,10 @@ const struct inode_operations gfs2_dir_iops = {
.permission = gfs2_permission, .permission = gfs2_permission,
.setattr = gfs2_setattr, .setattr = gfs2_setattr,
.getattr = gfs2_getattr, .getattr = gfs2_getattr,
.setxattr = gfs2_setxattr, .setxattr = generic_setxattr,
.getxattr = gfs2_getxattr, .getxattr = generic_getxattr,
.listxattr = gfs2_listxattr, .listxattr = gfs2_listxattr,
.removexattr = gfs2_removexattr, .removexattr = generic_removexattr,
.fiemap = gfs2_fiemap, .fiemap = gfs2_fiemap,
.get_acl = gfs2_get_acl, .get_acl = gfs2_get_acl,
.set_acl = gfs2_set_acl, .set_acl = gfs2_set_acl,
...@@ -2092,10 +2032,10 @@ const struct inode_operations gfs2_symlink_iops = { ...@@ -2092,10 +2032,10 @@ const struct inode_operations gfs2_symlink_iops = {
.permission = gfs2_permission, .permission = gfs2_permission,
.setattr = gfs2_setattr, .setattr = gfs2_setattr,
.getattr = gfs2_getattr, .getattr = gfs2_getattr,
.setxattr = gfs2_setxattr, .setxattr = generic_setxattr,
.getxattr = gfs2_getxattr, .getxattr = generic_getxattr,
.listxattr = gfs2_listxattr, .listxattr = gfs2_listxattr,
.removexattr = gfs2_removexattr, .removexattr = generic_removexattr,
.fiemap = gfs2_fiemap, .fiemap = gfs2_fiemap,
}; };
...@@ -583,13 +583,11 @@ int gfs2_xattr_acl_get(struct gfs2_inode *ip, const char *name, char **ppdata) ...@@ -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 * Returns: actual size of data on success, -errno on error
*/ */
static int gfs2_xattr_get(const struct xattr_handler *handler, static int __gfs2_xattr_get(struct inode *inode, const char *name,
struct dentry *unused, struct inode *inode, void *buffer, size_t size, int type)
const char *name, void *buffer, size_t size)
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_ea_location el; struct gfs2_ea_location el;
int type = handler->flags;
int error; int error;
if (!ip->i_eattr) if (!ip->i_eattr)
...@@ -611,6 +609,29 @@ static int gfs2_xattr_get(const struct xattr_handler *handler, ...@@ -611,6 +609,29 @@ static int gfs2_xattr_get(const struct xattr_handler *handler,
return error; 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. * ea_alloc_blk - allocates a new block for extended attributes.
* @ip: A pointer to the inode that's getting 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, ...@@ -1233,8 +1254,21 @@ static int gfs2_xattr_set(const struct xattr_handler *handler,
struct dentry *dentry, const char *name, struct dentry *dentry, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
return __gfs2_xattr_set(d_inode(dentry), name, value, struct inode *inode = d_inode(dentry);
size, flags, handler->flags); 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) static int ea_dealloc_indirect(struct gfs2_inode *ip)
......
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