Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
kernel sysfs events layer
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 90 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Robert Love  
View profile  
 More options Aug 31 2004, 5:52 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Tue, 31 Aug 2004 21:52:28 GMT
Local: Tues, Aug 31 2004 5:52 pm
Subject: [patch] kernel sysfs events layer
Here is the Kernel Events Layer rewritten as more of an asynchronous
sysfs change notifier.  The concept of object and payload have been
removed.  Instead, events are modeled as signals emitting from kobjects.
It is pretty simple.

The interface is now:

        int send_kevent(enum kevent type, struct kset *kset,
                        struct kobject *kobj, const char *signal)

Say your processor (with kobject "kobj") is overheating.  You might do

        send_kevent(KEVENT_POWER, NULL, kobj, "overheating");

We could get rid of signal and just require passing a specific attribute
file in sysfs, which would presumably explain the reason for the event,
but I think having a single signal value is acceptable.  The rest of the
payload has been ditched.

The basic idea here is to represent to user-space events as changes to
sysfs.  Media was changed?  Then that block device in sysfs emits a
"media_change" event.

This patch includes two example events: file system mount and unmount.

Kay has some utilities and examples at
        http://vrfy.org/projects/kevents/
and
        http://vrfy.org/projects/kdbusd/

The intention of this work is to hook the kernel into D-BUS, although
the implementation is agnostic and should work with any user-space
setup.

Best,

        Robert Love

Kernel Events Layer.  A simple sysfs change notifier over netlink.
Signed-Off-By: Robert Love <r...@novell.com>

 fs/super.c              |   11 ++++-
 include/linux/kevent.h  |   42 +++++++++++++++++++
 include/linux/netlink.h |    1
 init/Kconfig            |   14 ++++++
 kernel/Makefile         |    1
 kernel/kevent.c         |  105 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 173 insertions(+), 1 deletion(-)

diff -urN linux-2.6.9-rc1-mm2/fs/super.c linux/fs/super.c
--- linux-2.6.9-rc1-mm2/fs/super.c      2004-08-31 16:46:15.912777856 -0400
+++ linux/fs/super.c    2004-08-31 16:44:41.023203264 -0400
@@ -35,6 +35,7 @@
 #include <linux/vfs.h>
 #include <linux/writeback.h>             /* for the emergency remount stuff */
 #include <linux/idr.h>
+#include <linux/kevent.h>
 #include <asm/uaccess.h>

@@ -875,8 +876,12 @@
                        up_write(&s->s_umount);
                        deactivate_super(s);
                        s = ERR_PTR(error);
-               } else
+               } else {
                        s->s_flags |= MS_ACTIVE;
+                       if (bdev->bd_disk)
+                               send_kevent(KEVENT_FS, NULL,
+                                           &bdev->bd_disk->kobj, "mount");
+               }
        }

        return s;
@@ -891,6 +896,10 @@
 void kill_block_super(struct super_block *sb)
 {
        struct block_device *bdev = sb->s_bdev;
+
+       if (bdev->bd_disk)
+               send_kevent(KEVENT_FS, NULL, &bdev->bd_disk->kobj, "umount");
+
        generic_shutdown_super(sb);
        set_blocksize(bdev, sb->s_old_blocksize);
        close_bdev_excl(bdev);
diff -urN linux-2.6.9-rc1-mm2/include/linux/kevent.h linux/include/linux/kevent.h
--- linux-2.6.9-rc1-mm2/include/linux/kevent.h  1969-12-31 19:00:00.000000000 -0500
+++ linux/include/linux/kevent.h        2004-08-31 16:21:05.706364128 -0400
@@ -0,0 +1,42 @@
+#ifndef _LINUX_KEVENT_H
+#define _LINUX_KEVENT_H
+
+#include <linux/config.h>
+#include <linux/kobject.h>
+
+/* kevent types - these are used as the multicast group */
+enum kevent {
+       KEVENT_GENERAL  =       0,
+       KEVENT_STORAGE  =       1,
+       KEVENT_POWER    =       2,
+       KEVENT_FS       =       3,
+       KEVENT_HOTPLUG  =       4,
+};
+
+#ifdef __KERNEL__
+#ifdef CONFIG_KERNEL_EVENTS
+
+int send_kevent(enum kevent type, struct kset *kset,
+               struct kobject *kobj, const char *signal);
+
+int send_kevent_atomic(enum kevent type, struct kset *kset,
+                      struct kobject *kobj, const char *signal);
+
+#else
+
+static inline int send_kevent(enum kevent type, struct kset *kset,
+                             struct kobject *kobj, const char *signal)
+{
+       return 0;
+}
+
+static inline int send_kevent_atomic(enum kevent type, struct kset *kset,
+                                    struct kobject *kobj, const char *signal)
+{
+       return 0;
+}
+
+#endif /* CONFIG_KERNEL_EVENTS */
+#endif /* __KERNEL__ */
+
+#endif /* _LINUX_KEVENT_H */
diff -urN linux-2.6.9-rc1-mm2/include/linux/netlink.h linux/include/linux/netlink.h
--- linux-2.6.9-rc1-mm2/include/linux/netlink.h 2004-08-31 16:46:16.316716448 -0400
+++ linux/include/linux/netlink.h       2004-08-31 16:44:41.372150216 -0400
@@ -17,6 +17,7 @@
 #define NETLINK_ROUTE6         11      /* af_inet6 route comm channel */
 #define NETLINK_IP6_FW         13
 #define NETLINK_DNRTMSG                14      /* DECnet routing messages */
+#define NETLINK_KEVENT         15      /* Kernel messages to userspace */
 #define NETLINK_TAPBASE                16      /* 16 to 31 are ethertap */

 #define MAX_LINKS 32          
diff -urN linux-2.6.9-rc1-mm2/init/Kconfig linux/init/Kconfig
--- linux-2.6.9-rc1-mm2/init/Kconfig    2004-08-31 16:46:16.454695472 -0400
+++ linux/init/Kconfig  2004-08-31 16:44:41.445139120 -0400
@@ -149,6 +149,20 @@
          logging of avc messages output).  Does not do system-call
          auditing without CONFIG_AUDITSYSCALL.

+config KERNEL_EVENTS
+       bool "Kernel Events Layer"
+       depends on NET
+       default y
+       help
+         This option enables the kernel events layer, which is a simple
+         mechanism for kernel-to-user communication over a netlink socket.
+         The goal of the kernel events layer is to provide a simple and
+         efficient logging, error, and events system.  Specifically, code
+         is available to link the events into D-BUS.  Say Y, unless you
+         are building a system requiring minimal memory consumption.
+
+         D-BUS is available at http://dbus.freedesktop.org/
+
 config AUDITSYSCALL
        bool "Enable system-call auditing support"
        depends on AUDIT && (X86 || PPC64 || ARCH_S390 || IA64)
