return 0;
}
+static void alias_device_cb(struct device_user *dep, enum device_event ev)
+{
+ struct alias_device *alias;
+ bool present = false;
+
+ alias = container_of(dep, struct alias_device, dep);
+ switch (ev) {
+ case DEV_EVENT_ADD:
+ present = true;
+ case DEV_EVENT_REMOVE:
+ device_set_present(&alias->dev, present);
+ break;
+ default:
+ device_broadcast_event(&alias->dev, ev);
+ break;
+ }
+}
+
static struct device *
alias_device_create(const char *name, struct blob_attr *attr)
{
device_init_virtual(&alias->dev, &alias_device_type, NULL);
alias->avl.key = alias->name;
avl_insert(&aliases, &alias->avl);
+ alias->dep.alias = true;
+ alias->dep.cb = alias_device_cb;
return &alias->dev;
}
}
}
- device_set_present(&alias->dev, !!dev);
-
if (!dev && alias->dep.dev && !alias->dep.dev->active) {
device_remove_user(&alias->dep);
alias->dev.hidden = true;
avl_init(&devices, avl_strcmp, true, NULL);
}
-void device_broadcast_event(struct device *dev, enum device_event ev)
+
+static void __device_broadcast_event(struct list_head *head, enum device_event ev)
{
struct device_user *dep, *tmp;
- list_for_each_entry_safe(dep, tmp, &dev->users, list) {
+ list_for_each_entry_safe(dep, tmp, head, list) {
if (!dep->cb)
continue;
}
}
+void device_broadcast_event(struct device *dev, enum device_event ev)
+{
+ __device_broadcast_event(&dev->aliases, ev);
+ __device_broadcast_event(&dev->users, ev);
+}
+
int device_claim(struct device_user *dep)
{
struct device *dev = dep->dev;
D(DEVICE, "Initialize device '%s'\n", dev->ifname);
INIT_LIST_HEAD(&dev->users);
+ INIT_LIST_HEAD(&dev->aliases);
dev->type = type;
if (!dev->set_state)
void device_add_user(struct device_user *dep, struct device *dev)
{
+ struct list_head *head;
+
if (dep->dev)
device_remove_user(dep);
return;
dep->dev = dev;
- list_add_tail(&dep->list, &dev->users);
+
+ if (dep->alias)
+ head = &dev->aliases;
+ else
+ head = &dev->users;
+ list_add_tail(&dep->list, head);
+
if (dep->cb && dev->present) {
dep->cb(dep, DEV_EVENT_ADD);
if (dev->active)