From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Fri, 03 Sep 2004 13:49:18 +0000 Subject: Re: export of SEQNUM to userspace Message-Id: <20040903134918.GA29172@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="x+6KMIRAuhnl3hBn" List-Id: References: <20040829203523.GA15526@vrfy.org> In-Reply-To: <20040829203523.GA15526@vrfy.org> To: linux-hotplug@vger.kernel.org --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=utf-8 Content-Disposition: inline; filename="ksysfs-02.patch" Content-Transfer-Encoding: quoted-printable Add /sys/kernel subsystem to sysfs and export current hotplug SEQUNUM o /sys/kernel/hotplug_seqnum exports the current number=C2=B6 o lib/kobject.c's sequence_num is renamed to hotplug_seqnum and=C2=B6 exported by include/linux/kobject.h=C2=B6 o the source file ksysfs.c in kernel/ creates on init the=C2=B6 sybsystem "/sys/kernel/" in sysfs=C2=B6 Signed-off-by: Kay Sievers 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 @@ =20 #define KOBJ_NAME_LEN 20 =20 +#ifdef CONFIG_HOTPLUG +/* counter to tag the hotplug event, read only except for the kobject co= re */ +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) +=3D audit.o obj-$(CONFIG_AUDITSYSCALL) +=3D auditsc.o obj-$(CONFIG_KPROBES) +=3D kprobes.o +obj-$(CONFIG_SYSFS) +=3D ksysfs.o =20 ifneq ($(CONFIG_IA64),y) # According to Alan Modra , the -fno-omit-frame-p= ointer 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 + *=20 + * This file is released under the GPLv2 + * + */ + +#include +#include +#include +#include +#include +#include + +#define KERNEL_ATTR_RO(_name) \ +static struct subsys_attribute _name##_attr =3D __ATTR_RO(_name) + +#define KERNEL_ATTR_RW(_name) \ +static struct subsys_attribute _name##_attr =3D \ + __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[] =3D { +#ifdef CONFIG_HOTPLUG + &hotplug_seqnum_attr.attr, +#endif + NULL +}; + +static struct attribute_group kernel_attr_group =3D { + .attrs =3D kernel_attrs, +}; + +static int __init ksysfs_init(void) +{ + int error =3D subsystem_register(&kernel_subsys); + if (!error) + error =3D sysfs_create_group(&kernel_subsys.kset.kobj, &kernel_attr_gr= oup); + + 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 @@ =20 #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 =3D SPIN_LOCK_UNLOCKED; =20 static void kset_hotplug(const char *action, struct kset *kset, @@ -178,7 +178,7 @@ scratch +=3D sprintf(scratch, "ACTION=3D%s", action) + 1; =20 spin_lock(&sequence_lock); - seq =3D sequence_num++; + seq =3D hotplug_seqnum++; spin_unlock(&sequence_lock); =20 envp [i++] =3D scratch; --x+6KMIRAuhnl3hBn-- ------------------------------------------------------- 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