diff -urN linux-2.6.9-rc1-mm2/kernel/kevent.c linux/kernel/kevent.c
--- linux-2.6.9-rc1-mm2/kernel/kevent.c 1969-12-31 19:00:00.000000000 -0500
+++ linux/kernel/kevent.c       2004-08-31 16:20:00.280310400 -0400
@@ -0,0 +1,105 @@
+/*
+ * kernel/kevent.c - sysfs event delivery via netlink socket
+ *
+ * Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2004 Novell, Inc.  All rights reserved.
+ *
+ * Licensed under the GNU GPL v2.
+ *
+ * Authors:
+ *     Robert Love             <r...@novell.com>
+ *     Kay Sievers             <kay.siev...@vrfy.org>
+ *     Arjan van de Ven        <arj...@redhat.com>
+ */
+
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/socket.h>
+#include <linux/skbuff.h>
+#include <linux/netlink.h>
+#include <linux/string.h>
+#include <linux/kobject.h>
+#include <linux/kevent.h>
+#include <net/sock.h>
+
+static struct sock *kevent_sock = NULL;        /* kevent's global netlink socket */
+
+/**
+ * send_kevent - send a message to user-space via the kernel events layer
+ */
+static int do_send_kevent(enum kevent type, int gfp_mask,
+                         const char *object, const char *signal)
+{
+       struct sk_buff *skb;
+       char *buffer;
+       int len;
+
+       if (!kevent_sock)
+               return -EIO;
+
+       if (!object || !signal)
+               return -EINVAL;
+
+       len = strlen(object) + 1 + strlen(signal);
+
+       skb = alloc_skb(len, gfp_mask);
+       if (!skb)
+               return -ENOMEM;
+
+       buffer = skb_put(skb, len);
+
+       sprintf(buffer, "%s\n%s", object, signal);
+
+       return netlink_broadcast(kevent_sock, skb, 0, (1 << type), gfp_mask);
+}
+
+int send_kevent(enum kevent type, struct kset *kset,
+               struct kobject *kobj, const char *signal)
+{
+       const char *path;
+       int ret;
+
+       path = kobject_get_path(kset, kobj, GFP_KERNEL);
+       if (!path)
+               return -ENOMEM;
+
+       ret =  do_send_kevent(type, GFP_KERNEL, path, signal);
+       kfree(path);
+
+       return ret;
+}
+
+EXPORT_SYMBOL_GPL(send_kevent);
+
+int send_kevent_atomic(enum kevent type, struct kset *kset,
+                      struct kobject *kobj, const char *signal)
+{
+       const char *path;
+       int ret;
+
+       path = kobject_get_path(kset, kobj, GFP_ATOMIC);
+       if (!path)
+               return -ENOMEM;
+
+       ret =  do_send_kevent(type, GFP_ATOMIC, path, signal);
+       kfree(path);
+
+       return ret;
+}
+
+EXPORT_SYMBOL_GPL(send_kevent_atomic);
+
+static int kevent_init(void)
+{
+       kevent_sock = netlink_kernel_create(NETLINK_KEVENT, NULL);
+
+       if (!kevent_sock) {
+               printk(KERN_ERR
+                      "kevent: unable to create netlink socket!\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+module_init(kevent_init);
diff -urN linux-2.6.9-rc1-mm2/kernel/Makefile linux/kernel/Makefile
--- linux-2.6.9-rc1-mm2/kernel/Makefile 2004-08-31 16:46:16.471692888 -0400
+++ linux/kernel/Makefile       2004-08-31 16:45:49.025865288 -0400
@@ -27,6 +27,7 @@
 obj-$(CONFIG_AUDIT) += audit.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KERNEL_EVENTS) += kevent.o

 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <a...@linuxcare.com.au>, the -fno-omit-frame-pointer is

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Morton  
View profile  
 More options Aug 31 2004, 6:04 pm
Newsgroups: fa.linux.kernel
From: Andrew Morton <a...@osdl.org>
Date: Tue, 31 Aug 2004 22:04:54 GMT
Local: Tues, Aug 31 2004 6:04 pm
Subject: Re: [patch] kernel sysfs events layer

Robert Love <r...@ximian.com> wrote:

> +  len = strlen(object) + 1 + strlen(signal);
> +
> +  skb = alloc_skb(len, gfp_mask);
> +  if (!skb)
> +          return -ENOMEM;
> +
> +  buffer = skb_put(skb, len);
> +
> +  sprintf(buffer, "%s\n%s", object, signal);

Buffer overrun, methinks.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Aug 31 2004, 6:11 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Tue, 31 Aug 2004 22:11:49 GMT
Local: Tues, Aug 31 2004 6:11 pm
Subject: Re: [patch] kernel sysfs events layer

On Tue, 2004-08-31 at 15:00 -0700, Andrew Morton wrote:
> Why not share the implementation here?

Because we will probably want to export do_send_kevent(), with a
different name, if this thing starts getting used, because there are
places where the kobj path is already computed and although inexpensive
it does cost a few cycles to go kobject -> path as a string.

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Aug 31 2004, 6:14 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Tue, 31 Aug 2004 22:14:27 GMT
Local: Tues, Aug 31 2004 6:14 pm
Subject: Re: [patch] kernel sysfs events layer

On Tue, 2004-08-31 at 14:58 -0700, Chris Wedgwood wrote:
> I *still* thinking putting all the possible messages into something
> like include/linux/kevent_msg.h is a good idea to prevent people
> creating all sorts of stupid ad-hoc messages over time that userspace
> will ineviitably not be able to track....

I still agree, but since that does not change the API (I'd still want
the signal to be a string) that bit can come later when there are real
users.  Or I will take a patch now. ;-)

Since we ditched the payload, the only thing left is the signal, which
is going to be "changed" half the time anyhow.

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Aug 31 2004, 6:20 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Tue, 31 Aug 2004 22:20:03 GMT
Local: Tues, Aug 31 2004 6:20 pm
Subject: Re: [patch] kernel sysfs events layer

On Tue, 2004-08-31 at 15:06 -0700, Andrew Morton wrote:
> Robert Love <r...@ximian.com> wrote:

> >       -       len = strlen(object) + 1 + strlen(signal);
> >       +       len = strlen(object) + 1 + strlen(signal) + 1;

> > should fix it, right?

Attached.

        Robert Love

Kernel Events Layer.  A simple sysfs change notifier over netlink.
Signed-Off-By: Robert Love <r...@novell.com>

 fs/super.c              |   11 ++++-
 include/linux/kevent.h  |   42 +++++++++++++++++++
 include/linux/netlink.h |    1
 init/Kconfig            |   14 ++++++
 kernel/Makefile         |    1
 kernel/kevent.c         |  105 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 173 insertions(+), 1 deletion(-)

diff -urN linux-2.6.9-rc1-mm2/fs/super.c linux/fs/super.c
--- linux-2.6.9-rc1-mm2/fs/super.c      2004-08-31 16:46:15.912777856 -0400
+++ linux/fs/super.c    2004-08-31 16:44:41.023203264 -0400
@@ -35,6 +35,7 @@
 #include <linux/vfs.h>
 #include <linux/writeback.h>             /* for the emergency remount stuff */
 #include <linux/idr.h>
+#include <linux/kevent.h>
 #include <asm/uaccess.h>

@@ -875,8 +876,12 @@
                        up_write(&s->s_umount);
                        deactivate_super(s);
                        s = ERR_PTR(error);
-               } else
+               } else {
                        s->s_flags |= MS_ACTIVE;
+                       if (bdev->bd_disk)
+                               send_kevent(KEVENT_FS, NULL,
+                                           &bdev->bd_disk->kobj, "mount");
+               }
        }

        return s;
