From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Date: Fri, 03 Sep 2004 09:04:02 +0000 Subject: Re: export of SEQNUM to userspace Message-Id: <20040903090402.GA22401@kroah.com> List-Id: References: <20040829203523.GA15526@vrfy.org> In-Reply-To: <20040829203523.GA15526@vrfy.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org 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? thanks, greg k-h ------ diff -Nru a/include/linux/kobject.h b/include/linux/kobject.h --- a/include/linux/kobject.h 2004-09-03 11:00:55 +02:00 +++ b/include/linux/kobject.h 2004-09-03 11:00:55 +02:00 @@ -24,6 +24,9 @@ #define KOBJ_NAME_LEN 20 +/* counter to tag the hotplug event, read only except for the kobject core */ +extern unsigned long hotplug_seqnum; + struct kobject { char * k_name; char name[KOBJ_NAME_LEN]; diff -Nru a/kernel/Makefile b/kernel/Makefile --- a/kernel/Makefile 2004-09-03 11:00:55 +02:00 +++ b/kernel/Makefile 2004-09-03 11:00:55 +02:00 @@ -7,7 +7,7 @@ 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 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 11:00:55 +02:00 @@ -0,0 +1,52 @@ +/* + * 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 +#include + +#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) + +static ssize_t hotplug_seqnum_show(struct subsystem *subsys, char *page) +{ + return sprintf(page, "%lu\n", hotplug_seqnum); +} +KERNEL_ATTR_RO(hotplug_seqnum); + + +static decl_subsys(kernel, NULL, NULL); + +static struct attribute * kernel_attrs[] = { + &hotplug_seqnum_attr.attr, + 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 11:00:55 +02:00 +++ b/lib/kobject.c 2004-09-03 11:00:55 +02:00 @@ -120,7 +120,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, @@ -176,7 +176,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; ------------------------------------------------------- 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_idP47&alloc_id808&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