compelling reason to use a kset in kernel code?

2 messages, 1 author, 2012-10-14 · open the first message on its own page

compelling reason to use a kset in kernel code?

From: Robert P. J. Day <hidden>
Date: 2012-10-14 08:27:34

  it's not at all clear to me what the value is in using a kset when
writing some kernel code.  i can see the example program,
samples/kobject/kset-example.c, but that program doesn't seem to
demonstrate what the purpose is of the kset created.

  as another example, consider the different filesystem
implementations under the fs/ directory, and grep to see who uses
what to create the appropriate entry under /sys/fs/:

$ grep -r "create_and_add" *
9p/v9fs.c:	v9fs_kobj = kobject_create_and_add("9p", fs_kobj);
btrfs/sysfs.c:	btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);
configfs/mount.c:	config_kobj = kobject_create_and_add("config", kernel_kobj);
debugfs/inode.c:	debug_kobj = kobject_create_and_add("debug", kernel_kobj);
dlm/lockspace.c:	dlm_kset = kset_create_and_add("dlm", &dlm_uevent_ops, kernel_kobj);
ecryptfs/main.c:	ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
exofs/sys.c:	exofs_kset = kset_create_and_add("exofs", NULL, fs_kobj);
exofs/sys.c:		EXOFS_ERR("ERROR: kset_create_and_add exofs failed\n");
ext4/super.c:	ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
fscache/cache.c:	cache->kobj = kobject_create_and_add(tagname, fscache_root);
fscache/main.c:	fscache_root = kobject_create_and_add("fscache", kernel_kobj);
fuse/inode.c:	fuse_kobj = kobject_create_and_add("fuse", fs_kobj);
fuse/inode.c:	connections_kobj = kobject_create_and_add("connections", fuse_kobj);
gfs2/sys.c:	gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
namespace.c:	fs_kobj = kobject_create_and_add("fs", NULL);
ocfs2/cluster/sys.c:	o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
ocfs2/stackglue.c:	ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj);
$

  as you can see, some use kobject_create_and_add() while others use
kset_create_and_add(), and it's not clear to me what the difference is
in *why* one was chosen over the other.  thoughts?  i'm sure there's a
simple distinction i'm just missing here.

rday

-- 

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

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

compelling reason to use a kset in kernel code?

From: Robert P. J. Day <hidden>
Date: 2012-10-14 09:05:36

  as a short follow-up to my earlier post, here's some actual kernel
code that uses a kset for no obvious reason -- fs/btrfs/sysfs.c:

===== start =====
static struct kset *btrfs_kset;

int btrfs_init_sysfs(void)
{
        btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);
        if (!btrfs_kset)
                return -ENOMEM;
        return 0;
}

void btrfs_exit_sysfs(void)
{
        kset_unregister(btrfs_kset);
}
===== end =====

  that's it, that's the entire source file, with that kset being
created with a NULL pointer to a kset_uevent_ops.  so what's the point
of that code, other than to simply have the kobject /sys/fs/btrfs
appear under /sys?  or is that the whole purpose here?

rday

-- 

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

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help