Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e52eec13 authored by Andi Kleen's avatar Andi Kleen Committed by Greg Kroah-Hartman
Browse files

SYSFS: Allow boot time switching between deprecated and modern sysfs layout



I have some systems which need legacy sysfs due to old tools that are
making assumptions that a directory can never be a symlink to another
directory, 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.

v2: This is an updated version on top of Kay's patch to only
handle the block devices. I tested it on my old systems
and that seems to work.

Cc: axboe@kernel.dk
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 39aba963
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2365,6 +2365,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
+2 −5
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@
#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 +801,9 @@ static int __init genhd_device_init(void)

	register_blkdev(BLOCK_EXT_MAJOR, "blkext");

#ifndef CONFIG_SYSFS_DEPRECATED
	/* create top-level block dir */
	if (!sysfs_deprecated)
		block_depr = kobject_create_and_add("block", NULL);
#endif
	return 0;
}

+2 −2
Original line number Diff line number Diff line
@@ -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;
+17 −9
Original line number Diff line number Diff line
@@ -26,6 +26,19 @@
#include "base.h"
#include "power/power.h"

#ifdef CONFIG_SYSFS_DEPRECATED
#ifdef CONFIG_SYSFS_DEPRECATED_V2
long sysfs_deprecated = 1;
#else
long sysfs_deprecated = 0;
#endif
static __init int sysfs_deprecated_setup(char *arg)
{
	return strict_strtol(arg, 10, &sysfs_deprecated);
}
early_param("sysfs.deprecated", sysfs_deprecated_setup);
#endif

int (*platform_notify)(struct device *dev) = NULL;
int (*platform_notify_remove)(struct device *dev) = NULL;
static struct kobject *dev_kobj;
@@ -617,14 +630,13 @@ static struct kobject *get_device_parent(struct device *dev,
		struct kobject *parent_kobj;
		struct kobject *k;

#ifdef CONFIG_SYSFS_DEPRECATED
		/* block disks show up in /sys/block */
		if (dev->class == &block_class) {
		if (sysfs_deprecated && dev->class == &block_class) {
			if (parent && parent->class == &block_class)
				return &parent->kobj;
			return &block_class.p->class_subsys.kobj;
		}
#endif

		/*
		 * If we have no parent, we live in "virtual".
		 * Class-devices with a non class-device as parent, live
@@ -707,11 +719,9 @@ static int device_add_class_symlinks(struct device *dev)
			goto out_subsys;
	}

#ifdef CONFIG_SYSFS_DEPRECATED
	/* /sys/block has directories and does not need symlinks */
	if (dev->class == &block_class)
	if (sysfs_deprecated && dev->class == &block_class)
		return 0;
#endif

	/* link in the class directory pointing to the device */
	error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
@@ -738,10 +748,8 @@ static void device_remove_class_symlinks(struct device *dev)
	if (dev->parent && device_is_not_partition(dev))
		sysfs_remove_link(&dev->kobj, "device");
	sysfs_remove_link(&dev->kobj, "subsystem");
#ifdef CONFIG_SYSFS_DEPRECATED
	if (dev->class == &block_class)
	if (sysfs_deprecated && dev->class == &block_class)
		return;
#endif
	sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev));
}

+9 −10
Original line number Diff line number Diff line
@@ -513,14 +513,14 @@ void register_disk(struct gendisk *disk)

	if (device_add(ddev))
		return;
#ifndef CONFIG_SYSFS_DEPRECATED
	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
	if (!sysfs_deprecated)
		sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
#endif
	device_del(disk_to_dev(disk));
}
Loading