From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Fri, 03 Sep 2004 00:21:06 +0000 Subject: Re: export of SEQNUM to userspace Message-Id: <20040903002106.GA27626@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="WIyZ46R2i8wDzkSu" List-Id: References: <20040829203523.GA15526@vrfy.org> In-Reply-To: <20040829203523.GA15526@vrfy.org> To: linux-hotplug@vger.kernel.org --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="ksysfs-01.patch" --- ./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 + * + * This file is release under the GPLv2 + * + */ + +#include +#include +#include +#include +#include + +#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; --WIyZ46R2i8wDzkSu-- ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel