All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Coddington <bcodding@redhat.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v4 03/11] NFS: Open-code the nfs_kset kset_create_and_add()
Date: Thu, 15 Jun 2023 14:07:24 -0400	[thread overview]
Message-ID: <5324b8f02f6abda62fc6e59382791e48af8be4d3.1686851158.git.bcodding@redhat.com> (raw)
In-Reply-To: <cover.1686851158.git.bcodding@redhat.com>

In preparation to make objects below /sys/fs/nfs namespace aware, we need
to define our own kobj_type for the nfs kset so that we can add the
.child_ns_type member in a following patch.  No functional change here, only
the unrolling of kset_create_and_add().

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
 fs/nfs/sysfs.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index 8f89aeca6272..9adb8ac08d9a 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -25,12 +25,23 @@ static void nfs_netns_object_release(struct kobject *kobj)
 	kfree(kobj);
 }
 
+static void nfs_kset_release(struct kobject *kobj)
+{
+	struct kset *kset = container_of(kobj, struct kset, kobj);
+	kfree(kset);
+}
+
 static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
 		const struct kobject *kobj)
 {
 	return &net_ns_type_operations;
 }
 
+static struct kobj_type nfs_kset_type = {
+	.release = nfs_kset_release,
+	.sysfs_ops = &kobj_sysfs_ops,
+};
+
 static struct kobj_type nfs_netns_object_type = {
 	.release = nfs_netns_object_release,
 	.sysfs_ops = &kobj_sysfs_ops,
@@ -55,13 +66,32 @@ static struct kobject *nfs_netns_object_alloc(const char *name,
 
 int nfs_sysfs_init(void)
 {
-	nfs_kset = kset_create_and_add("nfs", NULL, fs_kobj);
+	int ret;
+
+	nfs_kset = kzalloc(sizeof(*nfs_kset), GFP_KERNEL);
 	if (!nfs_kset)
 		return -ENOMEM;
+
+	ret = kobject_set_name(&nfs_kset->kobj, "nfs");
+	if (ret) {
+		kfree(nfs_kset);
+		return ret;
+	}
+
+	nfs_kset->kobj.parent = fs_kobj;
+	nfs_kset->kobj.ktype = &nfs_kset_type;
+	nfs_kset->kobj.kset = NULL;
+
+	ret = kset_register(nfs_kset);
+	if (ret) {
+		kfree(nfs_kset);
+		return ret;
+	}
+
 	nfs_net_kobj = nfs_netns_object_alloc("net", nfs_kset, NULL);
 	if (!nfs_net_kobj) {
 		kset_unregister(nfs_kset);
-		nfs_kset = NULL;
+		kfree(nfs_kset);
 		return -ENOMEM;
 	}
 	return 0;
-- 
2.40.1


  parent reply	other threads:[~2023-06-15 18:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 18:07 [PATCH v4 00/11] NFS sysfs scaffolding Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 01/11] NFS: rename nfs_client_kset to nfs_kset Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 02/11] NFS: rename nfs_client_kobj to nfs_net_kobj Benjamin Coddington
2023-06-15 18:07 ` Benjamin Coddington [this message]
2023-06-15 18:07 ` [PATCH v4 04/11] NFS: Make all of /sys/fs/nfs network-namespace unique Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 05/11] NFS: add superblock sysfs entries Benjamin Coddington
2023-06-26 21:12   ` Nathan Chancellor
2023-06-26 21:47     ` Benjamin Coddington
2023-06-26 22:25       ` Nathan Chancellor
2023-06-15 18:07 ` [PATCH v4 06/11] NFS: Add sysfs links to sunrpc clients for nfs_clients Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 07/11] NFS: add a sysfs link to the lockd rpc_client Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 08/11] NFS: add a sysfs link to the acl rpc_client Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 09/11] NFS: add sysfs shutdown knob Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 10/11] NFS: Cancel all existing RPC tasks when shutdown Benjamin Coddington
2023-06-15 18:07 ` [PATCH v4 11/11] NFSv4: Clean up some shutdown loops Benjamin Coddington

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=5324b8f02f6abda62fc6e59382791e48af8be4d3.1686851158.git.bcodding@redhat.com \
    --to=bcodding@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.