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>
This commit is contained in:
@@ -20,6 +20,7 @@ config INFINIBAND_USER_MAD
|
|||||||
|
|
||||||
config INFINIBAND_USER_ACCESS
|
config INFINIBAND_USER_ACCESS
|
||||||
tristate "InfiniBand userspace access (verbs and CM)"
|
tristate "InfiniBand userspace access (verbs and CM)"
|
||||||
|
select ANON_INODES
|
||||||
---help---
|
---help---
|
||||||
Userspace InfiniBand access support. This enables the
|
Userspace InfiniBand access support. This enables the
|
||||||
kernel side of userspace verbs and the userspace
|
kernel side of userspace verbs and the userspace
|
||||||
|
@@ -42,8 +42,8 @@
|
|||||||
#include <linux/poll.h>
|
#include <linux/poll.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/file.h>
|
#include <linux/file.h>
|
||||||
#include <linux/mount.h>
|
|
||||||
#include <linux/cdev.h>
|
#include <linux/cdev.h>
|
||||||
|
#include <linux/anon_inodes.h>
|
||||||
|
|
||||||
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
||||||
|
|
||||||
@@ -53,8 +53,6 @@ MODULE_AUTHOR("Roland Dreier");
|
|||||||
MODULE_DESCRIPTION("InfiniBand userspace verbs access");
|
MODULE_DESCRIPTION("InfiniBand userspace verbs access");
|
||||||
MODULE_LICENSE("Dual BSD/GPL");
|
MODULE_LICENSE("Dual BSD/GPL");
|
||||||
|
|
||||||
#define INFINIBANDEVENTFS_MAGIC 0x49426576 /* "IBev" */
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
IB_UVERBS_MAJOR = 231,
|
IB_UVERBS_MAJOR = 231,
|
||||||
IB_UVERBS_BASE_MINOR = 192,
|
IB_UVERBS_BASE_MINOR = 192,
|
||||||
@@ -111,8 +109,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
|
|||||||
[IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,
|
[IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct vfsmount *uverbs_event_mnt;
|
|
||||||
|
|
||||||
static void ib_uverbs_add_one(struct ib_device *device);
|
static void ib_uverbs_add_one(struct ib_device *device);
|
||||||
static void ib_uverbs_remove_one(struct ib_device *device);
|
static void ib_uverbs_remove_one(struct ib_device *device);
|
||||||
|
|
||||||
@@ -492,7 +488,6 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
|
|||||||
int is_async, int *fd)
|
int is_async, int *fd)
|
||||||
{
|
{
|
||||||
struct ib_uverbs_event_file *ev_file;
|
struct ib_uverbs_event_file *ev_file;
|
||||||
struct path path;
|
|
||||||
struct file *filp;
|
struct file *filp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -515,27 +510,16 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
filp = anon_inode_getfile("[uverbs-event]", &uverbs_event_fops,
|
||||||
* fops_get() can't fail here, because we're coming from a
|
ev_file, O_RDONLY);
|
||||||
* system call on a uverbs file, which will already have a
|
|
||||||
* module reference.
|
|
||||||
*/
|
|
||||||
path.mnt = uverbs_event_mnt;
|
|
||||||
path.dentry = uverbs_event_mnt->mnt_root;
|
|
||||||
path_get(&path);
|
|
||||||
filp = alloc_file(&path, FMODE_READ, fops_get(&uverbs_event_fops));
|
|
||||||
if (!filp) {
|
if (!filp) {
|
||||||
ret = -ENFILE;
|
ret = -ENFILE;
|
||||||
goto err_fd;
|
goto err_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
filp->private_data = ev_file;
|
|
||||||
|
|
||||||
return filp;
|
return filp;
|
||||||
|
|
||||||
err_fd:
|
err_fd:
|
||||||
fops_put(&uverbs_event_fops);
|
|
||||||
path_put(&path);
|
|
||||||
put_unused_fd(*fd);
|
put_unused_fd(*fd);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@@ -825,21 +809,6 @@ static void ib_uverbs_remove_one(struct ib_device *device)
|
|||||||
kfree(uverbs_dev);
|
kfree(uverbs_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
|
|
||||||
const char *dev_name, void *data,
|
|
||||||
struct vfsmount *mnt)
|
|
||||||
{
|
|
||||||
return get_sb_pseudo(fs_type, "infinibandevent:", NULL,
|
|
||||||
INFINIBANDEVENTFS_MAGIC, mnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct file_system_type uverbs_event_fs = {
|
|
||||||
/* No owner field so module can be unloaded */
|
|
||||||
.name = "infinibandeventfs",
|
|
||||||
.get_sb = uverbs_event_get_sb,
|
|
||||||
.kill_sb = kill_litter_super
|
|
||||||
};
|
|
||||||
|
|
||||||
static int __init ib_uverbs_init(void)
|
static int __init ib_uverbs_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -864,33 +833,14 @@ static int __init ib_uverbs_init(void)
|
|||||||
goto out_class;
|
goto out_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = register_filesystem(&uverbs_event_fs);
|
|
||||||
if (ret) {
|
|
||||||
printk(KERN_ERR "user_verbs: couldn't register infinibandeventfs\n");
|
|
||||||
goto out_class;
|
|
||||||
}
|
|
||||||
|
|
||||||
uverbs_event_mnt = kern_mount(&uverbs_event_fs);
|
|
||||||
if (IS_ERR(uverbs_event_mnt)) {
|
|
||||||
ret = PTR_ERR(uverbs_event_mnt);
|
|
||||||
printk(KERN_ERR "user_verbs: couldn't mount infinibandeventfs\n");
|
|
||||||
goto out_fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ib_register_client(&uverbs_client);
|
ret = ib_register_client(&uverbs_client);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk(KERN_ERR "user_verbs: couldn't register client\n");
|
printk(KERN_ERR "user_verbs: couldn't register client\n");
|
||||||
goto out_mnt;
|
goto out_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_mnt:
|
|
||||||
mntput(uverbs_event_mnt);
|
|
||||||
|
|
||||||
out_fs:
|
|
||||||
unregister_filesystem(&uverbs_event_fs);
|
|
||||||
|
|
||||||
out_class:
|
out_class:
|
||||||
class_destroy(uverbs_class);
|
class_destroy(uverbs_class);
|
||||||
|
|
||||||
@@ -904,8 +854,6 @@ out:
|
|||||||
static void __exit ib_uverbs_cleanup(void)
|
static void __exit ib_uverbs_cleanup(void)
|
||||||
{
|
{
|
||||||
ib_unregister_client(&uverbs_client);
|
ib_unregister_client(&uverbs_client);
|
||||||
mntput(uverbs_event_mnt);
|
|
||||||
unregister_filesystem(&uverbs_event_fs);
|
|
||||||
class_destroy(uverbs_class);
|
class_destroy(uverbs_class);
|
||||||
unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
|
unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
|
||||||
idr_destroy(&ib_uverbs_pd_idr);
|
idr_destroy(&ib_uverbs_pd_idr);
|
||||||
|
Reference in New Issue
Block a user