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 13:49:18 +0000 [thread overview]
Message-ID: <20040903134918.GA29172@vrfy.org> (raw)
In-Reply-To: <20040829203523.GA15526@vrfy.org>
[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]
On Fri, Sep 03, 2004 at 11:22:03AM +0200, Kay Sievers wrote:
> On Fri, Sep 03, 2004 at 11:04:02AM +0200, Greg KH wrote:
> > On Fri, Sep 03, 2004 at 02:21:06AM +0200, Kay Sievers wrote:
> > > 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
> >
> > Nice, I like it. How about this, smaller version instead. I just
> > changed your code to use the __ATTR* macros and named a few variables a
> > bit better, no "g" variables for me :)
> >
> > Is this ok with you?
>
> Sure, looks perfect.
Oops, too fast. New patch. Forgot the unusal CONFIG_* combinations.
!CONFIG_SYSFS goes with:
obj-$(CONFIG_SYSFS) += ksysfs.o
and
!CONFIG_HOTPLUG needs the ifdef's in ksysfs.c and kobject.h or is
there any better way?
Tested compilation of all four combinations and booted with:
CONFIG_SYSFS + !CONFIG_HOTPLUG.
Kay
[-- Attachment #2: ksysfs-02.patch --]
[-- Type: text/plain, Size: 3496 bytes --]
Add /sys/kernel subsystem to sysfs and export current hotplug SEQUNUM
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¶
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
diff -Nru a/include/linux/kobject.h b/include/linux/kobject.h
--- a/include/linux/kobject.h 2004-09-03 15:12:57 +02:00
+++ b/include/linux/kobject.h 2004-09-03 15:12:57 +02:00
@@ -26,6 +26,11 @@
#define KOBJ_NAME_LEN 20
+#ifdef CONFIG_HOTPLUG
+/* counter to tag the hotplug event, read only except for the kobject core */
+extern unsigned long hotplug_seqnum;
+#endif
+
struct kobject {
char * k_name;
char name[KOBJ_NAME_LEN];
diff -Nru a/kernel/Makefile b/kernel/Makefile
--- a/kernel/Makefile 2004-09-03 15:12:57 +02:00
+++ b/kernel/Makefile 2004-09-03 15:12:57 +02:00
@@ -24,6 +24,7 @@
obj-$(CONFIG_AUDIT) += audit.o
obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_SYSFS) += ksysfs.o
ifneq ($(CONFIG_IA64),y)
# According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
diff -Nru a/kernel/ksysfs.c b/kernel/ksysfs.c
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/kernel/ksysfs.c 2004-09-03 15:12:57 +02:00
@@ -0,0 +1,55 @@
+/*
+ * 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 released under the GPLv2
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/init.h>
+
+#define KERNEL_ATTR_RO(_name) \
+static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
+
+#define KERNEL_ATTR_RW(_name) \
+static struct subsys_attribute _name##_attr = \
+ __ATTR(_name, 0644, _name##_show, _name##_store)
+
+#ifdef CONFIG_HOTPLUG
+static ssize_t hotplug_seqnum_show(struct subsystem *subsys, char *page)
+{
+ return sprintf(page, "%lu\n", hotplug_seqnum);
+}
+KERNEL_ATTR_RO(hotplug_seqnum);
+#endif
+
+static decl_subsys(kernel, NULL, NULL);
+
+static struct attribute * kernel_attrs[] = {
+#ifdef CONFIG_HOTPLUG
+ &hotplug_seqnum_attr.attr,
+#endif
+ NULL
+};
+
+static struct attribute_group kernel_attr_group = {
+ .attrs = kernel_attrs,
+};
+
+static int __init ksysfs_init(void)
+{
+ int error = subsystem_register(&kernel_subsys);
+ if (!error)
+ error = sysfs_create_group(&kernel_subsys.kset.kobj, &kernel_attr_group);
+
+ return error;
+}
+
+core_initcall(ksysfs_init);
diff -Nru a/lib/kobject.c b/lib/kobject.c
--- a/lib/kobject.c 2004-09-03 15:12:57 +02:00
+++ b/lib/kobject.c 2004-09-03 15:12:57 +02:00
@@ -122,7 +122,7 @@
#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 @@
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 13:49 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
2004-09-03 9:04 ` Greg KH
2004-09-03 9:22 ` Kay Sievers
2004-09-03 13:49 ` Kay Sievers [this message]
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=20040903134918.GA29172@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).