2 * Code for sending uevent notifications to user-space.
4 * Copyright 2015 Datera, Inc.
10 #include <linux/kobject.h>
12 #define notify_var(c, format, ...) \
15 lockdep_assert_held(&(c)->uevent_lock); \
16 ret = add_uevent_var(&(c)->uevent_env, format, ##__VA_ARGS__); \
20 static void notify_get(struct cache_set *c)
22 struct kobj_uevent_env *env = &c->uevent_env;
24 mutex_lock(&c->uevent_lock);
28 notify_var(c, "SET_UUID=%pU", c->sb.user_uuid.b);
31 static void notify_get_cache(struct cache *ca)
33 struct cache_set *c = ca->set;
34 char buf[BDEVNAME_SIZE];
37 notify_var(c, "UUID=%pU", ca->uuid.b);
38 notify_var(c, "BLOCKDEV=%s", bdevname(ca->disk_sb.bdev, buf));
41 static void notify_put(struct cache_set *c)
43 struct kobj_uevent_env *env = &c->uevent_env;
45 env->envp[env->envp_idx] = NULL;
46 kobject_uevent_env(&c->kobj, KOBJ_CHANGE, env->envp);
47 mutex_unlock(&c->uevent_lock);
50 void bch_notify_cache_set_read_write(struct cache_set *c)
53 notify_var(c, "STATE=active");
57 void bch_notify_cache_set_read_only(struct cache_set *c)
60 notify_var(c, "STATE=readonly");
64 void bch_notify_cache_set_stopped(struct cache_set *c)
67 notify_var(c, "STATE=stopped");
71 void bch_notify_cache_read_write(struct cache *ca)
73 struct cache_set *c = ca->set;
76 notify_var(c, "STATE=active");
80 void bch_notify_cache_read_only(struct cache *ca)
82 struct cache_set *c = ca->set;
85 notify_var(c, "STATE=readonly");
89 void bch_notify_cache_added(struct cache *ca)
91 struct cache_set *c = ca->set;
94 notify_var(c, "STATE=removing");
98 void bch_notify_cache_removing(struct cache *ca)
100 struct cache_set *c = ca->set;
102 notify_get_cache(ca);
103 notify_var(c, "STATE=removing");
107 void bch_notify_cache_remove_failed(struct cache *ca)
109 struct cache_set *c = ca->set;
111 notify_get_cache(ca);
112 notify_var(c, "STATE=remove_failed");
116 void bch_notify_cache_removed(struct cache *ca)
118 struct cache_set *c = ca->set;
120 notify_get_cache(ca);
121 notify_var(c, "STATE=removed");
125 void bch_notify_cache_error(struct cache *ca, bool fatal)
127 struct cache_set *c = ca->set;
129 notify_get_cache(ca);
130 notify_var(c, "STATE=error");
131 notify_var(c, "FATAL=%d", fatal);