@@ -891,6 +896,10 @@
 void kill_block_super(struct super_block *sb)
 {
        struct block_device *bdev = sb->s_bdev;
+
+       if (bdev->bd_disk)
+               send_kevent(KEVENT_FS, NULL, &bdev->bd_disk->kobj, "umount");
+
        generic_shutdown_super(sb);
        set_blocksize(bdev, sb->s_old_blocksize);
        close_bdev_excl(bdev);
diff -urN linux-2.6.9-rc1-mm2/include/linux/kevent.h linux/include/linux/kevent.h
--- linux-2.6.9-rc1-mm2/include/linux/kevent.h  1969-12-31 19:00:00.000000000 -0500
+++ linux/include/linux/kevent.h        2004-08-31 16:21:05.706364128 -0400
@@ -0,0 +1,42 @@
+#ifndef _LINUX_KEVENT_H
+#define _LINUX_KEVENT_H
+
+#include <linux/config.h>
+#include <linux/kobject.h>
+
+/* kevent types - these are used as the multicast group */
+enum kevent {
+       KEVENT_GENERAL  =       0,
+       KEVENT_STORAGE  =       1,
+       KEVENT_POWER    =       2,
+       KEVENT_FS       =       3,
+       KEVENT_HOTPLUG  =       4,
+};
+
+#ifdef __KERNEL__
+#ifdef CONFIG_KERNEL_EVENTS
+
+int send_kevent(enum kevent type, struct kset *kset,
+               struct kobject *kobj, const char *signal);
+
+int send_kevent_atomic(enum kevent type, struct kset *kset,
+                      struct kobject *kobj, const char *signal);
+
+#else
+
+static inline int send_kevent(enum kevent type, struct kset *kset,
+                             struct kobject *kobj, const char *signal)
+{
+       return 0;
+}
+
+static inline int send_kevent_atomic(enum kevent type, struct kset *kset,
+                                    struct kobject *kobj, const char *signal)
+{
+       return 0;
+}
+
+#endif /* CONFIG_KERNEL_EVENTS */
+#endif /* __KERNEL__ */
+
+#endif /* _LINUX_KEVENT_H */
diff -urN linux-2.6.9-rc1-mm2/include/linux/netlink.h linux/include/linux/netlink.h
--- linux-2.6.9-rc1-mm2/include/linux/netlink.h 2004-08-31 16:46:16.316716448 -0400
+++ linux/include/linux/netlink.h       2004-08-31 16:44:41.372150216 -0400
@@ -17,6 +17,7 @@
 #define NETLINK_ROUTE6         11      /* af_inet6 route comm channel */
 #define NETLINK_IP6_FW         13
 #define NETLINK_DNRTMSG                14      /* DECnet routing messages */
+#define NETLINK_KEVENT         15      /* Kernel messages to userspace */
 #define NETLINK_TAPBASE                16      /* 16 to 31 are ethertap */

 #define MAX_LINKS 32          
diff -urN linux-2.6.9-rc1-mm2/init/Kconfig linux/init/Kconfig
--- linux-2.6.9-rc1-mm2/init/Kconfig    2004-08-31 16:46:16.454695472 -0400
+++ linux/init/Kconfig  2004-08-31 16:44:41.445139120 -0400
@@ -149,6 +149,20 @@
          logging of avc messages output).  Does not do system-call
          auditing without CONFIG_AUDITSYSCALL.

+config KERNEL_EVENTS
+       bool "Kernel Events Layer"
+       depends on NET
+       default y
+       help
+         This option enables the kernel events layer, which is a simple
+         mechanism for kernel-to-user communication over a netlink socket.
+         The goal of the kernel events layer is to provide a simple and
+         efficient logging, error, and events system.  Specifically, code
+         is available to link the events into D-BUS.  Say Y, unless you
+         are building a system requiring minimal memory consumption.
+
+         D-BUS is available at http://dbus.freedesktop.org/
+
 config AUDITSYSCALL
        bool "Enable system-call auditing support"
        depends on AUDIT && (X86 || PPC64 || ARCH_S390 || IA64)
