SYSFS: Allow boot time switching between deprecated and modern sysfs layout
Subsystems (5)
PATCH 1/1 SYSFS: Allow boot time switching between deprecated and modern sysfs layout
From: Andi Kleen <[email protected]>
I have some systems which need legacy sysfs due to old udev versions, and it's a big hazzle to compile separate kernels for them.
This patch turns CONFIG_SYSFS_DEPRECATED into a run time option that can be switched on/off the kernel command line. This way the same binary can be used in both cases with just a option on the command line.
The old CONFIG_SYSFS_DEPRECATED_V2 option is still there to set the default. I kept the weird name to not break existing config files.
Also the compat code can be still completely disabled by undefining CONFIG_SYSFS_DEPRECATED_SWITCH -- just the optimizer takes care of this now instead of lots of ifdefs. This makes the code look nicer.
This is a tree sweep for core/scsi/block/sound/core. There weren't that many users and the changes were straight forward so I just did them all in one go without splitting up.
--- Documentation/kernel-parameters.txt | 9 ++ block/genhd.c | 8 +- drivers/base/bus.c | 12 ++-- drivers/base/class.c | 6 +- drivers/base/core.c | 150 +++++++++++++++++++++-------------- drivers/scsi/hosts.c | 5 +- drivers/scsi/scsi_scan.c | 5 +- fs/partitions/check.c | 19 ++--- include/linux/device.h | 7 ++ include/sound/core.h | 10 +-- init/Kconfig | 30 +++++-- sound/core/init.c | 14 +--- 12 files changed, 158 insertions(+), 117 deletions(-)
Documentation/kernel-parameters.txt +9 -0
@@ -2357,6 +2357,15 @@ and is between 256 and 4096 characters. It is defined in the file switches= [HW,M68k] + sysfs.deprecated=0|1 [KNL] + Enable/disable old style sysfs layout for old udev + on older distributions. When this option is enabled + very new udev will not work anymore. When this option + is disabled (or CONFIG_SYSFS_DEPRECATED not compiled) + in older udev will not work anymore. + Default depends on CONFIG_SYSFS_DEPRECATED_V2 set in + the kernel configuration. + sysrq_always_enabled [KNL] Ignore sysrq setting - this boot parameter will
block/genhd.c +3 -5
@@ -18,13 +18,12 @@#include <linux/buffer_head.h> #include <linux/mutex.h> #include <linux/idr.h> +#include <linux/device.h> #include "blk.h" static DEFINE_MUTEX (block_class_lock); -#ifndef CONFIG_SYSFS_DEPRECATED struct kobject *block_depr; -#endif /* for extended dynamic devt allocation, currently only one major is used */ #define MAX_EXT_DEVT (1 << MINORBITS)
@@ -803,10 +802,9 @@ static int __init genhd_device_init(void)register_blkdev (BLOCK_EXT_MAJOR ,"blkext" ); -#ifndef CONFIG_SYSFS_DEPRECATED /* create top-level block dir */ - block_depr =kobject_create_and_add ("block" ,NULL ); -#endif +if (!sysfs_deprecated) + block_depr =kobject_create_and_add ("block" ,NULL );return 0 ; }
drivers/base/bus.c +6 -6
@@ -16,6 +16,7 @@#include <linux/slab.h> #include <linux/init.h> #include <linux/string.h> +#include <linux/device.h> #include "base.h" #include "power/power.h"
@@ -440,21 +441,20 @@ static void device_remove_attrs(struct bus_type *bus, struct device *dev) } } -#ifdef CONFIG_SYSFS_DEPRECATED static int make_deprecated_bus_links (struct device *dev) { +if (!sysfs_deprecated) +return 0 ; +return sysfs_create_link (&dev->kobj, &dev->bus->p->subsys.kobj,"bus" ); }static void remove_deprecated_bus_links (struct device *dev) { -sysfs_remove_link (&dev->kobj,"bus" ); +if (sysfs_deprecated) +sysfs_remove_link (&dev->kobj,"bus" ); } -#else -static inline int make_deprecated_bus_links (struct device *dev) {return 0 ; } -static inline void remove_deprecated_bus_links (struct device *dev) { } -#endif /** * bus_add_device - add device to bus
drivers/base/class.c +3 -3
@@ -184,9 +184,9 @@ int __class_register(struct class *cls, struct lock_class_key *key)if (!cls->dev_kobj) cls->dev_kobj = sysfs_dev_char_kobj; -#if defined(CONFIG_SYSFS_DEPRECATED ) && defined(CONFIG_BLOCK ) +#if defined(CONFIG_BLOCK )/* let the block class directory show up in the root of sysfs */ -if (cls != &block_class) +if (sysfs_deprecated && cls != &block_class) cp->class_subsys.kobj.kset = class_kset;#else cp->class_subsys.kobj.kset = class_kset;
@@ -276,7 +276,7 @@ void class_destroy(struct class *cls)class_unregister (cls); } -#ifdef CONFIG_SYSFS_DEPRECATED +#ifdef CONFIG_SYSFS_DEPRECATED_SWITCH char *make_class_name (const char *name,struct kobject *kobj) {char *class_name;
drivers/base/core.c +90 -60
290 lines not on this page · raw message
drivers/scsi/hosts.c +2 -3
@@ -411,9 +411,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)device_initialize (&shost->shost_gendev);dev_set_name (&shost->shost_gendev,"host%d" , shost->host_no); -#ifndef CONFIG_SYSFS_DEPRECATED - shost->shost_gendev.bus = &scsi_bus_type; -#endif +if (!sysfs_deprecated) + shost->shost_gendev.bus = &scsi_bus_type; shost->shost_gendev.type = &scsi_host_type;device_initialize (&shost->shost_dev);
drivers/scsi/scsi_scan.c +2 -3
@@ -417,9 +417,8 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, starget->reap_ref =1 ; dev->parent =get_device (parent);dev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id); -#ifndef CONFIG_SYSFS_DEPRECATED - dev->bus = &scsi_bus_type; -#endif +if (!sysfs_deprecated) + dev->bus = &scsi_bus_type; dev->type = &scsi_target_type; starget->id = id; starget->channel = channel;
fs/partitions/check.c +9 -10
@@ -513,14 +513,14 @@ void register_disk(struct gendisk *disk)if (device_add (ddev))return ; -#ifndef CONFIG_SYSFS_DEPRECATED - err =sysfs_create_link (block_depr, &ddev->kobj, -kobject_name (&ddev->kobj)); -if (err) { -device_del (ddev); -return ; +if (!sysfs_deprecated) { + err =sysfs_create_link (block_depr, &ddev->kobj, +kobject_name (&ddev->kobj)); +if (err) { +device_del (ddev); +return ; + } } -#endif disk->part0.holder_dir =kobject_create_and_add ("holders" , &ddev->kobj); disk->slave_dir =kobject_create_and_add ("slaves" , &ddev->kobj);
@@ -737,8 +737,7 @@ void del_gendisk(struct gendisk *disk)kobject_put (disk->part0.holder_dir);kobject_put (disk->slave_dir); disk->driverfs_dev =NULL ; -#ifndef CONFIG_SYSFS_DEPRECATED -sysfs_remove_link (block_depr,dev_name (disk_to_dev (disk))); -#endif +if (!sysfs_deprecated) +sysfs_remove_link (block_depr,dev_name (disk_to_dev (disk)));device_del (disk_to_dev (disk)); }
include/linux/device.h +7 -0
@@ -751,4 +751,11 @@ do { \ MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) #define MODULE_ALIAS_CHARDEV_MAJOR(major) \ MODULE_ALIAS("char-major-" __stringify(major) "-*") + +#ifndef CONFIG_SYSFS_DEPRECATED_SWITCH +#define sysfs_deprecated 0 +#else +extern long sysfs_deprecated; +#endif +#endif /* _DEVICE_H_ */
include/sound/core.h +3 -7
@@ -29,6 +29,7 @@#include <linux/pm.h> /* pm_message_t */ #include <linux/device.h> #include <linux/stringify.h> +#include <linux/device.h> /* number of supported soundcards */ #ifdef CONFIG_SND_DYNAMIC_MINORS
@@ -133,9 +134,7 @@ struct snd_card {int free_on_last_close;/* free in context of file_release */ wait_queue_head_t shutdown_sleep;struct device *dev;/* device assigned to this card */ -#ifndef CONFIG_SYSFS_DEPRECATED struct device *card_dev;/* cardX object for sysfs */ -#endif #ifdef CONFIG_PM unsigned int power_state;/* power state */
@@ -196,11 +195,8 @@ struct snd_minor {/* return a device pointer linked to each sound device as a parent */ static inline struct device *snd_card_get_device_link (struct snd_card *card) { -#ifdef CONFIG_SYSFS_DEPRECATED -return card ? card->dev :NULL ; -#else -return card ? card->card_dev :NULL ; -#endif +struct device *dev = sysfs_deprecated ? card->dev : card->card_dev; +return card ? dev :NULL ; }/* sound.c */
init/Kconfig +21 -9
@@ -655,17 +655,19 @@ endif # CGROUPS config MM_OWNER bool -config SYSFS_DEPRECATED - bool - -config SYSFS_DEPRECATED_V2 - bool "enable deprecated sysfs features to support old userspace tools" +config SYSFS_DEPRECATED_SWITCH + bool "allow enabling deprecated sysfs layout at boot time" depends on SYSFS default n - select SYSFS_DEPRECATED help - This option switches the layout of sysfs to the deprecated - version. Do not use it on recent distributions. + Support runtime switching of the deprecated and modern + sysfs layout. Generally the modern layout is needed for newer + distributions and deprecated for very old distributions with + old udev. + + The default is modern layout unless CONFIG_SYSFS_DEPRECATED_V2 + is set. The old layout can be forced by setting + sysfs.deprecated=1 on the kernel command line. The current sysfs layout features a unified device tree at /sys/devices/, which is able to express a hierarchy between
@@ -678,6 +680,16 @@ config SYSFS_DEPRECATED_V2 subsystems will suppress the creation of some devices which depend on the unified device tree. +# use select, not depend, on DEPRECATED_SWITCH to not break old configs +config SYSFS_DEPRECATED_V2 + bool "enable deprecated sysfs features to support old userspace tools" + depends on SYSFS + default n + select SYSFS_DEPRECATED_SWITCH + help + This option switches the layout of sysfs to the deprecated + version. Do not use it on recent distributions. + This option is not a pure compatibility option that can be safely enabled on newer distributions. It will change the layout of sysfs to the non-extensible deprecated version,
@@ -690,7 +702,7 @@ config SYSFS_DEPRECATED_V2 older userspace tools, you might need to say Y here. Do not say Y, if the original kernel, that came with your distribution, has this option set to N. - + config RELAY bool "Kernel->user space relay support (formerly relayfs)" help
sound/core/init.c +3 -11
@@ -395,12 +395,10 @@ int snd_card_disconnect(struct snd_card *card)snd_printk (KERN_ERR "not all devices for card %i can be disconnected\n" , card->number);snd_info_card_disconnect (card); -#ifndef CONFIG_SYSFS_DEPRECATED -if (card->card_dev) { +if (!sysfs_deprecated && card->card_dev) {device_unregister (card->card_dev); card->card_dev =NULL ; } -#endif #ifdef CONFIG_PM wake_up (&card->power_sleep);#endif
@@ -573,7 +571,6 @@ void snd_card_set_id(struct snd_card *card, const char *nid) }EXPORT_SYMBOL (snd_card_set_id); -#ifndef CONFIG_SYSFS_DEPRECATED static ssize_t card_id_show_attr (struct device *dev,struct device_attribute *attr,char *buf)
@@ -630,7 +627,6 @@ card_number_show_attr(struct device *dev,static struct device_attribute card_number_attrs =__ATTR (number,S_IRUGO , card_number_show_attr,NULL ); -#endif /* CONFIG_SYSFS_DEPRECATED */ /** * snd_card_register - register the soundcard
@@ -649,15 +645,13 @@ int snd_card_register(struct snd_card *card)if (snd_BUG_ON (!card))return -EINVAL ; -#ifndef CONFIG_SYSFS_DEPRECATED -if (!card->card_dev) { +if (!sysfs_deprecated && !card->card_dev) { card->card_dev =device_create (sound_class, card->dev,MKDEV (0 ,0 ), card,"card%i" , card->number);if (IS_ERR (card->card_dev)) card->card_dev =NULL ; } -#endif if ((err =snd_device_register_all (card)) <0 )return err;mutex_lock (&snd_card_mutex);
@@ -674,8 +668,7 @@ int snd_card_register(struct snd_card *card)if (snd_mixer_oss_notify_callback)snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_REGISTER );#endif -#ifndef CONFIG_SYSFS_DEPRECATED -if (card->card_dev) { +if (!sysfs_deprecated && card->card_dev) { err =device_create_file (card->card_dev, &card_id_attrs);if (err <0 )return err;
@@ -683,7 +676,6 @@ int snd_card_register(struct snd_card *card)if (err <0 )return err; } -#endif return 0 ; }
Signature · 1 line
1.7.1
Quoted 9 lines · Andi Kleen
From: Andi Kleen <[email protected]>
I have some systems which need legacy sysfs due to old udev versions, and it's a big hazzle to compile separate kernels for them.
This patch turns
CONFIG_SYSFS_DEPRECATEDinto a run time option that can be switched on/off the kernel command line. This way the same binary can be used in both cases with just a option on the command line.
Nice idea. It will make testing easier for lots of people.
But, Kay and I just changed the logic in the kernel in this area, getting rid of the CONFIG_SYSFS_DEPRECATED_V2 option entirely, to try to make the code path smaller, only offering the "old" mode for block devices, to keep kernels booting on userspace instances like what you have.
So, could you respin this patch against the linux-next tree which has Kay's patch in it? Or, if it's easier, I've attached the patch below.
thanks,
greg k-h
Quoted 1 line
From foo@baz Sat Sep 4 22:33:14 PDT 2010
Date: Sat, 04 Sep 2010 22:33:14 -0700
To: Greg KH <[email protected]>
From: Kay Sievers <[email protected]>
Subject: driver core: remove CONFIG_SYSFS_DEPRECATED_V2 but keep it for block devices
This patch removes the old CONFIG_SYSFS_DEPRECATED_V2 config option, but it keeps the logic around to handle block devices in the old manner as some people like to run new kernel versions on old (pre 2007/2008) distros.
--- drivers/base/bus.c | 22 ----- drivers/base/class.c | 19 ---- drivers/base/core.c | 194 ++++++----------------------------------------- drivers/scsi/hosts.c | 2 drivers/scsi/scsi_scan.c | 2 include/sound/core.h | 6 - init/Kconfig | 42 +++------- sound/core/init.c | 11 -- 8 files changed, 41 insertions(+), 257 deletions(-)
drivers/base/bus.c +0 -22
@@ -440,22 +440,6 @@ static void device_remove_attrs(struct b } } -#ifdef CONFIG_SYSFS_DEPRECATED -static int make_deprecated_bus_links (struct device *dev) -{ -return sysfs_create_link (&dev->kobj, - &dev->bus->p->subsys.kobj,"bus" ); -} - -static void remove_deprecated_bus_links (struct device *dev) -{ -sysfs_remove_link (&dev->kobj,"bus" ); -} -#else -static inline int make_deprecated_bus_links (struct device *dev) {return 0 ; } -static inline void remove_deprecated_bus_links (struct device *dev) { } -#endif -/** * bus_add_device - add device to bus * @dev: device being added
@@ -482,15 +466,10 @@ int bus_add_device(struct device *dev) &dev->bus->p->subsys.kobj, "subsystem");if (error) goto out_subsys; - error =make_deprecated_bus_links (dev); -if (error) - goto out_deprecated;klist_add_tail (&dev->p->knode_bus, &bus->p->klist_devices); }return 0 ; -out_deprecated: -sysfs_remove_link (&dev->kobj,"subsystem" ); out_subsys:sysfs_remove_link (&bus->p->devices_kset->kobj,dev_name (dev)); out_id:
@@ -530,7 +509,6 @@ void bus_remove_device(struct device *de {if (dev->bus) {sysfs_remove_link (&dev->kobj,"subsystem" ); -remove_deprecated_bus_links (dev);sysfs_remove_link (&dev->bus->p->devices_kset->kobj,dev_name (dev));device_remove_attrs (dev->bus, dev);
drivers/base/class.c +0 -19
@@ -276,25 +276,6 @@ void class_destroy(struct class *cls)class_unregister (cls); } -#ifdef CONFIG_SYSFS_DEPRECATED -char *make_class_name (const char *name,struct kobject *kobj) -{ -char *class_name; -int size; - - size =strlen (name) +strlen (kobject_name (kobj)) +2 ; - - class_name =kmalloc (size,GFP_KERNEL ); -if (!class_name) -return NULL ; - -strcpy (class_name, name); -strcat (class_name,":" ); -strcat (class_name,kobject_name (kobj)); -return class_name; -} -#endif -/** * class_dev_iter_init - initialize class device iterator * @iter: class iterator to initialize
drivers/base/core.c +25 -169
280 lines not on this page · raw message
drivers/scsi/hosts.c +0 -2
@@ -411,9 +411,7 @@ struct Scsi_Host *scsi_host_alloc(structdevice_initialize (&shost->shost_gendev);dev_set_name (&shost->shost_gendev,"host%d" , shost->host_no); -#ifndef CONFIG_SYSFS_DEPRECATED shost->shost_gendev.bus = &scsi_bus_type; -#endif shost->shost_gendev.type = &scsi_host_type;device_initialize (&shost->shost_dev);
drivers/scsi/scsi_scan.c +0 -2
@@ -417,9 +417,7 @@ static struct scsi_target *scsi_alloc_ta starget->reap_ref =1 ; dev->parent =get_device (parent);dev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id); -#ifndef CONFIG_SYSFS_DEPRECATED dev->bus = &scsi_bus_type; -#endif dev->type = &scsi_target_type; starget->id = id; starget->channel = channel;
include/sound/core.h +0 -6
@@ -133,9 +133,7 @@ struct snd_card {int free_on_last_close;/* free in context of file_release */ wait_queue_head_t shutdown_sleep;struct device *dev;/* device assigned to this card */ -#ifndef CONFIG_SYSFS_DEPRECATED struct device *card_dev;/* cardX object for sysfs */ -#endif #ifdef CONFIG_PM unsigned int power_state;/* power state */
@@ -196,11 +194,7 @@ struct snd_minor {/* return a device pointer linked to each sound device as a parent */ static inline struct device *snd_card_get_device_link (struct snd_card *card) { -#ifdef CONFIG_SYSFS_DEPRECATED -return card ? card->dev :NULL ; -#else return card ? card->card_dev :NULL ; -#endif }/* sound.c */
init/Kconfig +13 -29
53 lines not on this page · raw message
sound/core/init.c +3 -8
@@ -395,12 +395,10 @@ int snd_card_disconnect(struct snd_cardsnd_printk (KERN_ERR "not all devices for card %i can be disconnected\n" , card->number);snd_info_card_disconnect (card); -#ifndef CONFIG_SYSFS_DEPRECATED if (card->card_dev) {device_unregister (card->card_dev); card->card_dev =NULL ; } -#endif #ifdef CONFIG_PM wake_up (&card->power_sleep);#endif
@@ -573,7 +571,6 @@ void snd_card_set_id(struct snd_card *ca }EXPORT_SYMBOL (snd_card_set_id); -#ifndef CONFIG_SYSFS_DEPRECATED static ssize_t card_id_show_attr (struct device *dev,struct device_attribute *attr,char *buf)
@@ -630,7 +627,6 @@ card_number_show_attr(struct device *devstatic struct device_attribute card_number_attrs =__ATTR (number,S_IRUGO , card_number_show_attr,NULL ); -#endif /* CONFIG_SYSFS_DEPRECATED */ /** * snd_card_register - register the soundcard
@@ -649,7 +645,7 @@ int snd_card_register(struct snd_card *cif (snd_BUG_ON (!card))return -EINVAL ; -#ifndef CONFIG_SYSFS_DEPRECATED +if (!card->card_dev) { card->card_dev = device_create(sound_class, card->dev, MKDEV(0, 0), card,
@@ -657,7 +653,7 @@ int snd_card_register(struct snd_card *cif (IS_ERR (card->card_dev)) card->card_dev =NULL ; } -#endif +if ((err =snd_device_register_all (card)) <0 )return err;mutex_lock (&snd_card_mutex);
@@ -674,7 +670,6 @@ int snd_card_register(struct snd_card *cif (snd_mixer_oss_notify_callback)snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_REGISTER );#endif -#ifndef CONFIG_SYSFS_DEPRECATED if (card->card_dev) { err =device_create_file (card->card_dev, &card_id_attrs);if (err <0 )
@@ -683,7 +678,7 @@ int snd_card_register(struct snd_card *cif (err <0 )return err; } -#endif +return 0 ; }
Quoted 5 lines · On Wed, 8 Sep 2010 06:55:30 -0700 Greg KH <[email protected]> wrote:
But, Kay and I just changed the logic in the kernel in this area, getting rid of the
CONFIG_SYSFS_DEPRECATED_V2option entirely, to try to make the code path smaller, only offering the "old" mode for block devices, to keep kernels booting on userspace instances like what you have.
That will likely break my user space, it relies on the old style net set up (opensuse 10.0) for network configuration. That was the main reason I did this patch.
Quoted 3 lines
So, could you respin this patch against the linux-next tree which has Kay's patch in it? Or, if it's easier, I've attached the patch below.
I can test your patch first, but to be honest I doubt it'll work on the 10.0 roots.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH] SYSFS: Allow boot time switching between deprecated and modern sysfs layout II
Quoted 9 lines · On Wed, 8 Sep 2010 16:02:35 +0200 Andi Kleen <[email protected]> wrote:
Quoted 5 lines · On Wed, 8 Sep 2010 06:55:30 -0700 Greg KH <[email protected]> wrote:
But, Kay and I just changed the logic in the kernel in this area, getting rid of the
CONFIG_SYSFS_DEPRECATED_V2option entirely, to try to make the code path smaller, only offering the "old" mode for block devices, to keep kernels booting on userspace instances like what you have.
Quoted 3 lines
That will likely break my user space, it relies on the old style net set up (opensuse 10.0) for network configuration. That was the main reason I did this patch.
... Just tested it. Never mind, it looks the old style network configuration seems to work still with this patch and my earlier pessimistic assumptions were incorrect.
Don't see any misfunction so it looks like the new patch is ok.
I'll respin my patch on top of this.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.