/sys/block and SYSFS_DEPRECATED, wanting a little clarification

Robert P. J. Day rpjday at crashcourse.ca
Tue Oct 9 05:35:39 EDT 2012


  following through the code that creates the entire /sys hierarchy
and ran across a puzzler involving /sys/block.  here are the top-level
entries in /sys:

$ ls
block  bus  class  dev  devices  firmware  fs  kernel  module  power
$

and it's easy to use a "grep" to see where most of them come from,
assuming most of them are represented by a global variable name ending
in "_kobj" as they often do:

$ grep -r "_kobj = kobject_create_and_add.*NULL" *
arch/powerpc/platforms/pseries/power.c:	power_kobj = kobject_create_and_add("power", NULL);
drivers/base/hypervisor.c:	hypervisor_kobj = kobject_create_and_add("hypervisor", NULL);
drivers/base/core.c:	dev_kobj = kobject_create_and_add("dev", NULL);
drivers/base/firmware.c:	firmware_kobj = kobject_create_and_add("firmware", NULL);
drivers/staging/speakup/kobjects.c:	accessibility_kobj = kobject_create_and_add("accessibility", NULL);
fs/namespace.c:	fs_kobj = kobject_create_and_add("fs", NULL);
kernel/ksysfs.c:	kernel_kobj = kobject_create_and_add("kernel", NULL);
kernel/power/main.c:	power_kobj = kobject_create_and_add("power", NULL);
$

  but i didn't see the creation of /sys/block and, after a bit of
looking, noticed it had a different name -- block_depr -- which
doesn't look like it's used all that much:

$ grep -rw block_depr *
block/genhd.c:struct kobject *block_depr;
block/genhd.c:		err = sysfs_create_link(block_depr, &ddev->kobj,
block/genhd.c:		sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
block/genhd.c:		block_depr = kobject_create_and_add("block", NULL);
include/linux/genhd.h:extern struct kobject *block_depr;
$


  now, given that that kobject is clearly "deprecated", it seemed that
it should be configurable to not create it at all and, sure enough,
there's what looks like the Kconfig entry in init/Kconfig:

config SYSFS_DEPRECATED
        bool "Enable deprecated sysfs features to support old userspace tools"
        depends on SYSFS
        default n
        help
          This option adds code that switches the layout of the "block" class
          devices, to not show up in /sys/class/block/, but only in
          /sys/block/.
          ...

but that looks a bit strange ... it doesn't omit the creation of
/sys/block; rather, it omits the creation of /sys/class/block, which
appears to be the *newer* location for that information.

  and there's this from drivers/base/core.c:

===== start =====
#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
===== end =====

  anyway, i explicitly selected no SYSFS_DEPRECATED config settings in
my build, but i still got the /sys/block entry under /sys.  is it
really necessary?  if it's "deprecated", should one not be able to
configure and build a kernel without it, if the newer(?) location for
it is /sys/class/block?  thoughts?

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================



More information about the Kernelnewbies mailing list