All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <rdreier@cisco.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Davide Libenzi <davidel@xmailserver.org>,
	akpm@linux-foundation.org
Subject: [PATCH 2/2] IB/uverbs: Use anonymous inodes instead of private filesystem
Date: Wed, 27 Feb 2008 11:18:57 -0800	[thread overview]
Message-ID: <adafxveyzq6.fsf_-_@cisco.com> (raw)
In-Reply-To: <adak5kqyzv1.fsf@cisco.com> (Roland Dreier's message of "Wed, 27 Feb 2008 11:16:02 -0800")

Now that anonymous inodes allow us to control when fd_install() is
called, we can convert ib_uverbs to use them instead of its own
private infinibandeventfs virtual filesystem.  This removes a healthy
chunk of code and also deletes the last in-tree user of
get_empty_filp(), which makes Christoph Hellwig happy.

Tested with an app that uses the ib_uverbs event file interfaces.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
---
 drivers/infiniband/core/uverbs_main.c |   76 ++++-----------------------------
 1 files changed, 9 insertions(+), 67 deletions(-)

diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 7c2ac39..7629566 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -40,11 +40,10 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/err.h>
-#include <linux/fs.h>
 #include <linux/poll.h>
 #include <linux/file.h>
-#include <linux/mount.h>
 #include <linux/cdev.h>
+#include <linux/anon_inodes.h>
 
 #include <asm/uaccess.h>
 
@@ -54,8 +53,6 @@ MODULE_AUTHOR("Roland Dreier");
 MODULE_DESCRIPTION("InfiniBand userspace verbs access");
 MODULE_LICENSE("Dual BSD/GPL");
 
-#define INFINIBANDEVENTFS_MAGIC	0x49426576	/* "IBev" */
-
 enum {
 	IB_UVERBS_MAJOR       = 231,
 	IB_UVERBS_BASE_MINOR  = 192,
@@ -112,8 +109,6 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
 	[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_remove_one(struct ib_device *device);
 
@@ -495,6 +490,7 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
 					int is_async, int *fd)
 {
 	struct ib_uverbs_event_file *ev_file;
+	struct inode *inode;
 	struct file *filp;
 	int ret;
 
@@ -510,37 +506,19 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
 	ev_file->async_queue = NULL;
 	ev_file->is_async    = is_async;
 
-	*fd = get_unused_fd();
-	if (*fd < 0) {
-		ret = *fd;
-		goto err;
-	}
-
-	filp = get_empty_filp();
-	if (!filp) {
-		ret = -ENFILE;
-		goto err_fd;
-	}
-
-	ev_file->file      = filp;
-
 	/*
 	 * fops_get() can't fail here, because we're coming from a
 	 * system call on a uverbs file, which will already have a
 	 * module reference.
 	 */
-	filp->f_op 	   = fops_get(&uverbs_event_fops);
-	filp->f_path.mnt 	   = mntget(uverbs_event_mnt);
-	filp->f_path.dentry 	   = dget(uverbs_event_mnt->mnt_root);
-	filp->f_mapping    = filp->f_path.dentry->d_inode->i_mapping;
-	filp->f_flags      = O_RDONLY;
-	filp->f_mode       = FMODE_READ;
-	filp->private_data = ev_file;
+	ret = anon_inode_allocfd(fd, &inode, &filp, "[uverbs-event]",
+				 fops_get(&uverbs_event_fops), ev_file);
+	if (ret)
+		goto err;
 
-	return filp;
+	ev_file->file = filp;
 
-err_fd:
-	put_unused_fd(*fd);
+	return filp;
 
 err:
 	kfree(ev_file);
@@ -817,21 +795,6 @@ static void ib_uverbs_remove_one(struct ib_device *device)
 	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)
 {
 	int ret;
@@ -858,33 +821,14 @@ static int __init ib_uverbs_init(void)
 		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);
 	if (ret) {
 		printk(KERN_ERR "user_verbs: couldn't register client\n");
-		goto out_mnt;
+		goto out_class;
 	}
 
 	return 0;
 
-out_mnt:
-	mntput(uverbs_event_mnt);
-
-out_fs:
-	unregister_filesystem(&uverbs_event_fs);
-
 out_class:
 	class_destroy(uverbs_class);
 
@@ -898,8 +842,6 @@ out:
 static void __exit ib_uverbs_cleanup(void)
 {
 	ib_unregister_client(&uverbs_client);
-	mntput(uverbs_event_mnt);
-	unregister_filesystem(&uverbs_event_fs);
 	class_destroy(uverbs_class);
 	unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
 	idr_destroy(&ib_uverbs_pd_idr);
-- 
1.5.4.2


  reply	other threads:[~2008-02-27 19:19 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-25 19:10 [PATCH] uverbs: kill last remaining modular get_empty_filp user Christoph Hellwig
2008-02-27 19:01 ` Roland Dreier
2008-02-27 19:16 ` [PATCH/RFC 1/2] anon-inodes: Remove fd_install() from anon_inode_getfd() Roland Dreier
2008-02-27 19:16   ` Roland Dreier
2008-02-27 19:18   ` Roland Dreier [this message]
2008-02-27 19:20   ` Avi Kivity
2008-02-27 19:41   ` Davide Libenzi
2008-02-27 19:41     ` Davide Libenzi
2008-02-27 20:14     ` Roland Dreier
2008-02-27 20:30       ` Davide Libenzi
2008-02-27 21:05         ` Roland Dreier
2008-02-27 21:05           ` Roland Dreier
2008-02-27 23:42           ` Roland Dreier
2008-02-27 23:42             ` Roland Dreier
2008-02-28  7:52             ` Avi Kivity
2008-02-28 20:04             ` Davide Libenzi
2008-02-28 20:24               ` Roland Dreier
2008-02-28 20:52                 ` Davide Libenzi
2008-03-05  9:32                   ` [kvm-devel] " Avi Kivity
2008-03-05  9:32                     ` Avi Kivity
2008-03-06 15:14             ` Christoph Hellwig
2008-03-06 15:14               ` Christoph Hellwig
2008-03-09  2:45               ` Roland Dreier
2008-03-09  2:45                 ` Roland Dreier
2008-03-17 10:40                 ` Christoph Hellwig
2008-03-17 10:40                   ` Christoph Hellwig
2008-03-17 10:48                   ` Avi Kivity
2008-03-09  2:46               ` Roland Dreier
2008-03-09  2:46                 ` Roland Dreier
2008-03-06 15:14   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=adafxveyzq6.fsf_-_@cisco.com \
    --to=rdreier@cisco.com \
    --cc=akpm@linux-foundation.org \
    --cc=davidel@xmailserver.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.