|
4 | 4 | */ |
5 | 5 | #include <linux/sunrpc/clnt.h> |
6 | 6 | #include <linux/kobject.h> |
| 7 | +#include "sysfs.h" |
7 | 8 |
|
8 | 9 | static struct kset *rpc_sunrpc_kset; |
9 | 10 | static struct kobject *rpc_sunrpc_client_kobj; |
@@ -56,8 +57,68 @@ int rpc_sysfs_init(void) |
56 | 57 | return 0; |
57 | 58 | } |
58 | 59 |
|
| 60 | +static void rpc_sysfs_client_release(struct kobject *kobj) |
| 61 | +{ |
| 62 | + struct rpc_sysfs_client *c; |
| 63 | + |
| 64 | + c = container_of(kobj, struct rpc_sysfs_client, kobject); |
| 65 | + kfree(c); |
| 66 | +} |
| 67 | + |
| 68 | +static const void *rpc_sysfs_client_namespace(struct kobject *kobj) |
| 69 | +{ |
| 70 | + return container_of(kobj, struct rpc_sysfs_client, kobject)->net; |
| 71 | +} |
| 72 | + |
| 73 | +static struct kobj_type rpc_sysfs_client_type = { |
| 74 | + .release = rpc_sysfs_client_release, |
| 75 | + .sysfs_ops = &kobj_sysfs_ops, |
| 76 | + .namespace = rpc_sysfs_client_namespace, |
| 77 | +}; |
| 78 | + |
59 | 79 | void rpc_sysfs_exit(void) |
60 | 80 | { |
61 | 81 | kobject_put(rpc_sunrpc_client_kobj); |
62 | 82 | kset_unregister(rpc_sunrpc_kset); |
63 | 83 | } |
| 84 | + |
| 85 | +static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent, |
| 86 | + struct net *net, |
| 87 | + int clid) |
| 88 | +{ |
| 89 | + struct rpc_sysfs_client *p; |
| 90 | + |
| 91 | + p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 92 | + if (p) { |
| 93 | + p->net = net; |
| 94 | + p->kobject.kset = rpc_sunrpc_kset; |
| 95 | + if (kobject_init_and_add(&p->kobject, &rpc_sysfs_client_type, |
| 96 | + parent, "clnt-%d", clid) == 0) |
| 97 | + return p; |
| 98 | + kobject_put(&p->kobject); |
| 99 | + } |
| 100 | + return NULL; |
| 101 | +} |
| 102 | + |
| 103 | +void rpc_sysfs_client_setup(struct rpc_clnt *clnt, struct net *net) |
| 104 | +{ |
| 105 | + struct rpc_sysfs_client *rpc_client; |
| 106 | + |
| 107 | + rpc_client = rpc_sysfs_client_alloc(rpc_sunrpc_client_kobj, net, clnt->cl_clid); |
| 108 | + if (rpc_client) { |
| 109 | + clnt->cl_sysfs = rpc_client; |
| 110 | + kobject_uevent(&rpc_client->kobject, KOBJ_ADD); |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +void rpc_sysfs_client_destroy(struct rpc_clnt *clnt) |
| 115 | +{ |
| 116 | + struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs; |
| 117 | + |
| 118 | + if (rpc_client) { |
| 119 | + kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE); |
| 120 | + kobject_del(&rpc_client->kobject); |
| 121 | + kobject_put(&rpc_client->kobject); |
| 122 | + clnt->cl_sysfs = NULL; |
| 123 | + } |
| 124 | +} |
0 commit comments