From: Alexander Aring <aahringo@redhat.com>
To: teigland@redhat.com
Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com,
agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org,
joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org,
rafael@kernel.org, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
ocfs2-devel@lists.linux.dev, lucien.xin@gmail.com,
aahringo@redhat.com
Subject: [RFC dlm/next 08/12] kobject: add kset_type_create_and_add() helper
Date: Wed, 14 Aug 2024 10:34:10 -0400 [thread overview]
Message-ID: <20240814143414.1877505-9-aahringo@redhat.com> (raw)
In-Reply-To: <20240814143414.1877505-1-aahringo@redhat.com>
Currently there exists the kset_create_and_add() helper that does not
allow to have a different ktype for the created kset kobject. To allow
a different ktype this patch will introduce the function
kset_type_create_and_add() that allows to set a different ktype instead
of using the global default kset_ktype variable.
In my example I need to separate the created kobject inside the kset by
net-namespaces. This patch allows me to do that by providing a user
defined kobj_type structure that implements the necessary namespace
functionality.
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
include/linux/kobject.h | 8 +++++--
lib/kobject.c | 49 +++++++++++++++++++++++++----------------
2 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index c8219505a79f..7504b7547ed2 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -175,8 +175,12 @@ struct kset {
void kset_init(struct kset *kset);
int __must_check kset_register(struct kset *kset);
void kset_unregister(struct kset *kset);
-struct kset * __must_check kset_create_and_add(const char *name, const struct kset_uevent_ops *u,
- struct kobject *parent_kobj);
+struct kset * __must_check
+kset_type_create_and_add(const char *name, const struct kset_uevent_ops *u,
+ struct kobject *parent_kobj, const struct kobj_type *ktype);
+struct kset * __must_check
+kset_create_and_add(const char *name, const struct kset_uevent_ops *u,
+ struct kobject *parent_kobj);
static inline struct kset *to_kset(struct kobject *kobj)
{
diff --git a/lib/kobject.c b/lib/kobject.c
index 72fa20f405f1..fbae94ea9bb5 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -957,7 +957,8 @@ static const struct kobj_type kset_ktype = {
*/
static struct kset *kset_create(const char *name,
const struct kset_uevent_ops *uevent_ops,
- struct kobject *parent_kobj)
+ struct kobject *parent_kobj,
+ const struct kobj_type *ktype)
{
struct kset *kset;
int retval;
@@ -973,17 +974,32 @@ static struct kset *kset_create(const char *name,
kset->uevent_ops = uevent_ops;
kset->kobj.parent = parent_kobj;
- /*
- * The kobject of this kset will have a type of kset_ktype and belong to
- * no kset itself. That way we can properly free it when it is
- * finished being used.
- */
- kset->kobj.ktype = &kset_ktype;
+ kset->kobj.ktype = ktype;
kset->kobj.kset = NULL;
return kset;
}
+struct kset *kset_type_create_and_add(const char *name,
+ const struct kset_uevent_ops *uevent_ops,
+ struct kobject *parent_kobj,
+ const struct kobj_type *ktype)
+{
+ struct kset *kset;
+ int error;
+
+ kset = kset_create(name, uevent_ops, parent_kobj, ktype);
+ if (!kset)
+ return NULL;
+ error = kset_register(kset);
+ if (error) {
+ kfree(kset);
+ return NULL;
+ }
+ return kset;
+}
+EXPORT_SYMBOL_GPL(kset_type_create_and_add);
+
/**
* kset_create_and_add() - Create a struct kset dynamically and add it to sysfs.
*
@@ -1002,18 +1018,13 @@ struct kset *kset_create_and_add(const char *name,
const struct kset_uevent_ops *uevent_ops,
struct kobject *parent_kobj)
{
- struct kset *kset;
- int error;
-
- kset = kset_create(name, uevent_ops, parent_kobj);
- if (!kset)
- return NULL;
- error = kset_register(kset);
- if (error) {
- kfree(kset);
- return NULL;
- }
- return kset;
+ /*
+ * The kobject of this kset will have a type of kset_ktype and belong to
+ * no kset itself. That way we can properly free it when it is
+ * finished being used.
+ */
+ return kset_type_create_and_add(name, uevent_ops, parent_kobj,
+ &kset_ktype);
}
EXPORT_SYMBOL_GPL(kset_create_and_add);
--
2.43.0
next prev parent reply other threads:[~2024-08-14 14:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 14:34 [RFC dlm/next 00/12] dlm: net-namespace functionality Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 01/12] dlm: introduce dlm_find_lockspace_name() Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 02/12] dlm: disallow different configs nodeid storages Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 03/12] dlm: add struct net to dlm_new_lockspace() Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 04/12] dlm: handle port as __be16 network byte order Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 05/12] dlm: use dlm_config as only cluster configuration Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 06/12] dlm: dlm_config_info config fields to unsigned int Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 07/12] dlm: rename config to configfs Alexander Aring
2024-08-14 14:34 ` Alexander Aring [this message]
2024-08-24 2:26 ` [RFC dlm/next 08/12] kobject: add kset_type_create_and_add() helper Greg KH
2024-08-25 19:54 ` Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 09/12] kobject: export generic helper ops Alexander Aring
2024-08-14 15:05 ` Greg KH
2024-08-14 20:47 ` Alexander Aring
2024-08-15 5:28 ` Greg KH
2024-08-14 14:34 ` [RFC dlm/next 10/12] dlm: separate dlm lockspaces per net-namespace Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 11/12] dlm: add nldlm net-namespace aware UAPI Alexander Aring
2024-08-14 14:34 ` [RFC dlm/next 12/12] gfs2: separate mount context by net-namespaces Alexander Aring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240814143414.1877505-9-aahringo@redhat.com \
--to=aahringo@redhat.com \
--cc=agruenba@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=gfs2@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=jlbec@evilplan.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
--cc=rafael@kernel.org \
--cc=song@kernel.org \
--cc=teigland@redhat.com \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).