Message ID | 20240814143414.1877505-10-aahringo@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | dlm: net-namespace functionality | expand |
On Wed, Aug 14, 2024 at 10:34:11AM -0400, Alexander Aring wrote: > This patch exports generic helpers like kset_release() and > kset_get_ownership() so users can use them in their own struct kobj_type > implementation instead of implementing their own functions that do the > same. Why is anyone needing these? What raw kobjects require this type of stuff? thanks, greg k-h
Hi, On Wed, Aug 14, 2024 at 11:06 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > On Wed, Aug 14, 2024 at 10:34:11AM -0400, Alexander Aring wrote: > > This patch exports generic helpers like kset_release() and > > kset_get_ownership() so users can use them in their own struct kobj_type > > implementation instead of implementing their own functions that do the > > same. > > Why is anyone needing these? What raw kobjects require this type of > stuff? > In this patch series I introduced kset_type_create_and_add() to have the possibility to do the exact same what kset_create_and_add() is doing, just setting a different "struct kobj_type", for the kset that is created internally by kset_create_and_add(). I can't use kset_create_and_add() as it always uses "kset_ktype", see [0]. I am doing that to have only a callback for ".child_ns_type" assigned as it returns the "&net_ns_type_operations;" structure to tell underneath everything is separated by net namespaces. I don't want to change anything else so the "struct kobj_type" should look like what kset_create_and_add() is doing. Therefore I am creating the same structure as kset_create_and_add() is using, see [0]. The "kobj_sysfs_ops" structure seems to be already accessible from outside, just the two functions I am exporting in this patch are missing. Or I implement it in the same way in the dlm/gfs2 codebase (that is what nfs is currently doing, see [1]). And then we are at the two users of those kobjects that are using those functions, it's DLM and GFS2 as they used kset_create_and_add() before and I just want to add the ".child_ns_type" callback. Other users could be nfs [1] (for the release, get_ownership - I have no idea). thanks. - Alex [0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/kobject.c?h=v6.11-rc3#n937 [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/nfs/sysfs.c?h=v6.11-rc3#n23
On Wed, Aug 14, 2024 at 04:47:28PM -0400, Alexander Aring wrote: > Hi, > > On Wed, Aug 14, 2024 at 11:06 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > > On Wed, Aug 14, 2024 at 10:34:11AM -0400, Alexander Aring wrote: > > > This patch exports generic helpers like kset_release() and > > > kset_get_ownership() so users can use them in their own struct kobj_type > > > implementation instead of implementing their own functions that do the > > > same. > > > > Why is anyone needing these? What raw kobjects require this type of > > stuff? > > > > In this patch series I introduced kset_type_create_and_add() to have > the possibility to do the exact same what kset_create_and_add() is > doing, just setting a different "struct kobj_type", for the kset that > is created internally by kset_create_and_add(). I can't use > kset_create_and_add() as it always uses "kset_ktype", see [0]. > > I am doing that to have only a callback for ".child_ns_type" assigned > as it returns the "&net_ns_type_operations;" structure to tell > underneath everything is separated by net namespaces. > I don't want to change anything else so the "struct kobj_type" should > look like what kset_create_and_add() is doing. Therefore I am creating > the same structure as kset_create_and_add() is using, see [0]. The > "kobj_sysfs_ops" structure seems to be already accessible from > outside, just the two functions I am exporting in this patch are > missing. Or I implement it in the same way in the dlm/gfs2 codebase > (that is what nfs is currently doing, see [1]). > > And then we are at the two users of those kobjects that are using > those functions, it's DLM and GFS2 as they used kset_create_and_add() > before and I just want to add the ".child_ns_type" callback. Other > users could be nfs [1] (for the release, get_ownership - I have no > idea). Ah, makes much more sense, thanks. And ick, network namespaces... Anyway, feel free to take this through whatever tree the rest of the series needs to go through: Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 7504b7547ed2..5fbc358e2be6 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -181,6 +181,8 @@ kset_type_create_and_add(const char *name, const struct kset_uevent_ops *u, struct kset * __must_check kset_create_and_add(const char *name, const struct kset_uevent_ops *u, struct kobject *parent_kobj); +void kset_release(struct kobject *kobj); +void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid); static inline struct kset *to_kset(struct kobject *kobj) { diff --git a/lib/kobject.c b/lib/kobject.c index fbae94ea9bb5..3c455002fd96 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -920,19 +920,21 @@ struct kobject *kset_find_obj(struct kset *kset, const char *name) } EXPORT_SYMBOL_GPL(kset_find_obj); -static void kset_release(struct kobject *kobj) +void kset_release(struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj); pr_debug("'%s' (%p): %s\n", kobject_name(kobj), kobj, __func__); kfree(kset); } +EXPORT_SYMBOL_GPL(kset_release); -static void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid) +void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid) { if (kobj->parent) kobject_get_ownership(kobj->parent, uid, gid); } +EXPORT_SYMBOL_GPL(kset_get_ownership); static const struct kobj_type kset_ktype = { .sysfs_ops = &kobj_sysfs_ops,
This patch exports generic helpers like kset_release() and kset_get_ownership() so users can use them in their own struct kobj_type implementation instead of implementing their own functions that do the same. Signed-off-by: Alexander Aring <aahringo@redhat.com> --- include/linux/kobject.h | 2 ++ lib/kobject.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-)