diff -urN linux-2.6.9-rc1-mm2/kernel/kevent.c linux/kernel/kevent.c
--- linux-2.6.9-rc1-mm2/kernel/kevent.c 1969-12-31 19:00:00.000000000 -0500
+++ linux/kernel/kevent.c       2004-08-31 16:20:00.280310400 -0400
@@ -0,0 +1,105 @@
+/*
+ * kernel/kevent.c - sysfs event delivery via netlink socket
+ *
+ * Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2004 Novell, Inc.  All rights reserved.
+ *
+ * Licensed under the GNU GPL v2.
+ *
+ * Authors:
+ *     Robert Love             <r...@novell.com>
+ *     Kay Sievers             <kay.siev...@vrfy.org>
+ *     Arjan van de Ven        <arj...@redhat.com>
+ */
+
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/socket.h>
+#include <linux/skbuff.h>
+#include <linux/netlink.h>
+#include <linux/string.h>
+#include <linux/kobject.h>
+#include <linux/kevent.h>
+#include <net/sock.h>
+
+static struct sock *kevent_sock = NULL;        /* kevent's global netlink socket */
+
+/**
+ * send_kevent - send a message to user-space via the kernel events layer
+ */
+static int do_send_kevent(enum kevent type, int gfp_mask,
+                         const char *object, const char *signal)
+{
+       struct sk_buff *skb;
+       char *buffer;
+       int len;
+
+       if (!kevent_sock)
+               return -EIO;
+
+       if (!object || !signal)
+               return -EINVAL;
+
+       len = strlen(object) + 1 + strlen(signal) + 1;
+
+       skb = alloc_skb(len, gfp_mask);
+       if (!skb)
+               return -ENOMEM;
+
+       buffer = skb_put(skb, len);
+
+       sprintf(buffer, "%s\n%s", object, signal);
+
+       return netlink_broadcast(kevent_sock, skb, 0, (1 << type), gfp_mask);
+}
+
+int send_kevent(enum kevent type, struct kset *kset,
+               struct kobject *kobj, const char *signal)
+{
+       const char *path;
+       int ret;
+
+       path = kobject_get_path(kset, kobj, GFP_KERNEL);
+       if (!path)
+               return -ENOMEM;
+
+       ret =  do_send_kevent(type, GFP_KERNEL, path, signal);
+       kfree(path);
+
+       return ret;
+}
+
+EXPORT_SYMBOL_GPL(send_kevent);
+
+int send_kevent_atomic(enum kevent type, struct kset *kset,
+                      struct kobject *kobj, const char *signal)
+{
+       const char *path;
+       int ret;
+
+       path = kobject_get_path(kset, kobj, GFP_ATOMIC);
+       if (!path)
+               return -ENOMEM;
+
+       ret =  do_send_kevent(type, GFP_ATOMIC, path, signal);
+       kfree(path);
+
+       return ret;
+}
+
+EXPORT_SYMBOL_GPL(send_kevent_atomic);
+
+static int kevent_init(void)
+{
+       kevent_sock = netlink_kernel_create(NETLINK_KEVENT, NULL);
+
+       if (!kevent_sock) {
+               printk(KERN_ERR
+                      "kevent: unable to create netlink socket!\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+module_init(kevent_init);
diff -urN linux-2.6.9-rc1-mm2/kernel/Makefile linux/kernel/Makefile
--- linux-2.6.9-rc1-mm2/kernel/Makefile 2004-08-31 16:46:16.471692888 -0400
+++ linux/kernel/Makefile       2004-08-31 16:45:49.025865288 -0400
@@ -27,6 +27,7 @@
 obj-$(CONFIG_AUDIT) += audit.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KERNEL_EVENTS) += kevent.o

 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <a...@linuxcare.com.au>, the -fno-omit-frame-pointer is

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Morton  
View profile  
 More options Aug 31 2004, 6:27 pm
Newsgroups: fa.linux.kernel
From: Andrew Morton <a...@osdl.org>
Date: Tue, 31 Aug 2004 22:27:59 GMT
Local: Tues, Aug 31 2004 6:27 pm
Subject: Re: [patch] kernel sysfs events layer

Robert Love <r...@ximian.com> wrote:

> On Tue, 2004-08-31 at 15:00 -0700, Andrew Morton wrote:

> > Why not share the implementation here?

> Because we will probably want to export do_send_kevent(), with a
> different name, if this thing starts getting used, because there are
> places where the kobj path is already computed and although inexpensive
> it does cost a few cycles to go kobject -> path as a string.

That's unrelated.   I meant:

static int __send_kevent(enum kevent type, struct kset *kset,
                struct kobject *kobj, const char *signal, int gfp_flags)
{
        const char *path;
        int ret;

        path = kobject_get_path(kset, kobj, gfp_flags);
        if (!path)
                return -ENOMEM;

        ret =  do_send_kevent(type, gfp_flags, path, signal);
        kfree(path);

        return ret;

}

int send_kevent(enum kevent type, struct kset *kset,
                struct kobject *kobj, const char *signal)
{
        return __send_kevent(type, kset, kobj, signal, GFP_KERNEL);
}

EXPORT_SYMBOL_GPL(send_kevent);

int send_kevent_atomic(enum kevent type, struct kset *kset,
                struct kobject *kobj, const char *signal)
{
        return __send_kevent(type, kset, kobj, signal, GFP_ATOMIC);

}

EXPORT_SYMBOL_GPL(send_kevent_atomic);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Aug 31 2004, 6:48 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Tue, 31 Aug 2004 22:48:09 GMT
Local: Tues, Aug 31 2004 6:48 pm
Subject: Re: [patch] kernel sysfs events layer

On Tue, 2004-08-31 at 15:10 -0700, Andrew Morton wrote:
> That's unrelated.   I meant:

Not unrelated - if it were not the case, I'd see your point.  But, ugh,
add another level of redirection to save the duplication of three lines?

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Aug 31 2004, 7:47 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Tue, 31 Aug 2004 23:47:16 GMT
Local: Tues, Aug 31 2004 7:47 pm
Subject: Re: [patch] kernel sysfs events layer

On Tue, 2004-08-31 at 14:56 -0700, Andrew Morton wrote:
> Robert Love <r...@ximian.com> wrote:

> > +     len = strlen(object) + 1 + strlen(signal);
> > +
> > +     skb = alloc_skb(len, gfp_mask);
> > +     if (!skb)
> > +             return -ENOMEM;
> > +
> > +     buffer = skb_put(skb, len);
> > +
> > +     sprintf(buffer, "%s\n%s", object, signal);

> Buffer overrun, methinks.

Hrm, but len is the right size...

Oh, missing the NULL, eh?

So

        -       len = strlen(object) + 1 + strlen(signal);
        +       len = strlen(object) + 1 + strlen(signal) + 1;

should fix it, right?

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Stekloff  
View profile  
 More options Aug 31 2004, 10:13 pm
Newsgroups: fa.linux.kernel
From: Daniel Stekloff <dstek...@us.ibm.com>
Date: Wed, 1 Sep 2004 02:13:06 GMT
Local: Tues, Aug 31 2004 10:13 pm
Subject: Re: [patch] kernel sysfs events layer

Hi Robert,

Are you limiting the kernel event mechanism a little too much by getting
rid of the payload? Wouldn't it be useful to sometimes have data at
event time?

Thanks,

Dan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kay Sievers  
View profile  
 More options Sep 1 2004, 6:14 am
Newsgroups: fa.linux.kernel
From: Kay Sievers <kay.siev...@vrfy.org>
Date: Wed, 1 Sep 2004 10:14:45 GMT
Local: Wed, Sep 1 2004 6:14 am
Subject: Re: [patch] kernel sysfs events layer

The motivation for doing this, is the ambitioned idea, that _data_ should
only be exposed through sysfs values to userspace. This would make it
possible for userspace to scan any state at any time, regardless of a
received event. Which should make the whole setup more reliable, as
applications can just read in the state at startup. We do a similar job
with udevstart, as all lost hotplug events during the early boot are
recovered just by reading sysfs and synthesize these events for creating
device nodes.

The same applies to the way back to the kernel. We don't want to send
data over the netlink back to the kernel, we can write to sysfs.

Very "simple" data still can be specified by the signal string, just
like a "verb" that describes, what actually happened with the kobject.
In the mount case, we send a "mount/unmount" event for the physical
device, and userspace can read "/proc/mounts" for the data, as
applications do today by polling.
Another version to do this (similar to Robert's CPU overheating example
above), is to create a owner value in the blockdevice's kset and let the
device claiming code fill that value. Then the signal may just be a simple
"add/remove" event for the "owner" file at device claiming and release.

Yes, it may require, that some things in the kernel need to use kobjects
to represent it's state to userspace, but that is a nice side effect and
better than a complicated definition, what the event may carry ot of the
kernel with every specific event, I think.

If you can think of any case we can't expose enough data with this model
or we will not be able to use sysfs, let us know.

Thanks,
Kay

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg KH  
View profile  
 More options Sep 2 2004, 4:39 am
Newsgroups: fa.linux.kernel
From: Greg KH <g...@kroah.com>
Date: Thu, 2 Sep 2004 08:39:12 GMT
Local: Thurs, Sep 2 2004 4:39 am
Subject: Re: [patch] kernel sysfs events layer

On Tue, Aug 31, 2004 at 06:05:24PM -0400, Robert Love wrote:
> +int send_kevent(enum kevent type, struct kset *kset,
> +          struct kobject *kobj, const char *signal);

Why is the kset needed?  We can determine that from the kobject.

How about changing this to:
        int send_kevent(struct kobject *kobj, struct attribute *attr);
which just tells userspace that a specific attribute needs to be read,
as something "important" has changed.

Will passing the attribute name be able to successfully handle the
"enum kevent" and "signal" combinations?

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Stekloff  
View profile  
 More options Sep 2 2004, 8:06 am
Newsgroups: fa.linux.kernel
From: Daniel Stekloff <dstek...@us.ibm.com>
Date: Thu, 2 Sep 2004 12:06:54 GMT
Local: Thurs, Sep 2 2004 8:06 am
Subject: Re: [patch] kernel sysfs events layer

On Thu, 2004-09-02 at 01:34, Greg KH wrote:
> On Tue, Aug 31, 2004 at 06:05:24PM -0400, Robert Love wrote:
> > +int send_kevent(enum kevent type, struct kset *kset,
> > +             struct kobject *kobj, const char *signal);

> Why is the kset needed?  We can determine that from the kobject.

> How about changing this to:
>    int send_kevent(struct kobject *kobj, struct attribute *attr);
> which just tells userspace that a specific attribute needs to be read,
> as something "important" has changed.

Do all events require an attribute? What about the "overheating"
example? Would you need an attribute or would getting a "signal" for a
specific kobj be enough?

Binding an attribute to an event would at least tell you the name of the
attribute to check. Otherwise, how does an app know the name of the
attribute that changed? Or am I missing something?

Thanks,

Dan

> Will passing the attribute name be able to successfully handle the
> "enum kevent" and "signal" combinations?

> thanks,

> greg k-h
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kay Sievers  
View profile  
 More options Sep 2 2004, 8:50 am
Newsgroups: fa.linux.kernel
From: Kay Sievers <kay.siev...@vrfy.org>
Date: Thu, 2 Sep 2004 12:50:18 GMT
Local: Thurs, Sep 2 2004 8:50 am
Subject: Re: [patch] kernel sysfs events layer

On Thu, Sep 02, 2004 at 10:34:08AM +0200, Greg KH wrote:
> On Tue, Aug 31, 2004 at 06:05:24PM -0400, Robert Love wrote:
> > +int send_kevent(enum kevent type, struct kset *kset,
> > +             struct kobject *kobj, const char *signal);

> Why is the kset needed?  We can determine that from the kobject.

I expect it's because:
  fill_kobj_path(struct kset *kset, struct kobject *kobj, char *path, int length)
  get_kobj_path_length(struct kset *kset, struct kobject *kobj)

and therefore the exported:
  kobject_get_path(struct kset *kset, struct kobject *kobj, int gfp_mask)

are all passing the kset. If they all are not needed, they can go too?

> How about changing this to:
>    int send_kevent(struct kobject *kobj, struct attribute *attr);
> which just tells userspace that a specific attribute needs to be read,
> as something "important" has changed.

Hmm, in most cases this will work. But in mandates the creation of an
attribute instead of the lazy signal string. Yes, it would be nicer in
the long run and closer to the idea, that the whole event data should be
available through sysfs, but it may be hard to reach this in some subsystems.

> Will passing the attribute name be able to successfully handle the
> "enum kevent" and "signal" combinations?

What should we do in the hotplug case? We may send a NULL attr for
the kset creation. But how can we distinguish between "add" and "remove"?
Just by looking if we find the sysfs dir? I'm not sure in this case.

Any ideas?

Thanks,
Kay
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kay Sievers  
View profile  
 More options Sep 2 2004, 9:27 am
Newsgroups: fa.linux.kernel
From: Kay Sievers <kay.siev...@vrfy.org>
Date: Thu, 2 Sep 2004 13:27:55 GMT
Local: Thurs, Sep 2 2004 9:27 am
Subject: Re: [patch] kernel sysfs events layer

Hmm, both can be the case at the moment. We need to decide, if we want to
mandate the use of a sysfs attribute instead of the string value as the signal.

> Binding an attribute to an event would at least tell you the name of the
> attribute to check. Otherwise, how does an app know the name of the
> attribute that changed? Or am I missing something?

That's a valid point, right. If we don't use "verbs" as the signal string,
and know what we can expect from that particular kind of event, we don't
know which attribute has changed.

The remaining questions are:

o Do we want the multicast - "channels" for the events? It may be nice, to
  have it, if a application only interested in e.g. hotplug events, can get
  only the interesting events?

o What kind of signal do we need? A lazy string, a well defined set like
  ADD/REMOVE/CHANGE?
  Or can we get rid of the whole signal? But how can we distinguish between
  add and remove? Watching if the sysfs file comes or goes is not a option,
  I think.

Thanks,
Kay
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Sep 2 2004, 12:29 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Thu, 2 Sep 2004 16:29:42 GMT
Local: Thurs, Sep 2 2004 12:29 pm
Subject: Re: [patch] kernel sysfs events layer

On Thu, 2004-09-02 at 10:34 +0200, Greg KH wrote:
> Why is the kset needed?  We can determine that from the kobject.

> How about changing this to:
>    int send_kevent(struct kobject *kobj, struct attribute *attr);
> which just tells userspace that a specific attribute needs to be read,
> as something "important" has changed.

> Will passing the attribute name be able to successfully handle the
> "enum kevent" and "signal" combinations?

We can drop the kset if you say we never need it.  Why do all the kobj
get_path functions take a kset then?  That is what confused me.

We can also drop the "enum kevent" if we decide we don't want to take
advantage of the multicasting of the netlink socket.  The enum defines
what multicast group the netlink message is sent out in.  I actually
have been talking to Kay about ditching it, and we are trying to figure
out if we ever _need_ it.

So that is 2 for 2.  But ...

I don't dig replacing the signal string with an attribute.  I think it
will really limit what we can do - having the signal as a verb
describing the event is really important.  We might also not always have
an attribute.  Kay's points are all valid.

So what if we had

        int send_kevent(struct kobject *kobj, const char *signal);

Which was a way of notifying user-space of a change of "signal" on the
object "kobj" in sysfs.

If we ever wanted to send an attribute, we can do something like

        const char *signal;

        signal = attribute_to_string(attribute);
        send_kevent(kobj, signal);
        kfree(signal);

Dig that?

Best,

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Sep 2 2004, 12:33 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Thu, 2 Sep 2004 16:33:03 GMT
Local: Thurs, Sep 2 2004 12:33 pm
Subject: Re: [patch] kernel sysfs events layer

On Thu, 2004-09-02 at 15:26 +0200, Kay Sievers wrote:
> o What kind of signal do we need? A lazy string, a well defined set like
>   ADD/REMOVE/CHANGE?
>   Or can we get rid of the whole signal? But how can we distinguish between
>   add and remove? Watching if the sysfs file comes or goes is not a option,
>   I think.

I think (from our off-list discussions) that we really need the signal.
Agreed?

I do think that defining the signal to specific values makes sense, e.g.
KEVENT_ADD, KEVENT_REMOVE, KEVENT_MOUNTED, etc.  We could also send the
attribute as a string.

To get around the hotplug issue that would occur without 'enum kevent',
as we discussed, we could have a "hotplug_added" signal or whatever.
Nothing wrong with that.

Cool or not?

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Stekloff  
View profile  
 More options Sep 2 2004, 2:37 pm
Newsgroups: fa.linux.kernel
From: Daniel Stekloff <dstek...@us.ibm.com>
Date: Thu, 2 Sep 2004 18:37:39 GMT
Local: Thurs, Sep 2 2004 2:37 pm
Subject: Re: [patch] kernel sysfs events layer

The only problem I see is making an app sift through all of the events
to get to a specific type of event. They'd have to parse and match the
signal, that could be costly.

Will there be small single purpose applications listening on the netlink
socket or off dbus for specific signals? Or do you see this mainly
handled by a single kevent daemon?

I thought you wanted to standardize the signals? Would you have a
delimiter in your signal to have a standard prefix to use to identify
the string in User Space?

Why not add the attribute name to the path you get from the kobj?

send_attribute_kevent(kobj, attr->name, signal);

and

send_kevent(kobj, signal);

Thanks,

Dan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Sep 2 2004, 2:43 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Thu, 2 Sep 2004 18:43:16 GMT
Local: Thurs, Sep 2 2004 2:43 pm
Subject: Re: [patch] kernel sysfs events layer

On Thu, 2004-09-02 at 11:35 -0700, Daniel Stekloff wrote:
> The only problem I see is making an app sift through all of the events
> to get to a specific type of event. They'd have to parse and match the
> signal, that could be costly.

I'd hope that they were not that many events that it would ever be
costly.

But this should be mitigated by your event aggregator in user-space,
whether that is D-BUS or whatever else.  If it is D-BUS, you could then
subscribe via D-BUS only to the events you care about.

> Will there be small single purpose applications listening on the netlink
> socket or off dbus for specific signals? Or do you see this mainly
> handled by a single kevent daemon?

Whatever you want to do.

I think they way we would set up our Linux desktop product would have D-
BUS listening on the kevent socket and propagating the events up the
stack (or have a separate daemon listen and funnel the events to D-BUS.
whatever).

Then applications up the stack would respond to and handle the D-BUS
signals.

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Stekloff  
View profile  
 More options Sep 2 2004, 4:53 pm
Newsgroups: fa.linux.kernel
From: Daniel Stekloff <dstek...@us.ibm.com>
Date: Thu, 2 Sep 2004 20:53:59 GMT
Local: Thurs, Sep 2 2004 4:53 pm
Subject: Re: [patch] kernel sysfs events layer
On Wed, 2004-09-01 at 03:07, Kay Sievers wrote:

[snip]

> The motivation for doing this, is the ambitioned idea, that _data_ should
> only be exposed through sysfs values to userspace. This would make it
> possible for userspace to scan any state at any time, regardless of a
> received event. Which should make the whole setup more reliable, as
> applications can just read in the state at startup. We do a similar job
> with udevstart, as all lost hotplug events during the early boot are
> recovered just by reading sysfs and synthesize these events for creating
> device nodes.

> The same applies to the way back to the kernel. We don't want to send
> data over the netlink back to the kernel, we can write to sysfs.

Ok.. so if I wanted to send an event (that included data at event time)
from a driver for a particular device, I would send the event with the
send_kevent() call and create and maintain an attribute for that
specific event. In order for an application to receive the data for the
event, the driver would need to store the data for that event somewhere
and keep it. Unless there's a write attribute to tell me it's been read,
I must maintain it or write over it if the same event occurs again.

Is this how it's supposed to work?

Even though 1) there won't be many events and 2) few events will include
data - don't you think this is a bit too much development overhead for
the driver?

If you had the payload with the event, you could fire and forget. It
would be fewer steps for the driver and require less management and
storage.

Thanks,

Dan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kay Sievers  
View profile  
 More options Sep 2 2004, 6:27 pm
Newsgroups: fa.linux.kernel
From: Kay Sievers <kay.siev...@vrfy.org>
Date: Thu, 2 Sep 2004 22:27:34 GMT
Local: Thurs, Sep 2 2004 6:27 pm
Subject: Re: [patch] kernel sysfs events layer

No, the current version(idea) is mainly a sysfs/kobject notification,
not a data channel, or something that requires a more complicated logic.
(but, yes, your example applies to simple event sequence numbers too. We
can't expose these kind of "snapshot data" by a sysfs value).

> Even though 1) there won't be many events and 2) few events will include
> data - don't you think this is a bit too much development overhead for
> the driver?

> If you had the payload with the event, you could fire and forget. It
> would be fewer steps for the driver and require less management and
> storage.

There will be only very few cases for that, but some drivers will want
to send these kind of information to userspace (even binary blobs).

Don't know if this kind of data dump should be part of kevent or better
handled by something driver specific. It gets even more complicated, if
the userspace listener must interpret all these different data formats.

Maybe we just need to rename "kevent" to "kobject_notify" to make the
focus more clear :)

