Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andreas Gruenbacher and committed by
Al Viro
bba0bd31 971df15b

+47 -27
+4 -3
fs/libfs.c
··· 236 236 * Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that 237 237 * will never be mountable) 238 238 */ 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, 241 241 const struct dentry_operations *dops, unsigned long magic) 242 242 { 243 243 struct super_block *s; ··· 254 254 s->s_blocksize_bits = PAGE_SHIFT; 255 255 s->s_magic = magic; 256 256 s->s_op = ops ? ops : &simple_super_operations; 257 + s->s_xattr = xattr; 257 258 s->s_time_gran = 1; 258 259 root = new_inode(s); 259 260 if (!root) ··· 282 281 deactivate_locked_super(s); 283 282 return ERR_PTR(-ENOMEM); 284 283 } 285 - EXPORT_SYMBOL(mount_pseudo); 284 + EXPORT_SYMBOL(mount_pseudo_xattr); 286 285 287 286 int simple_open(struct inode *inode, struct file *file) 288 287 {
+13 -4
include/linux/fs.h
··· 2075 2075 int (*test)(struct super_block *,void *), 2076 2076 int (*set)(struct super_block *,void *), 2077 2077 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 + } 2082 2091 2083 2092 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ 2084 2093 #define fops_get(fops) \
+30 -20
net/socket.c
··· 320 320 .d_dname = sockfs_dname, 321 321 }; 322 322 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 + 323 349 static struct dentry *sockfs_mount(struct file_system_type *fs_type, 324 350 int flags, const char *dev_name, void *data) 325 351 { 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); 328 355 } 329 356 330 357 static struct vfsmount *sock_mnt __read_mostly; ··· 490 463 return NULL; 491 464 } 492 465 493 - #define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname" 494 - #define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX) 495 - #define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1) 496 - static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode, 497 - const char *name, void *value, size_t size) 498 - { 499 - if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) { 500 - if (value) { 501 - if (dentry->d_name.len + 1 > size) 502 - return -ERANGE; 503 - memcpy(value, dentry->d_name.name, dentry->d_name.len + 1); 504 - } 505 - return dentry->d_name.len + 1; 506 - } 507 - return -EOPNOTSUPP; 508 - } 509 - 510 466 static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, 511 467 size_t size) 512 468 { ··· 519 509 } 520 510 521 511 static const struct inode_operations sockfs_inode_ops = { 522 - .getxattr = sockfs_getxattr, 512 + .getxattr = generic_getxattr, 523 513 .listxattr = sockfs_listxattr, 524 514 }; 525 515