Skip to content

Commit a265e55

Browse files
author
Roland Dreier
committed
IB/uverbs: Use anon_inodes instead of private infinibandeventfs
The anon_inodes interface has been split to allow creating a bare (non-installed) file pointer and also extended to allow specifying O_RDONLY in the flags. This makes it a suitable replacement for the private "infinibandeventfs" pseudo-filesystem used by uverbs, and this replacement saves a small chunk of boilerplate code. Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent 920d706 commit a265e55

2 files changed

Lines changed: 5 additions & 56 deletions

File tree

‎drivers/infiniband/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ config INFINIBAND_USER_MAD
2020

2121
config INFINIBAND_USER_ACCESS
2222
tristate "InfiniBand userspace access (verbs and CM)"
23+
select ANON_INODES
2324
---help---
2425
Userspace InfiniBand access support. This enables the
2526
kernel side of userspace verbs and the userspace

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#include <linux/poll.h>
4343
#include <linux/sched.h>
4444
#include <linux/file.h>
45-
#include <linux/mount.h>
4645
#include <linux/cdev.h>
46+
#include <linux/anon_inodes.h>
4747

4848
#include <asm/uaccess.h>
4949

@@ -53,8 +53,6 @@ MODULE_AUTHOR("Roland Dreier");
5353
MODULE_DESCRIPTION("InfiniBand userspace verbs access");
5454
MODULE_LICENSE("Dual BSD/GPL");
5555

56-
#define INFINIBANDEVENTFS_MAGIC 0x49426576 /* "IBev" */
57-
5856
enum {
5957
IB_UVERBS_MAJOR = 231,
6058
IB_UVERBS_BASE_MINOR = 192,
@@ -111,8 +109,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
111109
[IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,
112110
};
113111

114-
static struct vfsmount *uverbs_event_mnt;
115-
116112
static void ib_uverbs_add_one(struct ib_device *device);
117113
static void ib_uverbs_remove_one(struct ib_device *device);
118114

@@ -492,7 +488,6 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
492488
int is_async, int *fd)
493489
{
494490
struct ib_uverbs_event_file *ev_file;
495-
struct path path;
496491
struct file *filp;
497492
int ret;
498493

@@ -515,27 +510,16 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
515510
goto err;
516511
}
517512

518-
/*
519-
* fops_get() can't fail here, because we're coming from a
520-
* system call on a uverbs file, which will already have a
521-
* module reference.
522-
*/
523-
path.mnt = uverbs_event_mnt;
524-
path.dentry = uverbs_event_mnt->mnt_root;
525-
path_get(&path);
526-
filp = alloc_file(&path, FMODE_READ, fops_get(&uverbs_event_fops));
513+
filp = anon_inode_getfile("[uverbs-event]", &uverbs_event_fops,
514+
ev_file, O_RDONLY);
527515
if (!filp) {
528516
ret = -ENFILE;
529517
goto err_fd;
530518
}
531519

532-
filp->private_data = ev_file;
533-
534520
return filp;
535521

536522
err_fd:
537-
fops_put(&uverbs_event_fops);
538-
path_put(&path);
539523
put_unused_fd(*fd);
540524

541525
err:
@@ -825,21 +809,6 @@ static void ib_uverbs_remove_one(struct ib_device *device)
825809
kfree(uverbs_dev);
826810
}
827811

828-
static int uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
829-
const char *dev_name, void *data,
830-
struct vfsmount *mnt)
831-
{
832-
return get_sb_pseudo(fs_type, "infinibandevent:", NULL,
833-
INFINIBANDEVENTFS_MAGIC, mnt);
834-
}
835-
836-
static struct file_system_type uverbs_event_fs = {
837-
/* No owner field so module can be unloaded */
838-
.name = "infinibandeventfs",
839-
.get_sb = uverbs_event_get_sb,
840-
.kill_sb = kill_litter_super
841-
};
842-
843812
static int __init ib_uverbs_init(void)
844813
{
845814
int ret;
@@ -864,33 +833,14 @@ static int __init ib_uverbs_init(void)
864833
goto out_class;
865834
}
866835

867-
ret = register_filesystem(&uverbs_event_fs);
868-
if (ret) {
869-
printk(KERN_ERR "user_verbs: couldn't register infinibandeventfs\n");
870-
goto out_class;
871-
}
872-
873-
uverbs_event_mnt = kern_mount(&uverbs_event_fs);
874-
if (IS_ERR(uverbs_event_mnt)) {
875-
ret = PTR_ERR(uverbs_event_mnt);
876-
printk(KERN_ERR "user_verbs: couldn't mount infinibandeventfs\n");
877-
goto out_fs;
878-
}
879-
880836
ret = ib_register_client(&uverbs_client);
881837
if (ret) {
882838
printk(KERN_ERR "user_verbs: couldn't register client\n");
883-
goto out_mnt;
839+
goto out_class;
884840
}
885841

886842
return 0;
887843

888-
out_mnt:
889-
mntput(uverbs_event_mnt);
890-
891-
out_fs:
892-
unregister_filesystem(&uverbs_event_fs);
893-
894844
out_class:
895845
class_destroy(uverbs_class);
896846

@@ -904,8 +854,6 @@ static int __init ib_uverbs_init(void)
904854
static void __exit ib_uverbs_cleanup(void)
905855
{
906856
ib_unregister_client(&uverbs_client);
907-
mntput(uverbs_event_mnt);
908-
unregister_filesystem(&uverbs_event_fs);
909857
class_destroy(uverbs_class);
910858
unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
911859
idr_destroy(&ib_uverbs_pd_idr);

0 commit comments

Comments
 (0)