aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/core/uverbs_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/core/uverbs_main.c')
-rw-r--r--drivers/infiniband/core/uverbs_main.c82
1 files changed, 7 insertions, 75 deletions
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 5f284ffd430e..810f277739e2 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -41,8 +41,8 @@
41#include <linux/fs.h> 41#include <linux/fs.h>
42#include <linux/poll.h> 42#include <linux/poll.h>
43#include <linux/sched.h> 43#include <linux/sched.h>
44#include <linux/anon_inodes.h>
44#include <linux/file.h> 45#include <linux/file.h>
45#include <linux/mount.h>
46#include <linux/cdev.h> 46#include <linux/cdev.h>
47 47
48#include <asm/uaccess.h> 48#include <asm/uaccess.h>
@@ -53,8 +53,6 @@ MODULE_AUTHOR("Roland Dreier");
53MODULE_DESCRIPTION("InfiniBand userspace verbs access"); 53MODULE_DESCRIPTION("InfiniBand userspace verbs access");
54MODULE_LICENSE("Dual BSD/GPL"); 54MODULE_LICENSE("Dual BSD/GPL");
55 55
56#define INFINIBANDEVENTFS_MAGIC 0x49426576 /* "IBev" */
57
58enum { 56enum {
59 IB_UVERBS_MAJOR = 231, 57 IB_UVERBS_MAJOR = 231,
60 IB_UVERBS_BASE_MINOR = 192, 58 IB_UVERBS_BASE_MINOR = 192,
@@ -111,8 +109,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
111 [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq, 109 [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,
112}; 110};
113 111
114static struct vfsmount *uverbs_event_mnt;
115
116static void ib_uverbs_add_one(struct ib_device *device); 112static void ib_uverbs_add_one(struct ib_device *device);
117static void ib_uverbs_remove_one(struct ib_device *device); 113static void ib_uverbs_remove_one(struct ib_device *device);
118 114
@@ -489,12 +485,10 @@ void ib_uverbs_event_handler(struct ib_event_handler *handler,
489} 485}
490 486
491struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, 487struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
492 int is_async, int *fd) 488 int is_async)
493{ 489{
494 struct ib_uverbs_event_file *ev_file; 490 struct ib_uverbs_event_file *ev_file;
495 struct path path;
496 struct file *filp; 491 struct file *filp;
497 int ret;
498 492
499 ev_file = kmalloc(sizeof *ev_file, GFP_KERNEL); 493 ev_file = kmalloc(sizeof *ev_file, GFP_KERNEL);
500 if (!ev_file) 494 if (!ev_file)
@@ -509,38 +503,12 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
509 ev_file->is_async = is_async; 503 ev_file->is_async = is_async;
510 ev_file->is_closed = 0; 504 ev_file->is_closed = 0;
511 505
512 *fd = get_unused_fd(); 506 filp = anon_inode_getfile("[infinibandevent]", &uverbs_event_fops,
513 if (*fd < 0) { 507 ev_file, O_RDONLY);
514 ret = *fd; 508 if (IS_ERR(filp))
515 goto err; 509 kfree(ev_file);
516 }
517
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));
527 if (!filp) {
528 ret = -ENFILE;
529 goto err_fd;
530 }
531
532 filp->private_data = ev_file;
533 510
534 return filp; 511 return filp;
535
536err_fd:
537 fops_put(&uverbs_event_fops);
538 path_put(&path);
539 put_unused_fd(*fd);
540
541err:
542 kfree(ev_file);
543 return ERR_PTR(ret);
544} 512}
545 513
546/* 514/*
@@ -825,21 +793,6 @@ static void ib_uverbs_remove_one(struct ib_device *device)
825 kfree(uverbs_dev); 793 kfree(uverbs_dev);
826} 794}
827 795
828static 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
836static 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
843static int __init ib_uverbs_init(void) 796static int __init ib_uverbs_init(void)
844{ 797{
845 int ret; 798 int ret;
@@ -864,33 +817,14 @@ static int __init ib_uverbs_init(void)
864 goto out_class; 817 goto out_class;
865 } 818 }
866 819
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
880 ret = ib_register_client(&uverbs_client); 820 ret = ib_register_client(&uverbs_client);
881 if (ret) { 821 if (ret) {
882 printk(KERN_ERR "user_verbs: couldn't register client\n"); 822 printk(KERN_ERR "user_verbs: couldn't register client\n");
883 goto out_mnt; 823 goto out_class;
884 } 824 }
885 825
886 return 0; 826 return 0;
887 827
888out_mnt:
889 mntput(uverbs_event_mnt);
890
891out_fs:
892 unregister_filesystem(&uverbs_event_fs);
893
894out_class: 828out_class:
895 class_destroy(uverbs_class); 829 class_destroy(uverbs_class);
896 830
@@ -904,8 +838,6 @@ out:
904static void __exit ib_uverbs_cleanup(void) 838static void __exit ib_uverbs_cleanup(void)
905{ 839{
906 ib_unregister_client(&uverbs_client); 840 ib_unregister_client(&uverbs_client);
907 mntput(uverbs_event_mnt);
908 unregister_filesystem(&uverbs_event_fs);
909 class_destroy(uverbs_class); 841 class_destroy(uverbs_class);
910 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); 842 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
911 idr_destroy(&ib_uverbs_pd_idr); 843 idr_destroy(&ib_uverbs_pd_idr);