Thanks,
Kay

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Stekloff  
View profile  
 More options Sep 3 2004, 8:02 pm
Newsgroups: fa.linux.kernel
From: Daniel Stekloff <dstek...@us.ibm.com>
Date: Sat, 4 Sep 2004 00:02:07 GMT
Local: Fri, Sep 3 2004 8:02 pm
Subject: Re: [patch] kernel sysfs events layer
On Thu, 2004-09-02 at 15:15, Kay Sievers wrote:

[snip]

> Maybe we just need to rename "kevent" to "kobject_notify" to make the
> focus more clear :)

Thanks, Kay, for answering my questions.

I'm wondering if you've narrowed the interface too much in respect to
possible events. I'm interested in error event notification. My goal is
to work on creating common, consistent, and meaningful error messages or
notifications that can be easily understood or used to trigger events.
Possible responses to error messages - in User Space - could be to spit
out a more detailed error message to the console that includes possible
causes, possible actions, and the erroring device information (gathered
from HAL and/or sysfs) or to automatically launch a diagnostic.

While I'm currently more interested in the actual error events, I
thought I could take advantage of the proposed kevent interface because
parsing /var/log/messages is cumbersome. But now I'm not so sure.

I was thinking the send_kevent form that included the payload could be
put into dev_err() macros, so we didn't have to add yet another
interface to drivers. We could just patch dev_err(). I even thought we
could add a dev_event() for using specific events.

