sockfs: Get rid of getxattr iop
If we allow pseudo-filesystems created with mount_pseudo to have xattr handlers, we can replace sockfs_getxattr with a sockfs_xattr_get handler to use the xattr handler name parsing. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:

committed by
Al Viro

parent
971df15bd5
commit
bba0bd31b1
50
net/socket.c
50
net/socket.c
@@ -320,11 +320,38 @@ static const struct dentry_operations sockfs_dentry_operations = {
|
||||
.d_dname = sockfs_dname,
|
||||
};
|
||||
|
||||
static int sockfs_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *dentry, struct inode *inode,
|
||||
const char *suffix, void *value, size_t size)
|
||||
{
|
||||
if (value) {
|
||||
if (dentry->d_name.len + 1 > size)
|
||||
return -ERANGE;
|
||||
memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
|
||||
}
|
||||
return dentry->d_name.len + 1;
|
||||
}
|
||||
|
||||
#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
|
||||
#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
|
||||
#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
|
||||
|
||||
static const struct xattr_handler sockfs_xattr_handler = {
|
||||
.name = XATTR_NAME_SOCKPROTONAME,
|
||||
.get = sockfs_xattr_get,
|
||||
};
|
||||
|
||||
static const struct xattr_handler *sockfs_xattr_handlers[] = {
|
||||
&sockfs_xattr_handler,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct dentry *sockfs_mount(struct file_system_type *fs_type,
|
||||
int flags, const char *dev_name, void *data)
|
||||
{
|
||||
return mount_pseudo(fs_type, "socket:", &sockfs_ops,
|
||||
&sockfs_dentry_operations, SOCKFS_MAGIC);
|
||||
return mount_pseudo_xattr(fs_type, "socket:", &sockfs_ops,
|
||||
sockfs_xattr_handlers,
|
||||
&sockfs_dentry_operations, SOCKFS_MAGIC);
|
||||
}
|
||||
|
||||
static struct vfsmount *sock_mnt __read_mostly;
|
||||
@@ -463,23 +490,6 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
|
||||
#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
|
||||
#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
|
||||
static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
|
||||
if (value) {
|
||||
if (dentry->d_name.len + 1 > size)
|
||||
return -ERANGE;
|
||||
memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
|
||||
}
|
||||
return dentry->d_name.len + 1;
|
||||
}
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
|
||||
size_t size)
|
||||
{
|
||||
@@ -509,7 +519,7 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
|
||||
}
|
||||
|
||||
static const struct inode_operations sockfs_inode_ops = {
|
||||
.getxattr = sockfs_getxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = sockfs_listxattr,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user