From: David Howells <dhowells@redhat.com>
To: torvalds@osdl.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-afs@lists.infradead.org,
linux-fsdevel@vger.kernel.org, Wang Lei <wang840925@gmail.com>,
David Howells <dhowells@redhat.com>
Subject: [PATCH 03/17] VFS: Implement handling for pathless pioctls
Date: Tue, 16 Jun 2009 21:39:01 +0100 [thread overview]
Message-ID: <20090616203901.4526.200.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20090616203845.4526.60013.stgit@warthog.procyon.org.uk>
From: Wang Lei <wang840925@gmail.com>
Implement handling for pathless pioctls. Because these take no path argument,
there's no way to know for certain which filesystem they're aimed at, so we
have to switch on command number instead. This patch allows interested parties
to register handlers. Each registered handler function is tried in turn until
one doesn't return -EOPNOTSUPP.
This is required because OpenAFS implemented a number of AFS calls that don't
get given a path as they're aimed at AFS in general, and not at a particular
file, volume or cell in the AFS world.
Signed-off-by: Wang Lei <wang840925@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/compat_pioctl.c | 14 ++++--
fs/pioctl.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++--
include/linux/pioctl.h | 12 +++++
3 files changed, 130 insertions(+), 10 deletions(-)
diff --git a/fs/compat_pioctl.c b/fs/compat_pioctl.c
index 9f2de77..36b0553 100644
--- a/fs/compat_pioctl.c
+++ b/fs/compat_pioctl.c
@@ -75,11 +75,15 @@ long compat_sys_pioctl(const char __user *filename, int cmd,
kargs.out = NULL;
}
- error = user_path(filename, &path);
- if (!error) {
- if (path.dentry->d_inode)
- error = vfs_pioctl(path.dentry, cmd, &kargs);
- path_put(&path);
+ if (!filename) {
+ error = vfs_pioctl(NULL, cmd, &kargs);
+ } else {
+ error = user_path(filename, &path);
+ if (!error) {
+ if (path.dentry->d_inode)
+ error = vfs_pioctl(path.dentry, cmd, &kargs);
+ path_put(&path);
+ }
}
kfree(kargs.in);
diff --git a/fs/pioctl.c b/fs/pioctl.c
index c17f220..1fe4bf8 100644
--- a/fs/pioctl.c
+++ b/fs/pioctl.c
@@ -1,5 +1,6 @@
/* Path-based I/O control
*
+ * Copyright (C) 2009 Wang Lei <wang840925@gmail.com>
* Copyright (C) 2009 David Howells <dhowells@redhat.com>
* Copyright (C) 2008 Jacob Thebault-Spieker <summatusmentis@gmail.com>
*
@@ -12,15 +13,47 @@
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <linux/kernel.h>
+#include <linux/module.h>
#include <linux/namei.h>
#include <linux/pioctl.h>
#include <linux/slab.h>
+static struct pathless_pioctl_handler *pathless_pioctls;
+static DECLARE_RWSEM(pathless_pioctls_rwsem);
+
+/*
+ * Traverse the pathless pioctl handlers list, to find the appropriate handler
+ */
+static long pathless_pioctl(int cmd, struct vice_ioctl *arg)
+{
+ struct pathless_pioctl_handler *p;
+ long ret;
+
+ down_read(&pathless_pioctls_rwsem);
+ p = pathless_pioctls;
+ while (p) {
+ if (try_module_get(p->owner)) {
+ ret = p->pioctl(cmd, arg);
+ module_put(p->owner);
+ if (ret != -EOPNOTSUPP) {
+ up_write(&pathless_pioctls_rwsem);
+ return ret;
+ }
+ }
+ p = p->next;
+ }
+ up_read(&pathless_pioctls_rwsem);
+ return -EOPNOTSUPP;
+}
+
/*
* VFS entry point for path-based I/O control
*/
long vfs_pioctl(struct dentry *dentry, int cmd, struct vice_ioctl *arg)
{
+ if (!dentry)
+ return pathless_pioctl(cmd, arg);
+
if (!dentry->d_inode->i_op || !dentry->d_inode->i_op->pioctl)
return -EPERM;
@@ -28,6 +61,73 @@ long vfs_pioctl(struct dentry *dentry, int cmd, struct vice_ioctl *arg)
}
/*
+ * Find the pointer to an pathless pioctl handler or the point at which it
+ * should be inserted
+ */
+static struct pathless_pioctl_handler **find_pathless_pioctl(
+ struct pathless_pioctl_handler *handler)
+{
+ struct pathless_pioctl_handler **p;
+
+ for (p = &pathless_pioctls; *p; p = &(*p)->next)
+ if ((*p) == handler)
+ break;
+ return p;
+}
+
+/**
+ * pathless_pioctl_register - Register a pathless pioctl handler
+ * @handler: The handler to be registered
+ *
+ * Add a handler to the list of pathless pioctl handlers, making sure that the
+ * handler is not already registered.
+ */
+int pathless_pioctl_register(struct pathless_pioctl_handler *handler)
+{
+ int res = 0;
+ struct pathless_pioctl_handler **p;
+
+ if (handler->next)
+ return -EBUSY;
+
+ down_write(&pathless_pioctls_rwsem);
+ p = find_pathless_pioctl(handler);
+ if (*p)
+ res = -EBUSY;
+ else
+ *p = handler;
+ up_write(&pathless_pioctls_rwsem);
+ return res;
+}
+EXPORT_SYMBOL(pathless_pioctl_register);
+
+/**
+ * pathless_pioctl_unregister - Unregister a pathless pioctl handler
+ * @handler: The handler to be unregistered
+ *
+ * Remove the special handler from the list of pathless pioctl handlers, making
+ * sure that the handler is already registered.
+ */
+int pathless_pioctl_unregister(struct pathless_pioctl_handler *handler)
+{
+ struct pathless_pioctl_handler **p;
+
+ down_write(&pathless_pioctls_rwsem);
+ for (p = &pathless_pioctls; *p; p = &(*p)->next) {
+ if (*p == handler) {
+ *p = handler->next;
+ handler->next = NULL;
+ up_write(&pathless_pioctls_rwsem);
+ return 0;
+ }
+
+ }
+ up_write(&pathless_pioctls_rwsem);
+ return -EINVAL;
+}
+EXPORT_SYMBOL(pathless_pioctl_unregister);
+
+/*
* Path-based I/O control system call
*/
SYSCALL_DEFINE4(pioctl,
@@ -82,11 +182,15 @@ SYSCALL_DEFINE4(pioctl,
kargs.out = NULL;
}
- error = user_path(filename, &path);
- if (!error) {
- if (path.dentry->d_inode)
- error = vfs_pioctl(path.dentry, cmd, &kargs);
- path_put(&path);
+ if (!filename) {
+ error = vfs_pioctl(NULL, cmd, &kargs);
+ } else {
+ error = user_path(filename, &path);
+ if (!error) {
+ if (path.dentry->d_inode)
+ error = vfs_pioctl(path.dentry, cmd, &kargs);
+ path_put(&path);
+ }
}
kfree(kargs.in);
diff --git a/include/linux/pioctl.h b/include/linux/pioctl.h
index 8e979f4..a4c1082 100644
--- a/include/linux/pioctl.h
+++ b/include/linux/pioctl.h
@@ -41,6 +41,18 @@ struct vice_ioctl {
*/
extern long vfs_pioctl(struct dentry *, int, struct vice_ioctl *);
+/*
+ * Pathless pioctl handler type
+ */
+struct pathless_pioctl_handler {
+ struct module *owner;
+ struct pathless_pioctl_handler *next;
+ long (*pioctl)(int cmd, struct vice_ioctl *);
+};
+
+extern int pathless_pioctl_register(struct pathless_pioctl_handler *);
+extern int pathless_pioctl_unregister(struct pathless_pioctl_handler *);
+
#else
/*
next prev parent reply other threads:[~2009-06-16 20:39 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-16 20:38 [PATCH 00/17] [RFC] AFS: Implement OpenAFS pioctls(version)s David Howells
2009-06-16 20:38 ` [PATCH 01/17] VFS: Implement the pioctl() system call David Howells
2009-06-16 20:54 ` Christoph Hellwig
2009-06-17 0:19 ` David Howells
2009-06-17 9:02 ` Alan Cox
2009-06-16 20:38 ` [PATCH 02/17] VFS: Implement the AFS " David Howells
2009-06-16 20:39 ` David Howells [this message]
2009-06-17 7:47 ` [PATCH 03/17] VFS: Implement handling for pathless pioctls Andreas Dilger
2009-06-17 18:26 ` David Howells
2009-06-16 20:39 ` [PATCH 04/17] AFS: Add key request for pioctl David Howells
2009-06-16 20:39 ` [PATCH 05/17] AFS: Handle pathless pioctls aimed at AFS David Howells
2009-06-16 20:39 ` [PATCH 06/17] VFS: Define pioctl command wrappers David Howells
2009-06-16 20:39 ` [PATCH 07/17] AFS: Implement the PGetFid pioctl David Howells
2009-06-16 20:39 ` [PATCH 08/17] AFS: Implement the PGetFileCell pioctl David Howells
2009-06-16 20:39 ` [PATCH 09/17] AFS: Implement the PGetVolStat pioctl David Howells
2009-06-16 20:39 ` [PATCH 10/17] AFS: Implement the PWhereIs pioctl David Howells
2009-06-17 7:51 ` Andreas Dilger
2009-06-17 18:05 ` David Howells
2009-06-16 20:39 ` [PATCH 11/17] AFS: Implement the PFlushCB pioctl David Howells
2009-06-16 20:39 ` [PATCH 12/17] KEYS: Export lookup_user_key() and the key permission request flags David Howells
2009-06-16 20:39 ` [PATCH 13/17] RxRPC: Record extra data in key David Howells
2009-06-16 20:39 ` [PATCH 14/17] RxRPC: Declare the security index constants symbolically David Howells
2009-06-16 20:40 ` [PATCH 15/17] AFS: Implement the PSetTokens pioctl David Howells
2009-06-16 20:40 ` [PATCH 16/17] KEYS: Add a function by which the contents of a keyring can be enumerated David Howells
2009-06-16 20:40 ` [PATCH 17/17] AFS: Implement the PGetTokens pioctl David Howells
2009-06-16 22:59 ` [PATCH 00/17] [RFC] AFS: Implement OpenAFS pioctls(version)s David Howells
2009-06-16 23:11 ` Alan Cox
2009-06-17 0:25 ` David Howells
2009-06-17 7:55 ` Andreas Dilger
2009-06-17 16:09 ` Linus Torvalds
2009-06-17 18:37 ` Al Viro
2009-06-17 18:44 ` Linus Torvalds
2009-06-17 18:52 ` Al Viro
2009-06-17 19:28 ` David Howells
2009-06-18 12:50 ` Olivier Galibert
2009-06-17 17:24 ` David Howells
2009-06-17 17:33 ` Linus Torvalds
2009-06-17 18:03 ` David Howells
2009-06-17 18:24 ` Linus Torvalds
2009-06-17 18:30 ` Theodore Tso
2009-06-17 19:14 ` david
2009-06-17 19:30 ` David Howells
2009-06-17 19:51 ` David Howells
2009-06-17 20:09 ` Linus Torvalds
2009-06-17 9:00 ` Alan Cox
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=20090616203901.4526.200.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
--cc=wang840925@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).