udev kset_create_and_add() with own struct kobj_type?

From: Alexander Aring
Date: Mon Jul 15 2024 - 11:27:24 EST


Hi,

I am currently implementing namespace support into the fs/dlm
subsystem. The DLM subsystem uses kset_create_and_add("dlm",
&dlm_uevent_ops, kernel_kobj); to create the "dlm" sysfs directory.
Underneath it creates for each lockspace a subdirectory using
kobject_init_and_add() with a non-static name and being known during
runtime.

Now I want to add namespace support and need to change the "default"
kset->kobj.ktype = &kset_ktype; that is set by
kset_create_and_add()->kset_create() to my own kobj_type because I
need to implement a different ".child_ns_type" callback before
kset_register() is called.

So kset_create_and_add() does not allow me to add my own
".child_ns_type" callback for the kset that is required for me to have
my sysfs "kernel/dlm" directory separated by each net-namespace
without breaking any backwards compatibility.

My current solution is that I mostly copy&pasted the code of
kset_create_and_add()/kset_create() to have a way to tell my own
struct kobj_type that contains the implemented my own ".child_ns_type"
callback.

I am writing this mail to get some advice on what I can do here
without doing the copy&pasted code?
Add a parameter to kset_create_and_add() that allows me to set an
"struct kobj_type"?
Introducing a new function that does allow me to set the new parameter
(I probably like that because then I don't need to update all other
users)?

Thanks in advance for any advice.

- Alex