From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: export of SEQNUM to userspace
Date: Fri, 03 Sep 2004 00:21:06 +0000 [thread overview]
Message-ID: <20040903002106.GA27626@vrfy.org> (raw)
In-Reply-To: <20040829203523.GA15526@vrfy.org>
[-- Attachment #1: Type: text/plain, Size: 1333 bytes --]
On Thu, Sep 02, 2004 at 10:10:06AM +0200, Greg KH wrote:
> On Thu, Sep 02, 2004 at 12:36:57AM +0200, Kay Sievers wrote:
> > On Tue, Aug 31, 2004 at 02:16:32PM -0400, Greg KH wrote:
> > > On Sun, Aug 29, 2004 at 10:35:23PM +0200, Kay Sievers wrote:
> > > > Hi Greg,
> > > > we want to init HAL with the last emitted hotplug SEQNUM from the
> > > > kernel. I think of a sysfs file we can read. It would solve the problem
> > > > of the initial timeout, like we have with udevd too (the very first
> > > > event is delayed).
> > >
> > > Ok, that sounds reasonable.
> > >
> > > > What is a proper place to live for this beast?
> > >
> > > I'm getting a lot of requests for odd stuff like this in sysfs. Things
> > > that are "kernel" specific, and aren't associated with any one place
> > > (things that would end up in /proc/sys/kernel if we didn't have sysfs.)
> > >
> > > So, how about /sys/kernel?
> >
> > Sounds good!
> > Who should create the kset (or in this case it's a subsystem) for this?
>
> Hm, how about a new file in kernel/ ?
Something like this?
o /sys/kernel/hotplug_seqnum exports the current number
o lib/kobject.c's sequence_num is renamed to hotplug_seqnum and
exported by include/linux/kobject.h
o the source file ksysfs.c in kernel/ creates on init the
sybsystem "/sys/kernel/" in sysfs
Thanks,
Kay
[-- Attachment #2: ksysfs-01.patch --]
[-- Type: text/plain, Size: 3149 bytes --]
--- ./dev/null 1970-01-01 01:00:00.000000000 +0100
+++ ./kernel/ksysfs.c 2004-09-03 01:51:38.101622646 +0200
@@ -0,0 +1,63 @@
+/*
+ * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which
+ * are not related to any other subsystem
+ *
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ * This file is release under the GPLv2
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/init.h>
+
+#define KERNEL_ATTR_RO(_name) \
+static struct subsys_attribute _name##_attr = { \
+ .attr = { \
+ .name = __stringify(_name), \
+ .mode = 0444, \
+ }, \
+ .show = _name##_show, \
+}
+
+#define KERNEL_ATTR_RW(_name) \
+static struct subsys_attribute _name##_attr = { \
+ .attr = { \
+ .name = __stringify(_name), \
+ .mode = 0644, \
+ }, \
+ .show = _name##_show, \
+ .store = _name##_store, \
+}
+
+static ssize_t hotplug_seqnum_show(struct subsystem * subsys, char * page)
+{
+ return sprintf(page, "%lu\n", hotplug_seqnum);
+}
+KERNEL_ATTR_RO(hotplug_seqnum);
+
+
+decl_subsys(kernel, NULL, NULL);
+
+static struct attribute * g[] = {
+ &hotplug_seqnum_attr.attr,
+ NULL
+};
+
+static struct attribute_group attr_group = {
+ .attrs = g,
+};
+
+static int __init ksysfs_init(void)
+{
+ int error = subsystem_register(&kernel_subsys);
+ if (!error)
+ error = sysfs_create_group(&kernel_subsys.kset.kobj,&attr_group);
+
+ return error;
+}
+
+core_initcall(ksysfs_init);
===== include/linux/kobject.h 1.31 vs edited =====
--- 1.31/include/linux/kobject.h 2004-09-02 01:24:31 +02:00
+++ edited/include/linux/kobject.h 2004-09-03 01:51:17 +02:00
@@ -26,6 +26,9 @@
#define KOBJ_NAME_LEN 20
+/* counter to tag the hotplug event, also available through sysfs */
+extern unsigned long hotplug_seqnum;
+
struct kobject {
char * k_name;
char name[KOBJ_NAME_LEN];
===== kernel/Makefile 1.42 vs edited =====
--- 1.42/kernel/Makefile 2004-08-31 09:55:12 +02:00
+++ edited/kernel/Makefile 2004-09-03 01:46:09 +02:00
@@ -7,7 +7,7 @@ obj-y = sched.o fork.o exec_domain.o
sysctl.o capability.o ptrace.o timer.o user.o \
signal.o sys.o kmod.o workqueue.o pid.o \
rcupdate.o intermodule.o extable.o params.o posix-timers.o \
- kthread.o
+ kthread.o ksysfs.o
obj-$(CONFIG_FUTEX) += futex.o
obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
===== lib/kobject.c 1.45 vs edited =====
--- 1.45/lib/kobject.c 2004-08-25 21:30:25 +02:00
+++ edited/lib/kobject.c 2004-09-03 01:51:02 +02:00
@@ -122,7 +122,7 @@ char * kobject_get_path(struct kset *kse
#define BUFFER_SIZE 1024 /* should be enough memory for the env */
#define NUM_ENVP 32 /* number of env pointers */
-static unsigned long sequence_num;
+unsigned long hotplug_seqnum;
static spinlock_t sequence_lock = SPIN_LOCK_UNLOCKED;
static void kset_hotplug(const char *action, struct kset *kset,
@@ -178,7 +178,7 @@ static void kset_hotplug(const char *act
scratch += sprintf(scratch, "ACTION=%s", action) + 1;
spin_lock(&sequence_lock);
- seq = sequence_num++;
+ seq = hotplug_seqnum++;
spin_unlock(&sequence_lock);
envp [i++] = scratch;
next prev parent reply other threads:[~2004-09-03 0:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-29 20:35 export of SEQNUM to userspace Kay Sievers
2004-08-31 18:16 ` Greg KH
2004-09-01 22:36 ` Kay Sievers
2004-09-02 8:10 ` Greg KH
2004-09-03 0:21 ` Kay Sievers [this message]
2004-09-03 9:04 ` Greg KH
2004-09-03 9:22 ` Kay Sievers
2004-09-03 13:49 ` Kay Sievers
2004-09-03 17:21 ` Greg KH
2004-10-08 14:43 ` David Zeuthen
2004-10-08 21:05 ` Greg KH
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=20040903002106.GA27626@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@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 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).