1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2020 Anna Schumaker <Anna.Schumaker@Netapp.com>
5 #include <linux/sunrpc/clnt.h>
6 #include <linux/kobject.h>
8 static struct kset *rpc_sunrpc_kset;
9 static struct kobject *rpc_sunrpc_client_kobj;
11 static void rpc_sysfs_object_release(struct kobject *kobj)
16 static const struct kobj_ns_type_operations *
17 rpc_sysfs_object_child_ns_type(struct kobject *kobj)
19 return &net_ns_type_operations;
22 static struct kobj_type rpc_sysfs_object_type = {
23 .release = rpc_sysfs_object_release,
24 .sysfs_ops = &kobj_sysfs_ops,
25 .child_ns_type = rpc_sysfs_object_child_ns_type,
28 static struct kobject *rpc_sysfs_object_alloc(const char *name,
30 struct kobject *parent)
34 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
37 if (kobject_init_and_add(kobj, &rpc_sysfs_object_type,
38 parent, "%s", name) == 0)
45 int rpc_sysfs_init(void)
47 rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj);
50 rpc_sunrpc_client_kobj = rpc_sysfs_object_alloc("client", rpc_sunrpc_kset, NULL);
51 if (!rpc_sunrpc_client_kobj) {
52 kset_unregister(rpc_sunrpc_kset);
53 rpc_sunrpc_client_kobj = NULL;
59 void rpc_sysfs_exit(void)
61 kobject_put(rpc_sunrpc_client_kobj);
62 kset_unregister(rpc_sunrpc_kset);