Skip to content

Commit bba0bd3

Browse files
agruenbaAl Viro
authored andcommitted
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>
1 parent 971df15 commit bba0bd3

3 files changed

Lines changed: 47 additions & 27 deletions

File tree

‎fs/libfs.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ static const struct super_operations simple_super_operations = {
236236
* Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that
237237
* will never be mountable)
238238
*/
239-
struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
240-
const struct super_operations *ops,
239+
struct dentry *mount_pseudo_xattr(struct file_system_type *fs_type, char *name,
240+
const struct super_operations *ops, const struct xattr_handler **xattr,
241241
const struct dentry_operations *dops, unsigned long magic)
242242
{
243243
struct super_block *s;
@@ -254,6 +254,7 @@ struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
254254
s->s_blocksize_bits = PAGE_SHIFT;
255255
s->s_magic = magic;
256256
s->s_op = ops ? ops : &simple_super_operations;
257+
s->s_xattr = xattr;
257258
s->s_time_gran = 1;
258259
root = new_inode(s);
259260
if (!root)
@@ -281,7 +282,7 @@ struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
281282
deactivate_locked_super(s);
282283
return ERR_PTR(-ENOMEM);
283284
}
284-
EXPORT_SYMBOL(mount_pseudo);
285+
EXPORT_SYMBOL(mount_pseudo_xattr);
285286

286287
int simple_open(struct inode *inode, struct file *file)
287288
{

‎include/linux/fs.h‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,10 +2075,19 @@ struct super_block *sget(struct file_system_type *type,
20752075
int (*test)(struct super_block *,void *),
20762076
int (*set)(struct super_block *,void *),
20772077
int flags, void *data);
2078-
extern struct dentry *mount_pseudo(struct file_system_type *, char *,
2079-
const struct super_operations *ops,
2080-
const struct dentry_operations *dops,
2081-
unsigned long);
2078+
extern struct dentry *mount_pseudo_xattr(struct file_system_type *, char *,
2079+
const struct super_operations *ops,
2080+
const struct xattr_handler **xattr,
2081+
const struct dentry_operations *dops,
2082+
unsigned long);
2083+
2084+
static inline struct dentry *
2085+
mount_pseudo(struct file_system_type *fs_type, char *name,
2086+
const struct super_operations *ops,
2087+
const struct dentry_operations *dops, unsigned long magic)
2088+
{
2089+
return mount_pseudo_xattr(fs_type, name, ops, NULL, dops, magic);
2090+
}
20822091

20832092
/* Alas, no aliases. Too much hassle with bringing module.h everywhere */
20842093
#define fops_get(fops) \

‎net/socket.c‎

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,38 @@ static const struct dentry_operations sockfs_dentry_operations = {
320320
.d_dname = sockfs_dname,
321321
};
322322

323+
static int sockfs_xattr_get(const struct xattr_handler *handler,
324+
struct dentry *dentry, struct inode *inode,
325+
const char *suffix, void *value, size_t size)
326+
{
327+
if (value) {
328+
if (dentry->d_name.len + 1 > size)
329+
return -ERANGE;
330+
memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
331+
}
332+
return dentry->d_name.len + 1;
333+
}
334+
335+
#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
336+
#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
337+
#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
338+
339+
static const struct xattr_handler sockfs_xattr_handler = {
340+
.name = XATTR_NAME_SOCKPROTONAME,
341+
.get = sockfs_xattr_get,
342+
};
343+
344+
static const struct xattr_handler *sockfs_xattr_handlers[] = {
345+
&sockfs_xattr_handler,
346+
NULL
347+
};
348+
323349
static struct dentry *sockfs_mount(struct file_system_type *fs_type,
324350
int flags, const char *dev_name, void *data)
325351
{
326-
return mount_pseudo(fs_type, "socket:", &sockfs_ops,
327-
&sockfs_dentry_operations, SOCKFS_MAGIC);
352+
return mount_pseudo_xattr(fs_type, "socket:", &sockfs_ops,
353+
sockfs_xattr_handlers,
354+
&sockfs_dentry_operations, SOCKFS_MAGIC);
328355
}
329356

330357
static struct vfsmount *sock_mnt __read_mostly;
@@ -463,23 +490,6 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
463490
return NULL;
464491
}
465492

466-
#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
467-
#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
468-
#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
469-
static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode,
470-
const char *name, void *value, size_t size)
471-
{
472-
if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
473-
if (value) {
474-
if (dentry->d_name.len + 1 > size)
475-
return -ERANGE;
476-
memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
477-
}
478-
return dentry->d_name.len + 1;
479-
}
480-
return -EOPNOTSUPP;
481-
}
482-
483493
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
484494
size_t size)
485495
{
@@ -509,7 +519,7 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
509519
}
510520

511521
static const struct inode_operations sockfs_inode_ops = {
512-
.getxattr = sockfs_getxattr,
522+
.getxattr = generic_getxattr,
513523
.listxattr = sockfs_listxattr,
514524
};
515525

0 commit comments

Comments
 (0)