Now I'm wondering if this interface would be useful for error events.
Most error events don't require data at event time, but there are some
that do.

If you curious about the error events, I've started a list of actionable
error events that includes the current message string, possible causes,
and possible actions (it's a work in progress):

http://linux-diag.sourceforge.net/first_failure/FirstFailure.html

Thanks,
Dan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg KH  
View profile  
 More options Sep 4 2004, 3:53 am
Newsgroups: fa.linux.kernel
From: Greg KH <g...@kroah.com>
Date: Sat, 4 Sep 2004 07:53:45 GMT
Local: Sat, Sep 4 2004 3:53 am
Subject: Re: [patch] kernel sysfs events layer
Sorry, I'm at a conference, so email access is flaky at times...

On Thu, Sep 02, 2004 at 12:25:21PM -0400, Robert Love wrote:
> On Thu, 2004-09-02 at 10:34 +0200, Greg KH wrote:

> > Why is the kset needed?  We can determine that from the kobject.

> > How about changing this to:
> >       int send_kevent(struct kobject *kobj, struct attribute *attr);
> > which just tells userspace that a specific attribute needs to be read,
> > as something "important" has changed.

> > Will passing the attribute name be able to successfully handle the
> > "enum kevent" and "signal" combinations?

> We can drop the kset if you say we never need it.  Why do all the kobj
> get_path functions take a kset then?  That is what confused me.

Look at kobject_hotplug.  We can determine the kset assigned to a
kobject with the logic in that function.  Then we use the kset to get
the path and other good stuff that the hotplug call needs.

> We can also drop the "enum kevent" if we decide we don't want to take
> advantage of the multicasting of the netlink socket.  The enum defines
> what multicast group the netlink message is sent out in.  I actually
> have been talking to Kay about ditching it, and we are trying to figure
> out if we ever _need_ it.

Sounds fine to me.

> So that is 2 for 2.  But ...

> I don't dig replacing the signal string with an attribute.  I think it
> will really limit what we can do - having the signal as a verb
> describing the event is really important.  We might also not always have
> an attribute.  Kay's points are all valid.

> So what if we had

>    int send_kevent(struct kobject *kobj, const char *signal);

> Which was a way of notifying user-space of a change of "signal" on the
> object "kobj" in sysfs.

Ok, I'll accept that, and I like it, it's simple, and yet powerful for
pretty much everything we'll need in the future.

In fact, I like that type of function so much, I wrote it a few years
ago:
        void kobject_hotplug(const char *action, struct kobject *kobj)

You fell right into my trap :)

So, we're back to the original issue.  Why is this kernel event system
different from the hotplug system?  I would argue there isn't one,
becides the transport, as you seem to want everything that we currently
provide in the current kobject_hotplug() call.

But transports are important, I agree.

How about you just add the ability to send hotplug calls across netlink?
Make it so the kobject_hotplug() function does both the exec() call, and
a netlink call (based on a config option for those people who like to
configure such stuff.)

That way, programs who want to listen to netlink messages to get hotplug
events do so, and so does programs who want to do the /etc/hotplug.d/
type of notification?

Oh, and attributes.  How about we just change kobject_hotplug() to be:
        int kobject_hotplug(const char *action, struct kobject *kobj, struct attribute *attr);
and if we set attr to be a valid pointer, we make the DEVPATH paramater
contain the attribute name at the end of it.

I'd be glad to accept a patch that implements this.

Look acceptable?

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg KH  
View profile  
 More options Sep 4 2004, 4:16 am
