From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, malware-list@lists.printk.net
Cc: viro@zeniv.linux.org.uk, alan@lxorguk.ukuu.org.uk,
arjan@infradead.org, greg@kroah.com, tytso@mit.edu,
akpm@linux-foundation.org
Subject: [PATCH =-v3 08/21] fanotify: add a userspace interface for fastpaths
Date: Wed, 12 Nov 2008 11:11:08 -0500 [thread overview]
Message-ID: <20081112161108.25434.11628.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20081112161002.25434.82358.stgit@paris.rdu.redhat.com>
turns out the fastpath code is useless without an interface. This one
works.
Signed-off-by: Eric Paris <eparis@redhat.com>
---
fs/notify/group.c | 3 +++
include/linux/fanotify.h | 9 +++++++++
net/fanotify/af_fanotify.c | 36 +++++++++++++++++++++++++++++++++++-
3 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/fs/notify/group.c b/fs/notify/group.c
index ff9b5ef..21037cc 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -74,6 +74,9 @@ struct fanotify_group *fanotify_find_group(unsigned int group_num, unsigned int
INIT_LIST_HEAD(&group->notification_list);
init_waitqueue_head(&group->notification_waitq);
+ mutex_init(&group->fastpath_mutex);
+ INIT_LIST_HEAD(&group->fastpath_entries);
+
/* add it */
list_add_rcu(&group->group_list, &fanotify_groups);
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h
index e0e63f2..0646840 100644
--- a/include/linux/fanotify.h
+++ b/include/linux/fanotify.h
@@ -52,6 +52,15 @@ struct fanotify_event_metadata {
/* fanotify getsockopt optvals */
#define FANOTIFY_GET_EVENT 1
+/* struct used for FANOTIFY_SET_FASTPATH */
+struct fanotify_so_fastpath {
+ __s32 fd;
+ __u32 mask;
+} __attribute__((packed));
+
+/* fanotify setsockopt optvals */
+#define FANOTIFY_SET_FASTPATH 1
+
#ifdef __KERNEL__
#include <linux/fs.h>
diff --git a/net/fanotify/af_fanotify.c b/net/fanotify/af_fanotify.c
index 7474cf1..6f2357c 100644
--- a/net/fanotify/af_fanotify.c
+++ b/net/fanotify/af_fanotify.c
@@ -156,6 +156,40 @@ static int fan_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
return 0;
}
+static int fan_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
+{
+ struct fanotify_sock *fan_sock;
+ struct fanotify_group *group;
+ union {
+ struct fanotify_so_fastpath fastpath;
+ } data;
+ int ret = 0;
+
+ if (sock->state != SS_CONNECTED)
+ return -EBADF;
+
+ if (level != SOL_FANOTIFY)
+ return -ENOPROTOOPT;
+
+ fan_sock = fan_sk(sock->sk);
+ group = fan_sock->group;
+
+ switch(optname) {
+ case FANOTIFY_SET_FASTPATH:
+ if (optlen < sizeof(struct fanotify_so_fastpath))
+ return -ENOMEM;
+ ret = copy_from_user(&data.fastpath, optval, sizeof(struct fanotify_so_fastpath));
+ if (ret)
+ return ret;
+ ret = fanotify_fastpath_add(group, data.fastpath.fd, data.fastpath.mask);
+ break;
+ default:
+ return -ENOPROTOOPT;
+ }
+
+ return ret;
+}
+
static int fan_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen)
{
struct fanotify_sock *fan_sock;
@@ -218,7 +252,7 @@ static const struct proto_ops fanotify_proto_ops = {
.ioctl = sock_no_ioctl,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
- .setsockopt = sock_no_setsockopt,
+ .setsockopt = fan_setsockopt,
.getsockopt = fan_getsockopt,
.sendmsg = sock_no_sendmsg,
.recvmsg = sock_no_recvmsg,
next prev parent reply other threads:[~2008-11-12 16:12 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-12 16:10 [PATCH =-v3 00/21] fanotify: novel file access notification and permission system Eric Paris
2008-11-12 16:10 ` [PATCH =-v3 01/21] filesystem notification: create fs/notify to contain all fs notification Eric Paris
2008-11-12 16:10 ` [PATCH =-v3 02/21] fsnotify: pass a file instead of an inode to open, read, and write Eric Paris
2008-11-12 16:10 ` [PATCH =-v3 03/21] fanotify: fscking all notify, system wide file access notification Eric Paris
2008-11-12 16:10 ` [PATCH =-v3 04/21] fsnotify: sys_execve and sys_uselib do not call into fsnotify Eric Paris
2008-11-12 16:49 ` Christoph Hellwig
2008-11-12 21:15 ` Eric Paris
2008-11-12 16:10 ` [PATCH =-v3 05/21] fanotify: make use of the new fsnotify_open_exec calls Eric Paris
2008-11-12 16:10 ` [PATCH =-v3 06/21] fanotify: add a userspace interface for fanotify notifications Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 07/21] fanotify: fastpath to ignore certain in core inodes Eric Paris
2008-11-12 16:50 ` Christoph Hellwig
2008-11-12 16:56 ` Alan Cox
2008-11-12 16:58 ` Christoph Hellwig
2008-11-12 20:52 ` Eric Paris
2009-12-08 15:22 ` John Ogness
2008-11-12 22:38 ` Peter Zijlstra
2008-11-12 16:11 ` Eric Paris [this message]
2008-11-12 16:11 ` [PATCH =-v3 09/21] fanotify: add group priorities Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 10/21] fanotify: blocking and access granting Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 11/21] fanotify: give a special access permission check Eric Paris
2008-11-12 16:53 ` Christoph Hellwig
2008-11-12 21:23 ` Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 12/21] fanotify: user interface for access decisions Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 13/21] fanotify: ability for userspace to delay responses Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 14/21] fanotify: send pid with fanotify notification events Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 15/21] fanotify: send tgid with notification messages Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 16/21] fanotify: send file f_flags along with notifications Eric Paris
2008-11-12 16:11 ` [PATCH =-v3 17/21] fanotify: add option to clear all fastpaths Eric Paris
2008-11-12 16:12 ` [PATCH =-v3 18/21] fanotify: all userspace to set timeouts Eric Paris
2008-11-12 16:56 ` Christoph Hellwig
2008-11-12 21:14 ` Eric Paris
2008-11-12 16:12 ` [PATCH =-v3 19/21] fanotify: evict misbehaving clients Eric Paris
2008-11-12 16:12 ` [PATCH =-v3 20/21] fanotify: allow fastpath entries to survive inode modification Eric Paris
2008-11-12 16:12 ` [PATCH =-v3 21/21] fanotify: add Documentation Eric Paris
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=20081112161108.25434.11628.stgit@paris.rdu.redhat.com \
--to=eparis@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=malware-list@lists.printk.net \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/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