]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/notify.c
Delete more unused shim code, update bcache code
[bcachefs-tools-debian] / libbcache / notify.c
1 /*
2  * Code for sending uevent notifications to user-space.
3  *
4  * Copyright 2015 Datera, Inc.
5  */
6
7 #include "bcache.h"
8 #include "notify.h"
9
10 #include <linux/kobject.h>
11
12 #define notify_var(c, format, ...)                                      \
13 ({                                                                      \
14         int ret;                                                        \
15         lockdep_assert_held(&(c)->uevent_lock);                         \
16         ret = add_uevent_var(&(c)->uevent_env, format, ##__VA_ARGS__);  \
17         WARN_ON_ONCE(ret);                                              \
18 })
19
20 static void notify_get(struct cache_set *c)
21 {
22         struct kobj_uevent_env *env = &c->uevent_env;
23
24         mutex_lock(&c->uevent_lock);
25         env->envp_idx = 0;
26         env->buflen = 0;
27
28         notify_var(c, "SET_UUID=%pU", c->sb.user_uuid.b);
29 }
30
31 static void notify_get_cache(struct cache *ca)
32 {
33         struct cache_set *c = ca->set;
34         char buf[BDEVNAME_SIZE];
35
36         notify_get(c);
37         notify_var(c, "UUID=%pU", ca->uuid.b);
38         notify_var(c, "BLOCKDEV=%s", bdevname(ca->disk_sb.bdev, buf));
39 }
40
41 static void notify_put(struct cache_set *c)
42 {
43         struct kobj_uevent_env *env = &c->uevent_env;
44
45         env->envp[env->envp_idx] = NULL;
46         kobject_uevent_env(&c->kobj, KOBJ_CHANGE, env->envp);
47         mutex_unlock(&c->uevent_lock);
48 }
49
50 void bch_notify_fs_read_write(struct cache_set *c)
51 {
52         notify_get(c);
53         notify_var(c, "STATE=active");
54         notify_put(c);
55 }
56
57 void bch_notify_fs_read_only(struct cache_set *c)
58 {
59         notify_get(c);
60         notify_var(c, "STATE=readonly");
61         notify_put(c);
62 }
63
64 void bch_notify_fs_stopped(struct cache_set *c)
65 {
66         notify_get(c);
67         notify_var(c, "STATE=stopped");
68         notify_put(c);
69 }
70
71 void bch_notify_dev_read_write(struct cache *ca)
72 {
73         struct cache_set *c = ca->set;
74
75         notify_get_cache(ca);
76         notify_var(c, "STATE=active");
77         notify_put(c);
78 }
79
80 void bch_notify_dev_read_only(struct cache *ca)
81 {
82         struct cache_set *c = ca->set;
83
84         notify_get_cache(ca);
85         notify_var(c, "STATE=readonly");
86         notify_put(c);
87 }
88
89 void bch_notify_dev_added(struct cache *ca)
90 {
91         struct cache_set *c = ca->set;
92
93         notify_get_cache(ca);
94         notify_var(c, "STATE=removing");
95         notify_put(c);
96 }
97
98 void bch_notify_dev_removing(struct cache *ca)
99 {
100         struct cache_set *c = ca->set;
101
102         notify_get_cache(ca);
103         notify_var(c, "STATE=removing");
104         notify_put(c);
105 }
106
107 void bch_notify_dev_remove_failed(struct cache *ca)
108 {
109         struct cache_set *c = ca->set;
110
111         notify_get_cache(ca);
112         notify_var(c, "STATE=remove_failed");
113         notify_put(c);
114 }
115
116 void bch_notify_dev_removed(struct cache *ca)
117 {
118         struct cache_set *c = ca->set;
119
120         notify_get_cache(ca);
121         notify_var(c, "STATE=removed");
122         notify_put(c);
123 }
124
125 void bch_notify_dev_error(struct cache *ca, bool fatal)
126 {
127         struct cache_set *c = ca->set;
128
129         notify_get_cache(ca);
130         notify_var(c, "STATE=error");
131         notify_var(c, "FATAL=%d", fatal);
132         notify_put(c);
133 }