|
2 | 2 | /* |
3 | 3 | * Copyright (c) 2020 Anna Schumaker <[email protected]> |
4 | 4 | */ |
| 5 | +#include <linux/sunrpc/clnt.h> |
5 | 6 | #include <linux/kobject.h> |
6 | 7 |
|
7 | 8 | static struct kset *rpc_sunrpc_kset; |
| 9 | +static struct kobject *rpc_sunrpc_client_kobj; |
| 10 | + |
| 11 | +static void rpc_sysfs_object_release(struct kobject *kobj) |
| 12 | +{ |
| 13 | + kfree(kobj); |
| 14 | +} |
| 15 | + |
| 16 | +static const struct kobj_ns_type_operations * |
| 17 | +rpc_sysfs_object_child_ns_type(struct kobject *kobj) |
| 18 | +{ |
| 19 | + return &net_ns_type_operations; |
| 20 | +} |
| 21 | + |
| 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, |
| 26 | +}; |
| 27 | + |
| 28 | +static struct kobject *rpc_sysfs_object_alloc(const char *name, |
| 29 | + struct kset *kset, |
| 30 | + struct kobject *parent) |
| 31 | +{ |
| 32 | + struct kobject *kobj; |
| 33 | + |
| 34 | + kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); |
| 35 | + if (kobj) { |
| 36 | + kobj->kset = kset; |
| 37 | + if (kobject_init_and_add(kobj, &rpc_sysfs_object_type, |
| 38 | + parent, "%s", name) == 0) |
| 39 | + return kobj; |
| 40 | + kobject_put(kobj); |
| 41 | + } |
| 42 | + return NULL; |
| 43 | +} |
8 | 44 |
|
9 | 45 | int rpc_sysfs_init(void) |
10 | 46 | { |
11 | 47 | rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj); |
12 | 48 | if (!rpc_sunrpc_kset) |
13 | 49 | return -ENOMEM; |
| 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; |
| 54 | + return -ENOMEM; |
| 55 | + } |
14 | 56 | return 0; |
15 | 57 | } |
16 | 58 |
|
17 | 59 | void rpc_sysfs_exit(void) |
18 | 60 | { |
| 61 | + kobject_put(rpc_sunrpc_client_kobj); |
19 | 62 | kset_unregister(rpc_sunrpc_kset); |
20 | 63 | } |
0 commit comments