Newsgroups: fa.linux.kernel
From: Greg KH <g...@kroah.com>
Date: Sat, 4 Sep 2004 08:16:44 GMT
Local: Sat, Sep 4 2004 4:16 am
Subject: Re: [patch] kernel sysfs events layer

On Fri, Sep 03, 2004 at 04:59:51PM -0700, Daniel Stekloff wrote:
> On Thu, 2004-09-02 at 15:15, Kay Sievers wrote:
> [snip]
> > Maybe we just need to rename "kevent" to "kobject_notify" to make the
> > focus more clear :)

> Thanks, Kay, for answering my questions.

> I'm wondering if you've narrowed the interface too much in respect to
> possible events. I'm interested in error event notification.

I don't think this "event notification" system should be used for error
event notification.  For errors, you want to never drop them, or want to
rely on userspace reading the sysfs attribute file in time before it
changes again.

And as my previous message shows, I think we just evolved back to the
current hotplug interface, which really isn't a good one for errors :)

> If you curious about the error events, I've started a list of actionable
> error events that includes the current message string, possible causes,
> and possible actions (it's a work in progress):

> http://linux-diag.sourceforge.net/first_failure/FirstFailure.html

That's a great start.  Hopefully it will help in figuring out what error
messages should be standardized on across drivers that belong to the
same class.

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kay Sievers  
View profile  
 More options Sep 4 2004, 10:20 pm
Newsgroups: fa.linux.kernel
From: Kay Sievers <kay.siev...@vrfy.org>
Date: Sun, 5 Sep 2004 02:20:24 GMT
Local: Sat, Sep 4 2004 10:20 pm
Subject: Re: [patch] kernel sysfs events layer

On Sat, Sep 04, 2004 at 02:54:33AM +0200, Greg KH wrote:

> How about you just add the ability to send hotplug calls across netlink?
> Make it so the kobject_hotplug() function does both the exec() call, and
> a netlink call (based on a config option for those people who like to
> configure such stuff.)

> That way, programs who want to listen to netlink messages to get hotplug
> events do so, and so does programs who want to do the /etc/hotplug.d/
> type of notification?

> Oh, and attributes.  How about we just change kobject_hotplug() to be:
>    int kobject_hotplug(const char *action, struct kobject *kobj, struct attribute *attr);
> and if we set attr to be a valid pointer, we make the DEVPATH paramater
> contain the attribute name at the end of it.

If we add this to the kobject_hotplug function, how do we prevent the
execution of /sbin/hotplug for ksets that have positive hotplug filters?
So I've created a new function for now:
  int kobj_notify(const char *signal, struct kobject *kobj, struct attribute *attr)

which can be used from the subsystems. This function is also called for
the normal /sbin/hotplug event. (The subsystems may provide a additional
environment for the /sbin/hotplug events, this is ignored by now.)

Here is the debug output of a simple listener, while inserting a
USB-memory-stick, mounting, unmounting and removing it:

  [root@pim kdbusd]# ./kdbusd
  main: [1094349091] 'add' from '/org/kernel/devices/pci0000:00/0000:00:1d.1/usb3/3-1'
  main: [1094349091] 'add' from '/org/kernel/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0'
  main: [1094349091] 'add' from '/org/kernel/class/scsi_host/host2'
  main: [1094349091] 'add' from '/org/kernel/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/host2/2:0:0:0 '
  main: [1094349091] 'add' from '/org/kernel/block/sda'
  main: [1094349091] 'add' from '/org/kernel/class/scsi_device/2:0:0:0'
  main: [1094349091] 'add' from '/org/kernel/class/scsi_generic/sg0'
  main: [1094349092] 'add' from '/org/kernel/block/sda/sda1'

  main: [1094349094] 'claim' from '/org/kernel/block/sda/sda1'
  main: [1094349101] 'release' from '/org/kernel/block/sda/sda1'

  main: [1094349106] 'remove' from '/org/kernel/class/scsi_generic/sg0'
  main: [1094349106] 'remove' from '/org/kernel/class/scsi_device/2:0:0:0'
  main: [1094349106] 'remove' from '/org/kernel/block/sda/sda1'
  main: [1094349106] 'remove' from '/org/kernel/block/sda'
  main: [1094349106] 'remove' from '/org/kernel/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/host2/2:0:0:0 '
  main: [1094349106] 'remove' from '/org/kernel/class/scsi_host/host2'
  main: [1094349106] 'remove' from '/org/kernel/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0'
  main: [1094349106] 'remove' from '/org/kernel/devices/pci0000:00/0000:00:1d.1/usb3/3-1'

Thanks,
Kay

[ knotify-07.patch 6K ]
diff -Nru a/fs/super.c b/fs/super.c
--- a/fs/super.c        2004-09-05 03:54:23 +02:00
+++ b/fs/super.c        2004-09-05 03:54:23 +02:00
@@ -35,6 +35,7 @@
 #include <linux/vfs.h>
 #include <linux/writeback.h>             /* for the emergency remount stuff */
 #include <linux/idr.h>
+#include <linux/kobj_notify.h>
 #include <asm/uaccess.h>

@@ -633,6 +634,16 @@
        return (void *)s->s_bdev == data;
 }

+static void notify_device_claim(const char *action, struct block_device *bdev)
+{
+       if (bdev->bd_disk) {
+               if (bdev->bd_part)
+                       kobj_notify(action, &bdev->bd_part->kobj, NULL);
+               else
+                       kobj_notify(action, &bdev->bd_disk->kobj, NULL);
+       }
+}
+
 struct super_block *get_sb_bdev(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *data,
        int (*fill_super)(struct super_block *, void *, int))
@@ -675,8 +686,10 @@
                        up_write(&s->s_umount);
                        deactivate_super(s);
                        s = ERR_PTR(error);
-               } else
+               } else {
                        s->s_flags |= MS_ACTIVE;
+                       notify_device_claim("claim", bdev);
+               }
        }

        return s;
@@ -691,6 +704,8 @@
 void kill_block_super(struct super_block *sb)
 {
        struct block_device *bdev = sb->s_bdev;
+
+       notify_device_claim("release", bdev);
        generic_shutdown_super(sb);
        set_blocksize(bdev, sb->s_old_blocksize);
        close_bdev_excl(bdev);
@@ -717,6 +732,7 @@
                return ERR_PTR(error);
        }
        s->s_flags |= MS_ACTIVE;
+
        return s;
 }

diff -Nru a/include/linux/kobj_notify.h b/include/linux/kobj_notify.h
--- /dev/null   Wed Dec 31 16:00:00 196900
+++ b/include/linux/kobj_notify.h       2004-09-05 03:54:23 +02:00
@@ -0,0 +1,31 @@
+#ifndef _KOBJ_NOTIFY_H_
+#define _KOBJ_NOTIFY_H_
+
+#ifdef __KERNEL__
+#ifdef CONFIG_KOBJ_NOTIFY
+
+extern int kobj_notify(const char *signal, struct kobject *kobj,
+                      struct attribute *attr);
+
+extern int kobj_notify_atomic(const char *signal, struct kobject *kobj,
+                             struct attribute *attr);
+
+#else
+
+static inline int kobj_notify(const char *signal, struct kobject *kobj,
+                      struct attribute *attr)
+{
+       return 0;
+}
+
+static inline int kobj_notify_atomic(const char *signal, struct kobject *kobj,
+                             struct attribute *attr)
+{
+       return 0;
+}
+
+
+#endif /* CONFIG_KOBJ_NOTIFY */
+#endif /* __KERNEL__ */
+
+#endif /* _KOBJ_NOTIFY_H_ */
diff -Nru a/include/linux/netlink.h b/include/linux/netlink.h
--- a/include/linux/netlink.h   2004-09-05 03:54:23 +02:00
+++ b/include/linux/netlink.h   2004-09-05 03:54:23 +02:00
@@ -17,6 +17,7 @@
 #define NETLINK_ROUTE6         11      /* af_inet6 route comm channel */
 #define NETLINK_IP6_FW         13
 #define NETLINK_DNRTMSG                14      /* DECnet routing messages */
+#define NETLINK_KOBJ_NOTIFY    15      /* Kernel messages to userspace */
 #define NETLINK_TAPBASE                16      /* 16 to 31 are ethertap */

 #define MAX_LINKS 32          
diff -Nru a/init/Kconfig b/init/Kconfig
--- a/init/Kconfig      2004-09-05 03:54:23 +02:00
+++ b/init/Kconfig      2004-09-05 03:54:23 +02:00
@@ -195,6 +195,21 @@
          agent" (/sbin/hotplug) to load modules and set up software needed
          to use devices as you hotplug them.

+config KOBJ_NOTIFY
+       bool "Kernel Events Layer"
+       depends on NET && HOTPLUG
+       default y
+       help
+         This option enables the kernel events layer, which is a simple
+         mechanism for kernel-to-user communication over a netlink socket.
+         The goal of the kernel events layer is to provide a simple and
+         efficient events system, that notifies userspace about kobject state
+         changes e.g. hotplug events, power state changes or block device
+         claiming (mount/unmount).
+
+         Say Y, unless you are building a system requiring minimal memory
+         consumption.
+
 config IKCONFIG
        bool "Kernel .config support"
        ---help---
diff -Nru a/kernel/Makefile b/kernel/Makefile
--- a/kernel/Makefile   2004-09-05 03:54:23 +02:00
+++ b/kernel/Makefile   2004-09-05 03:54:23 +02:00
@@ -24,6 +24,7 @@
 obj-$(CONFIG_AUDIT) += audit.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KOBJ_NOTIFY) += kobj_notify.o

 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <a...@linuxcare.com.au>, the -fno-omit-frame-pointer is
diff -Nru a/kernel/kobj_notify.c b/kernel/kobj_notify.c
--- /dev/null   Wed Dec 31 16:00:00 196900
+++ b/kernel/kobj_notify.c      2004-09-05 03:54:23 +02:00
@@ -0,0 +1,88 @@
+/*
+ * kernel/kobj_notify.c - sysfs event delivery via netlink socket
+ *
+ * Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2004 Novell, Inc.  All rights reserved.
+ *
+ * Licensed under the GNU GPL v2.
+ *
+ * Authors:
+ *     Robert Love             <r...@novell.com>
+ *     Kay Sievers             <kay.siev...@vrfy.org>
+ *     Arjan van de Ven        <arj...@redhat.com>
+ */
+
+#include <linux/spinlock.h>
+#include <linux/socket.h>
+#include <linux/skbuff.h>
+#include <linux/netlink.h>
+#include <linux/string.h>
+#include <linux/kobject.h>
+#include <net/sock.h>
+
+static struct sock *kobj_notify_sock = NULL;
+
+static int do_kobj_notify(const char *signal, struct kobject *kobj,
+                         struct attribute *attr, int gfp_mask)
+{
+       const char *path;
+       struct sk_buff *skb;
+       char *buffer;
+       int len;
+
+       if (!kobj_notify_sock)
+               return -EIO;
+
+       path = kobject_get_path(NULL, kobj, gfp_mask);
+       if (!path)
+               return -ENOMEM;
+
+       len = strlen(signal) + 1;
+       len += strlen(path) + 1;
+       if (attr)
+               len += strlen(attr->name) + 1;
+
+       skb = alloc_skb(len, gfp_mask);
+       if (!skb)
+               return -ENOMEM;
+
+       buffer = skb_put(skb, len);
+       if (attr)
+               sprintf(buffer, "%s\n%s/%s", signal, path, attr->name);
+       else
+               sprintf(buffer, "%s\n%s", signal, path);
+       kfree(path);
+
+       return netlink_broadcast(kobj_notify_sock, skb, 0, 1, gfp_mask);
+}
+
+int kobj_notify(const char *signal, struct kobject *kobj,
+               struct attribute *attr)
+{
+       return do_kobj_notify(signal, kobj, attr, GFP_KERNEL);
+}
+
+EXPORT_SYMBOL(kobj_notify);
+
+int kobj_notify_atomic(const char *signal, struct kobject *kobj,
+                      struct attribute *attr)
+{
+       return do_kobj_notify(signal, kobj, attr, GFP_ATOMIC);
+}
+
+EXPORT_SYMBOL(kobj_notify_atomic);
+
+static int __init kobj_notify_init(void)
+{
+       kobj_notify_sock = netlink_kernel_create(NETLINK_KOBJ_NOTIFY, NULL);
+
+       if (!kobj_notify_sock) {
+               printk(KERN_ERR
+                      "kobj_notify: unable to create netlink socket!\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+core_initcall(kobj_notify_init);
diff -Nru a/lib/kobject.c b/lib/kobject.c
--- a/lib/kobject.c     2004-09-05 03:54:23 +02:00
+++ b/lib/kobject.c     2004-09-05 03:54:23 +02:00
@@ -13,6 +13,7 @@
 #undef DEBUG

 #include <linux/kobject.h>
+#include <linux/kobj_notify.h>
 #include <linux/string.h>
 #include <linux/module.h>
 #include <linux/stat.h>
@@ -202,6 +203,8 @@
                        goto exit;
                }
        }
+
+       kobj_notify(action, kobj, NULL);

        pr_debug ("%s: %s %s %s %s %s %s %s\n", __FUNCTION__, argv[0], argv[1],
                  envp[0], envp[1], envp[2], envp[3], envp[4]);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Love  
View profile  
 More options Sep 4 2004, 11:00 pm
Newsgroups: fa.linux.kernel
From: Robert Love <r...@ximian.com>
Date: Sun, 5 Sep 2004 03:00:52 GMT
Local: Sat, Sep 4 2004 11:00 pm
Subject: Re: [patch] kernel sysfs events layer

On Sat, 2004-09-04 at 02:54 +0200, Greg KH wrote:
> So, we're back to the original issue.  Why is this kernel event system
> different from the hotplug system?  I would argue there isn't one,
> becides the transport, as you seem to want everything that we currently
> provide in the current kobject_hotplug() call.

> But transports are important, I agree.

> How about you just add the ability to send hotplug calls across netlink?
> Make it so the kobject_hotplug() function does both the exec() call, and
> a netlink call (based on a config option for those people who like to
> configure such stuff.)

This smells.

Look, I agree that unifying the two ideas and transports as much as
possible is the right way to proceed.  But the fact is, as you said,
transports _are_ important.  And simply always sending out a hotplug
event _and_ a netlink event is silly and superfluous.  We need to make
up our minds.

I don't think anyone argues that netlink makes sense for these low
priority asynchronous events.

I'd prefer to integrate the two approaches as much as possible, but keep
the two transports separate.  Use hotplug for hotplug events as we do
now and use kevent, which is over netlink, for the new events we want to
add.

Maybe always do the kevent from the hotplug, but definitely do not do
the hotplug from all kevents.  It is redundant and extra overhead.

Doing both simultaneous begs the question of why have both.  Picking the
right tool for the job is, well, the right tool for the job.

        Robert Love

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 90   Newer >
« Back to Discussions « Newer topic     Older topic »